{"id":44068,"library":"ts-sql-query","title":"ts-sql-query","description":"ts-sql-query is a type-safe SQL query builder for TypeScript, inspired by Java's QueryDSL and JOOQ, supporting MariaDB, MySQL, Oracle, PostgreSQL, SQLite, and SQL Server. Current stable version is 1.67.0, with regular releases following minor updates. It emphasizes compile-time type checking for SQL queries, dynamic query construction, and avoids ORM patterns, making it suitable for projects requiring full SQL control without string concatenation. Unlike Knex or TypeORM, it provides first-class TypeScript support with inferred result types and no runtime schema generation.","status":"active","version":"1.67.0","language":"javascript","source_language":"en","source_url":"https://github.com/juanluispaz/ts-sql-query","tags":["javascript","jooq","querydsl","typescript","mariadb","mysql","oracle","sqlite","sqlserver"],"install":[{"cmd":"npm install ts-sql-query","lang":"bash","label":"npm"},{"cmd":"yarn add ts-sql-query","lang":"bash","label":"yarn"},{"cmd":"pnpm add ts-sql-query","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ts-sql-query does not expose a global export; you must import from specific subpaths like 'ts-sql-query/Connection'.","wrong":"import { Connection } from 'ts-sql-query'","symbol":"Connection","correct":"import { Connection } from 'ts-sql-query/Connection'"},{"note":"Table is used to define database tables; import from 'ts-sql-query/Table'.","wrong":"import { Table } from 'ts-sql-query/Table' (only correct)","symbol":"Table","correct":"import { Table } from 'ts-sql-query/Table'"},{"note":"Database-specific connections are in 'ts-sql-query/connections/' subpaths.","wrong":"import { PostgreSqlConnection } from 'ts-sql-query'","symbol":"PostgreSqlConnection","correct":"import { PostgreSqlConnection } from 'ts-sql-query/connections/PostgreSqlConnection'"},{"note":"Query runners are in 'ts-sql-query/queryRunners/' subpaths.","wrong":"import { ConsumerQueryRunner } from 'ts-sql-query'","symbol":"ConsumerQueryRunner","correct":"import { ConsumerQueryRunner } from 'ts-sql-query/queryRunners/ConsumerQueryRunner'"}],"quickstart":{"code":"import { Table } from 'ts-sql-query/Table';\nimport { PostgreSqlConnection } from 'ts-sql-query/connections/PostgreSqlConnection';\nimport { ConsumerQueryRunner } from 'ts-sql-query/queryRunners/ConsumerQueryRunner';\n\nclass TCustomer extends Table {\n  id = this.autogeneratedPrimaryKey('id', 'int');\n  firstName = this.column('first_name', 'string');\n  lastName = this.column('last_name', 'string');\n  birthday = this.optionalColumn('birthday', 'date');\n  constructor() { super('customer'); }\n}\nconst tCustomer = new TCustomer();\n\nasync function example() {\n  const connection = new PostgreSqlConnection(new ConsumerQueryRunner(async (query, params) => {\n    console.log('SQL:', query, 'Params:', params);\n    return { rows: [], affectedRows: 0 };\n  }));\n  const customerId = 10;\n  const customerWithId = await connection.selectFrom(tCustomer)\n    .where(tCustomer.id.equals(customerId))\n    .select({\n      id: tCustomer.id,\n      firstName: tCustomer.firstName,\n      lastName: tCustomer.lastName,\n      birthday: tCustomer.birthday\n    })\n    .executeSelectOne();\n  console.log(customerWithId);\n}\nexample().catch(console.error);","lang":"typescript","description":"Defines a customer table, creates a connection to PostgreSQL, and runs a type-safe select query with one result."},"warnings":[{"fix":"Update imports to use the new subpath, e.g., 'ts-sql-query/connections/PostgreSqlConnection'.","message":"In version 1.50.0, the import path for connections changed from 'ts-sql-query/Connection' to 'ts-sql-query/connections/<Database>Connection'.","severity":"breaking","affected_versions":"<1.50.0"},{"fix":"Switch to importing from 'ts-sql-query/connections/<Database>Connection'.","message":"Using 'ts-sql-query/Connection' directly is deprecated in favor of 'ts-sql-query/connections/*'.","severity":"deprecated","affected_versions":">=1.50.0"},{"fix":"Ensure your table class extends `Table` and correctly passes the table name to `super()`.","message":"Table classes must extend the `Table` class and call `super(tableName)` with the actual database table name. Not doing so causes runtime errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Use `executeSelectNoneOrOne()` if you expect no row, or catch the error.","message":"In version 1.60.0, the method `executeSelectOne` changed to throw an error if no row is found; previously it returned `undefined`.","severity":"breaking","affected_versions":"<1.60.0"},{"fix":"Always import from specific subpaths like 'ts-sql-query/Table', 'ts-sql-query/Connection', etc.","message":"Importing from 'ts-sql-query' (the root) does not export anything; you must use explicit subpaths. This is intentional to avoid naming conflicts.","severity":"gotcha","affected_versions":">=0.1.0"}],"env_vars":null,"search_vec":"'1.67.0':39 'avoid':60 'builder':16 'check':52 'class':83 'compil':49 'compile-tim':48 'concaten':74 'construct':58 'control':71 'current':35 'dynam':56 'emphas':47 'first':82 'first-class':81 'follow':43 'full':69 'generat':94 'infer':87 'inspir':19 'java':21 'javascript':95 'jooq':25,96 'knex':76 'make':63 'mariadb':27,99 'minor':44 'mysql':28,100 'oracl':29,101 'orm':61 'pattern':62 'postgresql':30 'project':67 'provid':80 'queri':4,8,15,55,57 'querydsl':23,97 'regular':41 'releas':42 'requir':68 'result':88 'runtim':92 'safe':13 'schema':93 'server':34 'sql':3,7,14,33,54,70 'sqlite':31,102 'sqlserver':103 'stabl':36 'string':73 'suitabl':65 'support':26,85 'time':50 'ts':2,6 'ts-sql-queri':1,5 'type':12,51,89 'type-saf':11 'typeorm':78 'typescript':18,84,98 'unlik':75 'updat':45 'version':37 'without':72","created_at":"2026-06-05T17:02:49.216468+00:00","updated_at":"2026-06-05T17:02:49.216468+00:00","problems":[{"fix":"Change import to a specific subpath, e.g., import { Table } from 'ts-sql-query/Table'.","cause":"Importing from the root 'ts-sql-query' instead of a specific subpath like 'ts-sql-query/Table'.","error":"Cannot find module 'ts-sql-query' or its corresponding type declarations."},{"fix":"Ensure the class extends `Table` and calls `super('table_name')`.","cause":"Table class not properly extending `Table` or not calling `super(tableName)`.","error":"Property 'id' does not exist on type 'TCustomer'."},{"fix":"Check the query runner implementation; ensure it returns an object with `rows` and `affectedRows`.","cause":"The connection object is not properly instantiated or the query runner is misconfigured.","error":"TypeError: Cannot read properties of undefined (reading 'selectFrom')"},{"fix":"Check the query runner interface; it should be `(query: string, params: any[]) => Promise<{ rows: any[], affectedRows: number }>`.","cause":"Using a query runner that does not match the expected signature, e.g., passing wrong types.","error":"No overload matches this call. Overload 1 of 2, '(query: string, params: any[]): Promise<...>', gave the following error."}],"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://ts-sql-query.readthedocs.io/","github":"https://github.com/juanluispaz/ts-sql-query","docs":null,"changelog":null,"pypi":null,"npm":"ts-sql-query","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}}