{"library":"sql-select-ts","title":"SQL Select TS Query Builder","type":"library","description":"sql-select-ts is a modern, database-agnostic SELECT query builder for JavaScript and TypeScript, currently stable at version 2.0.18. It distinguishes itself through its composable API and strong static type checking, making it an excellent choice for projects prioritizing type safety and maintainable SQL generation. The package exhibits a frequent release cadence, with numerous minor updates and bug fixes being published regularly, indicating active development and responsiveness to community feedback. Its core value proposition lies in enabling developers to construct complex SELECT queries programmatically without sacrificing type safety or database portability, moving beyond raw string concatenation or less type-safe alternatives. It focuses specifically on SELECT statements, offering a streamlined API for this common database operation, and is suitable for both Node.js and browser environments.","language":"javascript","status":"active","last_verified":"Wed Apr 22","install":{"commands":["npm install sql-select-ts"],"cli":null},"imports":["import { select } from 'sql-select-ts'","import { column } from 'sql-select-ts'","import { table } from 'sql-select-ts'","import { raw } from 'sql-select-ts'"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":"https://lucasavila00.github.io/sql-select-ts/","github":"https://github.com/lucasavila00/sql-select-ts","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/sql-select-ts","openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import { select, column, table, raw } from 'sql-select-ts';\n\ninterface User {\n  id: number;\n  name: string;\n  email: string;\n  createdAt: Date;\n}\n\ninterface Post {\n  id: number;\n  userId: number;\n  title: string;\n}\n\nconst users = table<User>('users');\nconst posts = table<Post>('posts');\n\n// Build a complex SELECT query with joins, conditions, grouping, and ordering\nconst query = select(\n  column(users.id),\n  column(users.name).as('userName'),\n  column(users.email),\n  raw('COUNT(posts.id)').as('postCount')\n)\n  .from(users)\n  .leftJoin(posts)\n  .on(column(users.id).eq(column(posts.userId)))\n  .where(column(users.createdAt).gt(raw(\"NOW() - INTERVAL '1 year'\")))\n  .groupBy(column(users.id), column(users.name), column(users.email))\n  .orderBy(column(users.name).asc())\n  .limit(10)\n  .offset(0);\n\nconst queryString = query.toSQL();\nconsole.log(queryString);\n/*\nExpected output:\nSELECT users.id, users.name AS userName, users.email, COUNT(posts.id) AS postCount\nFROM users\nLEFT JOIN posts ON users.id = posts.userId\nWHERE users.createdAt > NOW() - INTERVAL '1 year'\nGROUP BY users.id, users.name, users.email\nORDER BY users.name ASC\nLIMIT 10 OFFSET 0\n*/","lang":"typescript","description":"Demonstrates building a multi-table SELECT query with aliased columns, aggregates, joins, complex WHERE clauses, grouping, ordering, and pagination, then converts it to a raw SQL string.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}