Registry / database / driftsql

driftsql

JSON →
library2.0.0-beta.6jsnpmunverified

DriftSQL is a modern, type-safe SQL client for TypeScript, currently in beta (v2.0.0-beta.6). It provides a built-in schema builder and migration system, allowing developers to define database schemas in code and migrate automatically. Key differentiators include full TypeScript type inference from schema definitions, lightweight zero-dependency core, and a query builder that prevents runtime errors by catching type mismatches at compile time. Unlike traditional ORMs, it focuses on type safety without sacrificing performance. It supports PostgreSQL and SQLite, with Community-provided drivers for MySQL and MSSQL.

npm install driftsql
INSTALL
IMPORT
SIG · DRIFTSQL
D
driftsql
databasejavascriptv2.0.0-beta.6
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.

DriftClient
✓ import { DriftClient } from 'driftsql'
✗ const DriftClient = require('driftsql')
ESM-only since v2.0.0-beta.
sql
✓ import { sql } from 'driftsql'
✗ import { query } from 'driftsql'
The tagged template literal function is called 'sql', not 'query'.
default
✓ import Drift from 'driftsql'
✗ import { Drift } from 'driftsql'
Default export is named 'Drift' (capital D), but it's a default export, so no braces.

Shows how to define a table schema, initialize a DriftSQL client, and execute a type-safe query with automatic parameter binding.

import { DriftClient, sql } from 'driftsql'; import { defineTable, text, integer } from 'driftsql/schema'; // Define schema const Users = defineTable('users', { id: integer().primaryKey(), name: text().notNull(), email: text().unique(), }); // Create client const client = new DriftClient({ dialect: 'postgresql', connection: process.env.DATABASE_URL ?? 'postgres://localhost:5432/mydb', }); // Run a typed query async function main() { const users = await client.execute( sql`SELECT * FROM ${Users} WHERE ${Users.name} = ${'Alice'}` ); console.log(users.rows); } main();
Debug
Known issues
breakingv2.0.0 removes the old old-style schema builder. Use defineTable from 'driftsql/schema'.
fix
Migrate schema definitions to use defineTable with column builders.
affects: >=2.0.0
deprecatedDriftClient constructor options changed: 'driver' replaced by 'dialect' in v2.0.0.
fix
Replace 'driver: 'pg'' with 'dialect: 'postgresql''.
affects: >=2.0.0-beta.5
gotchaTable names in template literals must be bare identifiers (not strings). Using strings like sql`SELECT * FROM 'users'` fails.
fix
Use sql`SELECT * FROM ${Users}` where Users is a table object from defineTable.
affects: >=1.0.0
gotchaDefault export is called 'Drift', not 'driftsql'. Importing as default with a different name works, but beware of common typos.
fix
Use import Drift from 'driftsql'.
affects: >=2.0.0
deprecatedThe 'query' method on DriftClient is deprecated in favor of 'execute'.
fix
Replace client.query(...) with client.execute(...).
affects: >=2.0.0-beta.4
Errors
Common errors & fixes
Cannot find module 'driftsql' or its corresponding type declarations.
Missing or incompatible TypeScript types (package ships types but may need tsconfig.json settings).
fix
Ensure moduleResolution is 'node16' or 'nodenext' in tsconfig.json, or set 'moduleResolution: 'bundler'. Also install latest version (>=2.0.0-beta).
TypeError: (0 , driftsql_1.sql) is not a function
Using a wrong import pattern (e.g., import { query } instead of { sql }).
fix
Change import to import { sql } from 'driftsql'.
Error: No dialect provided or dialect not supported.
DriftClient constructed without a 'dialect' option (or before v2.0.0, without 'driver').
fix
Add dialect: 'postgresql' (or 'sqlite', etc.) to the DriftClient options.
Upgrade
Version history
2.0.0-beta.6latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
Resources
driftsql — npm install driftsql · libregistry