Registry / database / sql-ts

sql-ts

JSON →
library7.1.0jsnpmunverified

sql-ts is a TypeScript-first SQL query builder supporting PostgreSQL, MySQL, Microsoft SQL Server, Oracle, and SQLite dialects. Current stable version is 7.1.0. It generates parameterized queries to prevent SQL injection, supports composite queries, joins, subqueries, and table aliasing. Unlike similar libraries like Knex.js, sql-ts provides strong typing for tables and columns via generics, making it ideal for TypeScript projects that need compile-time safety for SQL queries. Release cadence is irregular. Key differentiator: automatic parameterization and dialect compatibility without SQL generation overhead.

npm install sql-ts
INSTALL
IMPORT
SIG · SQL-TS
S
sql-ts
databasejavascriptv7.1.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.

Sql
import { Sql } from 'sql-ts'
const Sql = require('sql-ts')
The main class; must be instantiated with a dialect string (e.g., 'postgres', 'mysql'). ESM-only from v7.
TableDefinition
import { TableDefinition } from 'sql-ts'
Type for table definition objects; useful for typed table schemas.
Queryable
import type { Queryable } from 'sql-ts'
import { Queryable } from 'sql-ts'
Queryable is an interface used for type constraints; should be imported as a type.

Demonstrates basic query building with sql-ts, including table definition, parameterized where clause, and dialect-specific output.

import { Sql } from 'sql-ts'; const sql = new Sql('postgres'); const user = sql.define<{ id: number; name: string; email: string }>({ name: 'user', columns: ['id', 'name', 'email'] }); const query = user .select(user.star()) .from(user) .where(user.name.equals('Alice').and(user.id.equals(1))) .toQuery(); console.log(query.text); console.log(query.values);
Debug
Known issues
breakingVersion 7 removed CommonJS support. All imports must use ESM syntax.
fix
Use import { Sql } from 'sql-ts' instead of require('sql-ts').
affects: >=7.0.0
deprecatedThe `create` function is deprecated in favor of `define` for table creation.
fix
Replace `sql.create({...})` with `sql.define({...})`.
affects: >=6.0.0
gotchaTable columns must include an 'id' column for `select().from(table)` to work; otherwise there is no default column.
fix
Ensure tables have an 'id' column or use explicit column selection, e.g., `user.select(user.name)`.
affects: <7.0.0
gotchaThe 'mysql' dialect uses backticks for identifiers, while 'postgres' uses double quotes. This can cause cross-dialect migration issues.
fix
Always specify the correct dialect when creating the Sql instance.
affects: all
deprecatedThe `mysql` dialect is deprecated and will be removed in a future version; use `mariadb` instead.
fix
Use `new Sql('mariadb')` instead of `new Sql('mysql')`.
affects: >=7.1.0
Errors
Common errors & fixes
TypeError: sql.create is not a function
Using deprecated `create` method instead of `define`.
fix
Replace `sql.create(...)` with `sql.define(...)`.
Cannot find module 'sql-ts'
Requiring the module with CommonJS in a project that uses ESM, or missing installation.
fix
Install sql-ts with 'npm install sql-ts' and use ESM imports: `import { Sql } from 'sql-ts'`.
Property 'lastLogin' does not exist on type 'TableDefinition<...>'
TypeScript generic not aligned with actual columns defined.
fix
Ensure the generic type passed to `sql.define<{...}>` matches the 'columns' array exactly.
Error: No dialect specified
Missing or invalid dialect string when instantiating Sql.
fix
Provide one of: 'postgres', 'mysql', 'mssql', 'sqlite', or 'oracle'.
Upgrade
Version history
7.1.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
10
Meta
2
OpenAI (training)
1
Resources
packagesql-ts
sql-ts — npm install sql-ts · libregistry