Skip to main content

Crate kimberlite_query

Crate kimberlite_query 

Source
Expand description

§kmb-query: SQL query layer for Kimberlite projections

This crate provides a minimal SQL query engine for compliance lookups against the projection store.

§SQL Subset

Supported SQL features:

  • SELECT with column list or *
  • FROM single table
  • WHERE with comparison predicates (=, <, >, <=, >=, IN)
  • ORDER BY (ascending/descending)
  • LIMIT
  • Parameterized queries ($1, $2, …)

Intentionally unsupported:

  • JOIN (queries are single-table only)
  • Subqueries
  • Aggregations (COUNT, SUM, etc.)
  • GROUP BY, HAVING
  • DISTINCT

§Usage

use kimberlite_query::{QueryEngine, Schema, SchemaBuilder, ColumnDef, DataType, Value};
use kimberlite_store::{BTreeStore, TableId};

// Define schema
let schema = SchemaBuilder::new()
    .table(
        "users",
        TableId::new(1),
        vec![
            ColumnDef::new("id", DataType::BigInt).not_null(),
            ColumnDef::new("name", DataType::Text).not_null(),
        ],
        vec!["id".into()],
    )
    .build();

// Create engine
let engine = QueryEngine::new(schema);

// Execute query
let mut store = BTreeStore::open("data/projections")?;
let result = engine.query(&mut store, "SELECT * FROM users WHERE id = $1", &[Value::BigInt(42)])?;

§Point-in-Time Queries

For compliance, you can query at a specific log position:

let result = engine.query_at(
    &mut store,
    "SELECT * FROM users WHERE id = 1",
    &[],
    Offset::new(1000),  // Query state as of log position 1000
)?;

Modules§

key_encoder
Lexicographic key encoding for B+tree lookups.

Structs§

ColumnDef
Definition of a table column.
ColumnName
SQL column name.
IndexDef
Definition of a secondary index on a table.
ParsedColumn
Parsed column definition.
ParsedCreateIndex
Parsed CREATE INDEX statement.
ParsedCreateTable
Parsed CREATE TABLE statement.
ParsedDelete
Parsed DELETE statement.
ParsedInsert
Parsed INSERT statement.
ParsedSelect
Parsed SELECT statement.
ParsedUpdate
Parsed UPDATE statement.
PreparedQuery
A prepared (planned) query ready for execution.
QueryEngine
Query engine for executing SQL against a projection store.
QueryResult
Result of executing a query.
Schema
Schema registry mapping SQL names to store types.
SchemaBuilder
Builder for constructing schemas fluently.
TableDef
Definition of a table in the schema.
TableName
SQL table name.

Enums§

DataType
SQL data types supported by the query engine.
ParsedStatement
Top-level parsed SQL statement.
Predicate
A comparison predicate from the WHERE clause.
PredicateValue
A value in a predicate (literal or parameter reference).
QueryError
Errors that can occur during query parsing and execution.
Value
A typed SQL value.

Functions§

execute
Executes a query plan against the current store state.
parse_statement
Parses a SQL statement string into a ParsedStatement.
plan_query
Plans a parsed SELECT statement.

Type Aliases§

Result
Result type for query operations.
Row
A single result row.