SELECT -> CREATE TABLE Conversion
QueryBuilder.buildCreateTableQuery turns a projection into a CREATE TABLE ... AS SELECT ... statement so rawsql-ts can seed temporary tables without exposing mutable state to the test runner. Because the select query already contains the desired columns and CTEs, the helper simply wraps it inside the new table definition while preserving optional flags such as TEMPORARY or IF NOT EXISTS.
Transformation details
- The given
SelectQuerybecomes theAS SELECTsource of theCreateTableQuery, so anyWITHclauses or computed columns survive untouched. tableNameidentifies where the rows should land, andisTemporarycontrols whether the table is created in the session-local namespace.ifNotExistsensures the helper can be re-run without failing when bootstrap fixtures already created the table.
This conversion is especially helpful for the SQLite testkit demos, where a temporary table hosts fixture rows before the repository under test runs SELECT statements against it.
ts
const createTableQuery = QueryBuilder.buildCreateTableQuery(simpleSelectQuery, 'tmp_customers', true, true);Learn More
- QueryBuilder API for
buildCreateTableQueryand the flags that mirror native DDL. - SQLite Testkit Guide to see where temporary tables help compose fixtures.
- Why SQL Unit Testing Is Hard for the philosophy of relying on
SELECTrewrites and letting conversions manage DML/DDL.