{"id":47425,"library":"driftsql","title":"DriftSQL","description":"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.","status":"active","version":"2.0.0-beta.6","language":"javascript","source_language":"en","source_url":"https://github.com/lassejlv/driftsql","tags":["javascript","typescript"],"install":[{"cmd":"npm install driftsql","lang":"bash","label":"npm"},{"cmd":"yarn add driftsql","lang":"bash","label":"yarn"},{"cmd":"pnpm add driftsql","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since v2.0.0-beta.","wrong":"const DriftClient = require('driftsql')","symbol":"DriftClient","correct":"import { DriftClient } from 'driftsql'"},{"note":"The tagged template literal function is called 'sql', not 'query'.","wrong":"import { query } from 'driftsql'","symbol":"sql","correct":"import { sql } from 'driftsql'"},{"note":"Default export is named 'Drift' (capital D), but it's a default export, so no braces.","wrong":"import { Drift } from 'driftsql'","symbol":"default","correct":"import Drift from 'driftsql'"}],"quickstart":{"code":"import { DriftClient, sql } from 'driftsql';\nimport { defineTable, text, integer } from 'driftsql/schema';\n\n// Define schema\nconst Users = defineTable('users', {\n  id: integer().primaryKey(),\n  name: text().notNull(),\n  email: text().unique(),\n});\n\n// Create client\nconst client = new DriftClient({\n  dialect: 'postgresql',\n  connection: process.env.DATABASE_URL ?? 'postgres://localhost:5432/mydb',\n});\n\n// Run a typed query\nasync function main() {\n  const users = await client.execute(\n    sql`SELECT * FROM ${Users} WHERE ${Users.name} = ${'Alice'}`\n  );\n  console.log(users.rows);\n}\n\nmain();","lang":"typescript","description":"Shows how to define a table schema, initialize a DriftSQL client, and execute a type-safe query with automatic parameter binding."},"warnings":[{"fix":"Migrate schema definitions to use defineTable with column builders.","message":"v2.0.0 removes the old old-style schema builder. Use defineTable from 'driftsql/schema'.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Replace 'driver: 'pg'' with 'dialect: 'postgresql''.","message":"DriftClient constructor options changed: 'driver' replaced by 'dialect' in v2.0.0.","severity":"deprecated","affected_versions":">=2.0.0-beta.5"},{"fix":"Use sql`SELECT * FROM ${Users}` where Users is a table object from defineTable.","message":"Table names in template literals must be bare identifiers (not strings). Using strings like sql`SELECT * FROM 'users'` fails.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use import Drift from 'driftsql'.","message":"Default export is called 'Drift', not 'driftsql'. Importing as default with a different name works, but beware of common typos.","severity":"gotcha","affected_versions":">=2.0.0"},{"fix":"Replace client.query(...) with client.execute(...).","message":"The 'query' method on DriftClient is deprecated in favor of 'execute'.","severity":"deprecated","affected_versions":">=2.0.0-beta.4"}],"env_vars":null,"search_vec":"'allow':28 'automat':38 'beta':15 'builder':24,57 'built':21 'built-in':20 'catch':63 'client':10 'code':35 'communiti':87 'community-provid':86 'compil':67 'core':53 'current':13 'databas':32 'defin':31 'definit':48 'depend':52 'develop':29 'differenti':40 'driftsql':1,2 'driver':89 'error':61 'focus':73 'full':42 'includ':41 'infer':45 'javascript':94 'key':39 'lightweight':49 'migrat':26,37 'mismatch':65 'modern':5 'mssql':93 'mysql':91 'orm':71 'perform':79 'postgresql':82 'prevent':59 'provid':18,88 'queri':56 'runtim':60 'sacrif':78 'safe':8 'safeti':76 'schema':23,33,47 'sql':9 'sqlite':84 'support':81 'system':27 'time':68 'tradit':70 'type':7,44,64,75 'type-saf':6 'typescript':12,43,95 'unlik':69 'v2.0.0-beta.6':16 'without':77 'zero':51 'zero-depend':50","created_at":"2026-06-07T16:51:27.804893+00:00","updated_at":"2026-06-07T16:51:27.804893+00:00","problems":[{"fix":"Ensure moduleResolution is 'node16' or 'nodenext' in tsconfig.json, or set 'moduleResolution: 'bundler'. Also install latest version (>=2.0.0-beta).","cause":"Missing or incompatible TypeScript types (package ships types but may need tsconfig.json settings).","error":"Cannot find module 'driftsql' or its corresponding type declarations."},{"fix":"Change import to import { sql } from 'driftsql'.","cause":"Using a wrong import pattern (e.g., import { query } instead of { sql }).","error":"TypeError: (0 , driftsql_1.sql) is not a function"},{"fix":"Add dialect: 'postgresql' (or 'sqlite', etc.) to the DriftClient options.","cause":"DriftClient constructed without a 'dialect' option (or before v2.0.0, without 'driver').","error":"Error: No dialect provided or dialect not supported."}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/lassejlv/driftsql","github":"https://github.com/lassejlv/driftsql","docs":null,"changelog":null,"pypi":null,"npm":"driftsql","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-07","next_check":"2026-09-05","install_tag":null}}