Install sqlty for TypeScript and JavaScript¶
sqlty checks the sql tagged templates of postgres.js, node-postgres, mysql2 and
better-sqlite3 through ESLint,
against the CREATE TABLE statements of your .sql files. It needs no database.
Not on npm yet
@sqlty/eslint-plugin is published from the next release on. Until then, try it in
the playground, under the "TypeScript (ESLint plugin)" example.
1. Install¶
npm install --save-dev eslint @typescript-eslint/parser @sqlty/eslint-plugin
The plugin runs the engine as WebAssembly, so it needs no Python and no native build. It needs ESLint 9 or newer.
2. Configure¶
// eslint.config.js
import parser from "@typescript-eslint/parser";
import sqlty from "@sqlty/eslint-plugin";
const check = ["error", { schema: "schema.sql", driver: "postgres", targets: [{ tag: "sql", transform: "{type}[]" }] }];
export default [
{ files: ["**/*.js"], plugins: { sqlty }, rules: { "sqlty/check-sql": check } },
{ files: ["**/*.ts"], languageOptions: { parser }, plugins: { sqlty }, rules: { "sqlty/check-sql": check } },
];
driver is postgres for postgres.js or pg for node-postgres. With dialect: "mysql" it
is mysql2, with dialect: "sqlite" better-sqlite3. Every option is in
TypeScript and JavaScript (ESLint).
3. Check¶
npx eslint . # reports unknown tables and columns, and stale row types
npx eslint . --fix # writes each query's row type as its type argument
4. Editor and CI¶
The ESLint extension
shows the findings in VS Code as you type, and any editor with ESLint support does the
same. In CI, npx eslint . fails the job on an error:
# .github/workflows/eslint.yml
name: eslint
on: [pull_request]
jobs:
eslint:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v7
- uses: actions/setup-node@v7
- run: npm ci
- run: npx eslint .
Common questions¶
Do I need @sqlty/cli for TypeScript?¶
No. @sqlty/cli is the sqlty command, which checks Python. The ESLint plugin carries
its own engine.
Which databases does the plugin support?¶
PostgreSQL, with the row types postgres.js and node-postgres return; MySQL, with mysql2's; SQLite, with better-sqlite3's.
Can I run the engine without ESLint?¶
Yes. @sqlty/wasm exposes it to JavaScript, see
Embedding in JavaScript.