{"id":23011688,"url":"https://github.com/jhuntdev/sql-string-qb","last_synced_at":"2025-04-23T01:27:48.608Z","repository":{"id":267649923,"uuid":"901789530","full_name":"jhuntdev/sql-string-qb","owner":"jhuntdev","description":"A simple JavaScript/TypeScript library for assembling complex SQL queries. Miniscule, type-safe, and dependency-free.","archived":false,"fork":false,"pushed_at":"2025-04-02T03:33:43.000Z","size":38,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-02T03:41:49.201Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jhuntdev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-12-11T10:15:13.000Z","updated_at":"2025-04-02T03:33:46.000Z","dependencies_parsed_at":"2024-12-11T16:35:00.423Z","dependency_job_id":"507551fd-c73d-466c-a861-4b08874afb5d","html_url":"https://github.com/jhuntdev/sql-string-qb","commit_stats":null,"previous_names":["jhuntdev/sql-string-qb"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhuntdev%2Fsql-string-qb","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhuntdev%2Fsql-string-qb/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhuntdev%2Fsql-string-qb/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jhuntdev%2Fsql-string-qb/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jhuntdev","download_url":"https://codeload.github.com/jhuntdev/sql-string-qb/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250351371,"owners_count":21416310,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-12-15T10:10:33.304Z","updated_at":"2025-04-23T01:27:48.602Z","avatar_url":"https://github.com/jhuntdev.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SQL String QB🏈\n\n## A simple JavaScript/TypeScript library for assembling complex SQL queries. Miniscule, type-safe, and dependency-free.\n\nInspired by classNames and several tagged template libraries, this small but powerful SQL query builder allows you to elegantly craft complex SQL statements without compromising code readability or performance. Its output is an object which drops right into popular SQL database clients. The `qb.t` function automatically breaks out values from template literals and can be used either on its own or as an argument in `qb()`.\n\n_WARNING! Variables outside a `qb.t` function will go directly into the query and should be escaped first._\n\n## Installation\n\nInstall SQL String QB🏈 from npm\n\nWith npm:\n```bash\nnpm install --save sql-string-qb\n```\nor using yarn:\n```bash\nyarn add sql-string-qb\n```\n\n## Usage\n\n```javascript\nimport qb from 'sql-string-qb' \n\nconst showPrice = false\nconst category = 'sporting-goods'\nconst sortColumn = undefined\nconst sortOrder = undefined\n\nconst query = qb(\n    'SELECT `id`, `name`',\n    showPrice \u0026\u0026 ', `price`',\n    'FROM `products` WHERE',\n    category ? qb.t`\\`category\\` = ${category}` : '\\`category\\` IS NULL',\n    'ORDER BY',\n    sortColumn || '`createdAt`',\n    sortOrder || 'DESC',\n    'LIMIT 12'\n)\n\ntypeof query     // =\u003e \"object\"\nquery.toString() // =\u003e \"SELECT `id`, `name` FROM `products` WHERE `category` = ? ORDER BY `createdAt` DESC LIMIT 12\"\nquery.sql        // =\u003e \"SELECT `id`, `name` FROM `products` WHERE `category` = ? ORDER BY `createdAt` DESC LIMIT 12\"\nquery.query      // =\u003e \"SELECT `id`, `name` FROM `products` WHERE `category` = ? ORDER BY `createdAt` DESC LIMIT 12\"\nquery.text       // =\u003e \"SELECT `id`, `name` FROM `products` WHERE `category` = $1 ORDER BY `createdAt` DESC LIMIT 12\"\nquery.statement  // =\u003e \"SELECT `id`, `name` FROM `products` WHERE `category` = :1 ORDER BY `createdAt` DESC LIMIT 12\"\nquery.values     // =\u003e [\"sporting-goods\"]\n\npg.query(query) // Uses query.text and query.values\nmysql.query(query) // Uses query.sql and query.values\nmysql2.query(query) // Uses query.sql and query.values\nsequelize.query(query) // Uses query.query and query.values\noracledb.execute(query) // Uses query.statement and query.values\n\n// Experimental Helper Functions\nqb.set({\n    column_1: 'value 1',\n    column_2: qb.unescaped('value 2')\n}) // =\u003e \"SET `column_1` = ?, `column_2` = 'value 2'\" [\"value1\"]\nqb.values({\n    column_1: 'value 1',\n    column_2: qb.unescaped('value 2')\n}) // =\u003e \"(`column_1`, `column_2`) VALUES (?, 'value 2')\" [\"value1\"]\nqb.in([\n    'value 1',\n    qb.unescaped('value 2')\n]) // =\u003e \"IN (?, 'value 2')\" [\"value1\"]\n```\n\n## License\n\nThis project is licensed under the [MIT License](LICENSE).","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhuntdev%2Fsql-string-qb","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjhuntdev%2Fsql-string-qb","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjhuntdev%2Fsql-string-qb/lists"}