Skip to content

The lock file and hyper-sql pull ​

sql.lock stores every column and parameter type that your database reported. Generate or update it by running hyper-sql pull in your project directory:

sh
npx hyper-sql pull
text
sql.lock written: 1 tables, 1 statements

hyper-sql pull reads your hyper-sql options from tsconfig.json, asks the database to describe every query, and writes the results to sql.lock (or whichever path you configured in the lock option). The lock file records:

  • a hash of your schema file;
  • every table and view, with each column's type, NOT NULL constraint, and default status;
  • for every statement: its SQL hash, parameter types, and output column types;
  • on Postgres: the labels of every enum type.

How pull inspects your queries ​

SQLite: hyper-sql pull loads schema.sql into an in-memory SQLite database and prepares each statement. No external server or setup is required—just Node 24 or later.

Postgres: hyper-sql pull connects to the database in DATABASE_URL (supporting sslmode=disable, require, and verify-full), applies your schema inside a transaction, asks Postgres to describe each query, and rolls the transaction back so nothing persists. It speaks the Postgres wire protocol directly with SCRAM-SHA-256 and TLS, so you don't need to install a driver just to pull.

If any statement fails to prepare, hyper-sql pull prints the database's error message along with its location in your .sql file and stops without updating the lock. Fix the SQL and pull again.

Committing the lock file ​

Commit sql.lock to version control. Because hyper-sql's mapper reads only your .sql files, annotations, and sql.lock, builds on CI or teammate machines produce the exact same types without ever connecting to a database. Never edit sql.lock by hand.

A statement is considered stale if its SQL has changed since the last hyper-sql pull. The content hash ignores -- annotations, regular comments, and whitespace, so tweaking an annotation, adding a comment, or reformatting blank lines won't invalidate the lock—whereas editing SQL or a conditional block will.

When the lock is out of date, TypeScript reports:

text
changed since the last sql pull: run hyper-sql pull

This error appears on the modified .sql file (or on line 1 of schema.sql if the schema changed). Until you re-run hyper-sql pull, hyper-sql continues checking the rest of your code against the previous lock so other type errors stay visible. You can see this live in the playground: open lock-stale and click Pull to watch the error clear, or open lock-missing to see what happens with no lock file.

In CI, add hyper-sql pull --check to verify that sql.lock is up to date. It exits with code 1 if the lock is stale and never modifies files on disk.

STRICT tables in SQLite ​

By default, every table in a SQLite schema must be declared STRICT (add STRICT right after the closing parenthesis of CREATE TABLE). In a STRICT table, SQLite enforces each column's declared type on every write, so the types in TypeScript actually match what's stored in the database. Without STRICT, hyper-sql pull rejects the table. Views and virtual tables are exempt.

STRICT tables still allow ANY columns. They type as number | bigint | string | Uint8Array (plus | null if nullable), and you can narrow them in queries with -- @col. See any-column.

If you're working with an existing non-STRICT SQLite schema, set "sqliteStrict": false in your options. Columns will then follow SQLite's type affinity rules (with declared types containing DATE, TIME, or STAMP mapped to string), and runtime validation will guard every value you read. See pull-not-strict. Postgres doesn't use this option.

Views ​

Views are recorded in sql.lock alongside tables. Because neither database guarantees non-nullability on view columns, every view column is typed as nullable with no default. On SQLite, a view column defined by an expression has no declared type—add a -- @type annotation on that column in schema.sql so hyper-sql knows its type. See views (SQLite) and views (Postgres).

Other pull errors ​

hyper-sql pull also rejects:

  • Transaction statements in a Postgres schema (BEGIN, COMMIT, ROLLBACK, etc.), since pull already wraps your schema in its own rolled-back transaction.
  • Queries referencing tables missing from schema.sql.
  • Parameters with conflicting types across different branches of a dynamic query—make sure the parameter resolves to one consistent type.

Every error message and its fix is listed in Errors.