Expand description
#3070: a D1 call’s literal SQL, checked against the schema its binding’s
migrations build.
D1Sql::build applies each database’s migrations, in order, to a fresh
in-memory SQLite (a bundled one, so every machine and CI agree), once per
run. The checker records each literal statement as a
D1SqlSite (a Callee::D1Sql entry
under the SQL argument’s id); D1Sql::check_unit then prepares each one
against its database. prepare executes nothing, so the check is cheap and
has no side effects. Reported:
bynk.d1.sql_invalid: the statement doesn’t prepare (a syntax error, an unknown table or column);bynk.d1.sql_param_count: the SQL’s parameter count (sqlite3_bind_parameter_count, the rule the test D1 refuses a mismatch by, #3003) differs from the list literal passed;bynk.d1.select_field_missing: aselect[T]field with no column;bynk.d1.migration_invalid(warning): a migration that doesn’t apply; the database’s statements are then not checked, since each would only echo it.
A database with no migrations directory has no schema, so sql_invalid and
select_field_missing have nothing to check against; but the parameter
count is a property of the SQL text, so parameter_count (a scanner that
mirrors SQLite’s) still checks it (#3126). A database whose migrations
failed is skipped entirely, as each statement would only echo that warning.
#3197: the statements of a literal batch list run in order, so each is
prepared against the schema the earlier ones leave: inside a savepoint on the
schema connection, a statement that prepares and is DDL (CREATE, DROP,
ALTER) is also executed, and the savepoint is rolled back when the batch
has been checked, on every path, so the shared schema is never left changed.
Never stricter than the test tier is the aim, since that tier runs the same
migrations on Node’s own SQLite.
On wasm32 (the playground) there is no migrations folder and no SQLite:
D1Sql::build returns None.
Structs§
- D1Sql
- The schema each migrated database builds, ready to
prepareagainst.