TypeScript SQL query builder with type-safe column references and auto-completion. Current stable version is 0.8.6, released as a single major version since 2016. Unlike Knex.js or TypeORM, it provides partial type safety by mapping TypeScript interfaces to database tables, eliminating string-based column names. Supports SELECT, INSERT, UPDATE, JOINs, WHERE clauses (including complex conditions), transactions, and aggregation. Under the hood: Knex.js for query execution. Release cadence is low, with ongoing work on SELECT expressions. Key limitation: only partial type safety (not full compile-time checks). Ships TypeScript types.
npm install simple-typed-sqlNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Shows full setup: knex client, Mapper, table mapping, table creation, insert, and select.
Use TypeScript strict mode and manually verify complex queries.
Always pass a configured knex instance to the Mapper constructor.
Use exact database table names as strings.
Add useNullAsDefault: true to knex configuration when using SQLite3.
npm install simple-typed-sql@latest
Use 'import knex from "knex"' for ESM or 'const knex = require("knex");' for CJS.Ensure fieldName in defineNumber({ fieldName: 'foo_count' }) matches DB column; type may need explicit assertion.