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:
SELECTwith column list or*FROMsingle tableWHEREwith 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,HAVINGDISTINCT
§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§
- Column
Def - Definition of a table column.
- Column
Name - SQL column name.
- Index
Def - Definition of a secondary index on a table.
- Parsed
Column - Parsed column definition.
- Parsed
Create Index - Parsed CREATE INDEX statement.
- Parsed
Create Table - Parsed CREATE TABLE statement.
- Parsed
Delete - Parsed DELETE statement.
- Parsed
Insert - Parsed INSERT statement.
- Parsed
Select - Parsed SELECT statement.
- Parsed
Update - Parsed UPDATE statement.
- Prepared
Query - A prepared (planned) query ready for execution.
- Query
Engine - Query engine for executing SQL against a projection store.
- Query
Result - Result of executing a query.
- Schema
- Schema registry mapping SQL names to store types.
- Schema
Builder - Builder for constructing schemas fluently.
- Table
Def - Definition of a table in the schema.
- Table
Name - SQL table name.
Enums§
- Data
Type - SQL data types supported by the query engine.
- Parsed
Statement - Top-level parsed SQL statement.
- Predicate
- A comparison predicate from the WHERE clause.
- Predicate
Value - A value in a predicate (literal or parameter reference).
- Query
Error - 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.