Expand description
§wasm-dbms-sql
SQL front-end for the wasm-dbms
DBMS engine.
The crate turns SQL text into operations on a wasm-dbms database. The
schema is still defined with #[derive(Table)]; SQL only reads and writes
data.
§Supported SQL
SELECTwithJOIN,WHERE,DISTINCT, aggregate functions,GROUP BY,HAVING,ORDER BY,LIMIT, andOFFSETINSERT,UPDATE, andDELETE; the last two require aWHEREclauseBEGIN,COMMIT, andROLLBACK, addressed by the transaction id passed toexecute- positional
?parameters
The full dialect is described in the SQL reference.
§Usage
SqlEngine runs statements. It takes the database schema once and the
DbmsContext on every call:
ⓘ
use wasm_dbms::prelude::*;
use wasm_dbms_api::prelude::*;
use wasm_dbms_memory::prelude::HeapMemoryProvider;
use wasm_dbms_sql::SqlEngine;
#[derive(Clone, DatabaseSchema)]
#[tables(User = "users")]
pub struct MySchema;
let ctx = DbmsContext::new(HeapMemoryProvider::default());
MySchema::register_tables(&ctx)?;
let engine = SqlEngine::new(MySchema);
engine.execute(
&ctx,
None,
"INSERT INTO users (id, name) VALUES (?, ?)",
&[Value::from(1u32), Value::from("Alice")],
)?;
let result = engine.execute(
&ctx,
None,
"SELECT name FROM users WHERE id = 1",
&[],
)?;parse exposes the parser on its own. It returns the syntax tree of a
statement, as defined in ast, without touching a database.
§Layout
| Module | Role |
|---|---|
lexer | Splits SQL text into tokens with their line and column |
parser | Builds the ast from the tokens |
planner | Resolves names, converts values, and builds Query and Filter |
engine | Runs the plan on the database, outside or inside a transaction |
The result and error types, SqlResult and SqlError, are defined in
wasm-dbms-api behind its sql feature, which this crate enables.
Modules§
- ast
- Abstract syntax tree of the supported SQL dialect.
Structs§
- Parsed
Statement - A parsed statement and the number of
?placeholders it contains. - SqlEngine
- Runs SQL statements against a
wasm-dbmsdatabase.
Functions§
- parse
- Parses one SQL statement.