Registry / database / typesql-cli

typesql-cli

JSON →
library0.24.0jsnpmunverified

TypeSQL generates type-safe TypeScript APIs from raw SQL statements. Version 0.24.0 is current. Release cadence is irregular, with frequent minor updates. Key differentiators: no ORM required, infers parameter/column types and nullability, supports dynamic ORDER BY, and works with PostgreSQL, MySQL, SQLite, LibSQL, and Cloudflare D1. The CLI tool scans SQL files and produces typed query functions, reducing boilerplate and runtime errors.

npm install typesql-cli
INSTALL
IMPORT
SIG · TYPESQL-CLI
T
typesql-cli
databasejavascriptv0.24.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

generated query function
import { selectProducts } from './select-products'
const { selectProducts } = require('./select-products')
Generated files are ESM modules. Use named imports matching the SQL file name in camelCase.
typesql CLI command
npx typesql generate
typesql generate
If installed globally via `npm install -g typesql-cli`, you can use `typesql generate` directly. Otherwise use `npx typesql generate`.
TypeSQL config
typesql.json
.typesqlrc
Configuration file must be named `typesql.json` in project root or specified via `-c` flag.

Demonstrates installation, configuration, SQL file creation, code generation, and usage of a typed query function.

// 1. Install globally npm install -g typesql-cli // 2. Initialize config typesql init # This creates typesql.json in current directory // 3. Edit typesql.json { "databaseUri": "sqlite://./chinook.db", "sqlDir": "./sqls", "client": "better-sqlite3" } // 4. Create a SQL file: ./sqls/select-invoices.sql SELECT InvoiceId, InvoiceDate, Total FROM invoices WHERE CustomerId = :customerId // 5. Generate typesql generate // 6. Use the generated API import { selectInvoices } from './sqls/select-invoices'; import Database from 'better-sqlite3'; const db = new Database('./chinook.db'); const invoiceRows = selectInvoices(db, { customerId: 5 }); // invoiceRows is typed as Array<{ InvoiceId: number; InvoiceDate: string; Total: number }> console.log(invoiceRows);
Debug
Known issues
gotchaGenerated files use ESM syntax; projects using CommonJS must enable ESM via .mjs extension or "type": "module" in package.json.
fix
Add "type": "module" to package.json or rename generated .ts files to .mts and use dynamic import.
affects: >=0.0.0
deprecatedThe `authToken` option in typesql.json is deprecated; use environment variables for credentials.
fix
Remove `authToken` from config and use database URI with credentials or env vars (`${DB_USER}`).
affects: <=0.24.0
breakingBreaking change in v0.20.0: `includeCrudTables` option replaced with `crudTables` and now expects an array of table names, not a string.
fix
Update typesql.json: replace "includeCrudTables": [] with "crudTables": [] and list table names explicitly.
affects: >=0.20.0
gotchaMust have a running database (or local SQLite file) when generating; TypeSQL connects to infer types.
fix
Ensure database is accessible with the URI provided in typesql.json. For SQLite, the file must exist.
affects: >=0.0.0
gotchaThe CLI does not watch for file changes; you must re-run `typesql generate` after editing SQL files.
fix
Add a build script like `"generate": "typesql generate"` and run it manually or via a watcher (e.g., nodemon).
affects: >=0.0.0
Errors
Common errors & fixes
Error: Cannot find module 'typesql-core'
Missing local installation of typesql-core when using the CLI globally.
fix
Install all dependencies locally: `npm install typesql-cli typesql-core` or use `npx` to run the global CLI.
ConnectionError: getaddrinfo ENOTFOUND localhost
Database host unreachable or wrong URI.
fix
Check databaseUri in typesql.json. Ensure database server is running and accessible.
TypeError: selectInvoices is not a function
Generated file imported incorrectly or not generated yet.
fix
Run `typesql generate` after creating/editing SQL files. Use named import matching the file name (camelCase).
SyntaxError: Cannot use import statement outside a module
Generated file uses ESM but project is CommonJS.
fix
Add "type": "module" to package.json, or rename generated .js file to .mjs.
Upgrade
Version history
0.24.0latest on npm
Audit
Dependencies
typesql-coreoptionalCore library for type generation logic
Agent activity
22 hits · last 30 days
node
18
Meta
1
OpenAI (training)
1
Resources
typesql-cli — npm install typesql-cli · libregistry