{"id":43842,"library":"simple-typed-sql","title":"Simple Typed SQL","description":"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.","status":"active","version":"0.8.6","language":"javascript","source_language":"en","source_url":"https://github.com/smphhh/simple-typed-sql","tags":["javascript","typescript","sql","node"],"install":[{"cmd":"npm install simple-typed-sql","lang":"bash","label":"npm"},{"cmd":"yarn add simple-typed-sql","lang":"bash","label":"yarn"},{"cmd":"pnpm add simple-typed-sql","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Underlying query builder and execution engine","package":"knex","optional":false}],"imports":[{"note":"Named export; no default export.","wrong":"import Mapper from 'simple-typed-sql';","symbol":"Mapper","correct":"import { Mapper } from 'simple-typed-sql';"},{"note":"Named export from main module.","wrong":"import { defineMapping } from 'simple-typed-sql/mapping';","symbol":"defineMapping","correct":"import { defineMapping } from 'simple-typed-sql';"},{"note":"Access via main module.","wrong":"import { defineNumber } from 'simple-typed-sql/definitions';","symbol":"defineNumber","correct":"import { defineNumber } from 'simple-typed-sql';"}],"quickstart":{"code":"import knex from 'knex';\nimport { Mapper, defineMapping, defineNumber, defineString, defineDatetime } from 'simple-typed-sql';\n\nconst knexClient = knex({\n  client: 'sqlite3',\n  connection: { filename: ':memory:' },\n  useNullAsDefault: true\n});\n\nconst mapper = new Mapper(knexClient);\n\nconst fooMapping = defineMapping('foo_table', {\n  id: defineNumber(),\n  name: defineString(),\n  createdTime: defineDatetime({ fieldName: 'created_time' }),\n  fooCount: defineNumber({ fieldName: 'foo_count' })\n});\n\n(async () => {\n  await knexClient.schema.createTable('foo_table', (table) => {\n    table.increments('id');\n    table.string('name');\n    table.datetime('created_time');\n    table.integer('foo_count');\n  });\n\n  await mapper.insertInto(fooMapping, {\n    id: 1,\n    name: 'foo1',\n    createdTime: new Date(),\n    fooCount: 5\n  });\n\n  const foos = await mapper.selectAllFrom(fooMapping);\n  console.log(foos);\n})().catch(console.error);","lang":"typescript","description":"Shows full setup: knex client, Mapper, table mapping, table creation, insert, and select."},"warnings":[{"fix":"Use TypeScript strict mode and manually verify complex queries.","message":"Only partial type safety — column names are type-checked, but not all SQL constructs (e.g., subqueries) enforce type constraints at compile time.","severity":"breaking","affected_versions":">=0.0.0"},{"fix":"Always pass a configured knex instance to the Mapper constructor.","message":"Mapper instances must be created with a Knex client; they are not standalone.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use exact database table names as strings.","message":"Table name in defineMapping must match actual SQL table name; no automatic pluralization or case conversion.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add useNullAsDefault: true to knex configuration when using SQLite3.","message":"SQLite3 requires useNullAsDefault: true in knex config, otherwise insert may fail.","severity":"deprecated","affected_versions":">=0.0.0"}],"env_vars":null,"search_vec":"'0.8.6':22 '2016':30 'aggreg':65 'auto':16 'auto-complet':15 'base':50 'builder':7 'cadenc':74 'check':94 'claus':59 'column':12,51 'compil':92 'compile-tim':91 'complet':17 'complex':61 'condit':62 'current':18 'databas':45 'elimin':47 'execut':72 'express':82 'full':90 'hood':68 'includ':60 'insert':55 'interfac':43 'javascript':98 'join':57 'key':83 'knex.js':32,69 'limit':84 'low':76 'major':27 'map':41 'name':52 'node':101 'ongo':78 'partial':37,86 'provid':36 'queri':6,71 'refer':13 'releas':23,73 'safe':11 'safeti':39,88 'select':54,81 'ship':95 'simpl':1 'sinc':29 'singl':26 'sql':3,5,100 'stabl':19 'string':49 'string-bas':48 'support':53 'tabl':46 'time':93 'transact':63 'type':2,10,38,87,97 'type-saf':9 'typeorm':34 'typescript':4,42,96,99 'unlik':31 'updat':56 'version':20,28 'work':79","created_at":"2026-06-05T17:01:44.737158+00:00","updated_at":"2026-06-05T17:01:44.737158+00:00","problems":[{"fix":"npm install simple-typed-sql@latest","cause":"Package not installed or version mismatch.","error":"Cannot find module 'simple-typed-sql'"},{"fix":"Use 'import knex from \"knex\"' for ESM or 'const knex = require(\"knex\");' for CJS.","cause":"Importing knex incorrectly (using default import in CJS context).","error":"TypeError: knex is not a function"},{"fix":"Ensure fieldName in defineNumber({ fieldName: 'foo_count' }) matches DB column; type may need explicit assertion.","cause":"TypeScript can't infer type for properties with custom fieldName.","error":"Property 'fooCount' does not exist on type '...'"}],"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/smphhh/simple-typed-sql#readme","github":"https://github.com/smphhh/simple-typed-sql","docs":null,"changelog":null,"pypi":null,"npm":"simple-typed-sql","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-05","next_check":"2026-09-03","install_tag":null}}