Database API (vaeljs-dbapi)
vaeljs-dbapi is the workspace database crate backing vael:db, vael:db/migrate, and vjs db migrate in vjs (vaeljs / vaeljs-core). It gives Rust callers and the vael:db JavaScript surface one SQL shape: strict JSON configuration (with verifyFull TLS enabled by default on network drivers), named @name or positional ? parameters, bounded driver-neutral rows, fluent AST query builders, deterministic SQL migrations, and redacted errors.
The crate is asynchronous and does not create a Tokio runtime; callers execute inside an existing Tokio runtime.
What Shipped (v0.0.0-alpha.0 Baseline, Multi-Driver & Builder/Migrate in v0.0.0-alpha.3)
Section titled “What Shipped (v0.0.0-alpha.0 Baseline, Multi-Driver & Builder/Migrate in v0.0.0-alpha.3)”- Strict configuration parser: Parses SQLite, PostgreSQL, MySQL, MariaDB, and Microsoft SQL Server configs (Rust
SqliteConfig/NetworkConfiginvaeljs-dbapi, corresponding to JSSqliteDbConfig/NetworkDbConfiginvael:db). Network drivers default to fail-closed verified TLS (tlsMode: "verifyFull"/tls: true, with optionalcaFile; passtls: falseortlsMode: "plaintext"only to opt into cleartext for local dev). Unknown fields, wrong types, empty required values, and out-of-range numbers fail closed with static descriptions that never echo a field value. - Lexical binding compiler: A hand-written UTF-8 byte lexer rewrites
@nameor?into the target dialect’s placeholder syntax and builds the ordered parameter vector. Handles quoted strings/identifiers, comments, PostgreSQL dollar quoting, and operator sequences containing@or?. - Default SQLite provider: End-to-end execution via
neotales-dbapi-sqlite(andneotales-migration-sqlite), backingvael:dbopenSqlite()andopen({ driver: "sqlite", ... }). Defaultvaeljs/vaeljs-dbapibuilds stay lean with SQLite only. - Opt-in network SQL drivers (shipped in
v0.0.0-alpha.3): Cargo features onvaeljs/vaeljs-core(vael-db-postgres,vael-db-mysql,vael-db-mariadb,vael-db-mssql,vael-db-all, backed byvaeljs-dbapifeaturespostgres,mysql,mariadb,mssql,all-drivers) link pure-Rust providers (neotales-dbapi-postgres,neotales-dbapi-mysql,neotales-dbapi-mariadb,neotales-dbapi-mssql, and siblingneotales-migration-*crates withrustls) overvaeljs-dbapi’s unified@name/?parameter binding, query AST, and redactedDbErrorlayer. - Lean feature gating (
--no-default-features): Buildingvaeljs-dbapiwith--no-default-featureskeeps all drivers out (leaving only the config parser and binding compiler), and requesting an uncompiled driver in default builds still validates config strictly before failing closed withErrorKind::DriverUnavailable(DbErrorcode === "DRIVER_UNAVAILABLE") without opening a socket. - Facade, fluent query AST, savepoints & migrations (
v0.0.0-alpha.3):Db,Connection, andTransactionwithexecute, boundedquery, cardinality-onequery_one, explicit commit/rollback, nested SQLsavepoint(), lossless rich-type encoding/decoding (uuid,date,timestamp,timestampTz,decimal,json), zero-ORM fluent AST query builder +sqltagged templates invael:db, and deterministic migrations invael:db/migrateandvjs db migrate.
Why neotales-dbapi Is Reused
Section titled “Why neotales-dbapi Is Reused”neotales-dbapi (0.0.0-alpha.1), neotales-migration (0.0.0-alpha.1), and the driver provider crates (neotales-dbapi-* and neotales-migration-*, all pinned at =0.0.0-alpha.1) are published from neotales/rs-db under MIT. Reusing them provides sanitized errors, bounded row access (RowLimit::default(): 1,000 rows / 1 MiB), transaction lifecycle guards, pooled/network backends, and deterministic migration execution without duplicating row/value models. vaeljs-dbapi layers the portable binding compiler, query AST, and strict configuration facade on top.
Security Model
Section titled “Security Model”- Values are never interpolated: The compiler emits SQL text and a separate parameter vector so values cannot alter statement structure. (SQL text itself remains code; placeholders do not sanitize identifiers or SQL fragments.)
- No regular expressions: The scanner is a deterministic byte lexer over UTF-8 with ASCII delimiters.
- Ambiguity fails closed:
?NNN,:name,$name,??, a bare@, mixed named and positional placeholders, multiple statements, and trigger bodies are rejected. A trailing;is accepted only when followed solely by whitespace, comments, and semicolons. MySQL--is treated as a comment only when followed by whitespace or a control character. - Dialect-aware literals: Handles single/double quotes, backticks (SQLite/MySQL), brackets (SQLite/SQL Server), line/block comments, nested block comments (PostgreSQL/SQL Server), PostgreSQL dollar quoting, and backslash escapes. MySQL (
/*! ... */) and MariaDB (/*M! ... */) executable comments are rejected in both the primary scan and trailing terminator scan. - Server-mode ambiguity checks: Ordinary MySQL and PostgreSQL strings can change end boundaries depending on
NO_BACKSLASH_ESCAPESorstandard_conforming_strings. The scanner evaluates both interpretations and rejects strings whose end boundaries disagree (explicitE'...'andU&'...'forms in PostgreSQL are accepted). - Redacted static errors & zero logging:
DbErrorcarries a category and fixed detail string — never paths, hosts, usernames, passwords, SQL text, or driver messages.Debugon network configs redacts sensitive fields, and SQL statement logging is disabled.
Known Limits
Section titled “Known Limits”- The scanner is not a full SQL parser: it cannot distinguish T-SQL local variables (
DECLARE @x) or MySQL user variables (@var) from named parameters. PostgreSQL’s bare?jsonb operator conflicts with positional placeholders, so PostgreSQL queries in portable mode require@nameparameters. - SQLite uses dynamic typing; JSON
nullbinds as SQL NULL with declaredTEXTtype (Rust callers can useParam::TypedNull). - JSON parameters from JavaScript accept
Uint8ArrayforBLOBbytes invael:db, whileParam::Bytesis used directly in Rust. - Parameter name matching is exact and case-sensitive; SQL Server rewrites named parameters to
@p1,@p2, etc. to avoid case-insensitive collisions. query_onematerializes the bounded batch before checking cardinality; use explicitLIMIT/ keyset paging for large datasets.
Cancellation & Dispatch Outcomes
Section titled “Cancellation & Dispatch Outcomes”- Dropping an in-flight future signals cancellation via a SQLite progress handler and discards an interrupted dispatched connection. Validation failures before dispatch do not invalidate the session.
WriteOutcomeUnknownandCommitOutcomeUnknownidentify post-dispatch failures where SQLite may have applied the write or committed the transaction (discarding the connection onCommitOutcomeUnknown). Callers must not blindly retry post-dispatch errors; acquire a fresh connection and verify state.
Verification Commands
Section titled “Verification Commands”cargo fmt --checkcargo clippy -p vaeljs-dbapi --all-targets --all-features -- -D warningscargo test -p vaeljs-dbapicargo test -p vaeljs-dbapi --no-default-featurescargo tree -p vaeljs-dbapi --no-default-features # no Node/V8 dependency