{"id":43783,"library":"safe-squel","title":"squel - SQL query string builder","description":"squel is a flexible and powerful SQL query string builder for JavaScript, supporting SELECT, UPDATE, INSERT, and DELETE queries with method chaining. It works in Node.js and browsers, supports parameterized queries for safe value escaping, and can be customized for any SQL command. Version 5.12.5 is the latest stable release. It is lightweight (~7 KB min+gzip) and actively maintained on GitHub, though the maintainer suggests considering more actively developed alternatives like Knex. Squel includes support for MySQL-specific commands and auto-quoting of field names. It ships TypeScript types and runs on Node >= 0.12.0.","status":"active","version":"5.12.5","language":"javascript","source_language":"en","source_url":"https://github.com/hiddentao/squel","tags":["javascript","sql","database","rdbms","typescript"],"install":[{"cmd":"npm install safe-squel","lang":"bash","label":"npm"},{"cmd":"yarn add safe-squel","lang":"bash","label":"yarn"},{"cmd":"pnpm add safe-squel","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Default import; squel is a default export. For CommonJS: const squel = require('squel').","wrong":"import { squel } from 'squel'","symbol":"squel","correct":"import squel from 'squel'"},{"note":"Named export for individual query builders. CommonJS: const { select } = require('squel').","wrong":"const select = require('squel').select","symbol":"select","correct":"import { select } from 'squel'"},{"note":"Utility to build custom SQL expressions with parameters. CommonJS: const { str } = require('squel').","wrong":"const str = require('squel').str","symbol":"str","correct":"import { str } from 'squel'"}],"quickstart":{"code":"import squel from 'squel';\n\n// Build a SELECT query\nconst query = squel.select()\n  .from('users')\n  .field('id')\n  .field('name')\n  .where('age > ?', 18)\n  .limit(10)\n  .toString();\n\nconsole.log(query);\n// SELECT `id`, `name` FROM `users` WHERE (age > 18) LIMIT 10\n\n// Parameterized version\nconst param = squel.select()\n  .from('users')\n  .where('age BETWEEN ? AND ?', 20, 30)\n  .toParam();\nconsole.log(param.text);\n// SELECT * FROM `users` WHERE (age BETWEEN ? AND ?)\nconsole.log(param.values);\n// [20, 30]","lang":"typescript","description":"Builds a SELECT query and a parameterized query using method chaining."},"warnings":[{"fix":"Pass { autoQuoteFieldNames: true } to squel.select() or the constructor.","message":"Auto-quoting field names is off by default. Many users expect table.field to be quoted but it isn't unless autoQuoteFieldNames is set.","severity":"gotcha","affected_versions":"*"},{"fix":"Use squel.str() inside the where clause with ? placeholders: .where('col = ?', squel.str('RANGE(?, ?)', a, b)).","message":"Using parameterized queries with squel.str() requires special attention to the ? placeholders. A common mistake is forgetting that squel.str() does not escape its own arguments.","severity":"gotcha","affected_versions":"*"},{"fix":"Migrate to Knex or another actively maintained query builder.","message":"The 'squel' package is no longer actively developed. The maintainer recommends considering alternatives like Knex.","severity":"deprecated","affected_versions":">=5.0.0"},{"fix":"Pass the squel instance directly, e.g., .from(squel.select().from('students'), 's').","message":"When building nested queries, ensure the inner query is passed as the first argument to .from() or .join() without calling .toString(). Passing a string will not auto-quote properly.","severity":"gotcha","affected_versions":"*"},{"fix":"Use .order('col', true, 'DESC') or .order('col', null, 'DESC') properly.","message":"The .order() method defaults to ASC. Specifying 'DESC' incorrectly (e.g., .order('col', 'DESC')) works but requires three arguments to match the method signature.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"search_vec":"'0.12.0':102 '5.12.5':50 '7':59 'activ':64,74 'altern':76 'auto':89 'auto-quot':88 'browser':33 'builder':5,15 'chain':27 'command':48,86 'consid':72 'custom':44 'databas':105 'delet':23 'develop':75 'escap':40 'field':92 'flexibl':9 'github':67 'gzip':62 'includ':80 'insert':21 'javascript':17,103 'kb':60 'knex':78 'latest':53 'lightweight':58 'like':77 'maintain':65,70 'method':26 'min':61 'mysql':84 'mysql-specif':83 'name':93 'node':101 'node.js':31 'parameter':35 'power':11 'queri':3,13,24,36 'quot':90 'rdbms':106 'releas':55 'run':99 'safe':38 'select':19 'ship':95 'specif':85 'sql':2,12,47,104 'squel':1,6,79 'stabl':54 'string':4,14 'suggest':71 'support':18,34,81 'though':68 'type':97 'typescript':96,107 'updat':20 'valu':39 'version':49 'work':29","created_at":"2026-06-05T17:01:27.284847+00:00","updated_at":"2026-06-05T17:01:27.284847+00:00","problems":[{"fix":"Add 'import squel from \"squel\"' (ESM) or 'const squel = require(\"squel\")' (CJS) at the top of your file.","cause":"Using squel without importing or requiring it.","error":"squel is not defined"},{"fix":"Use 'import squel from \"squel\"' (default import) or 'const squel = require(\"squel\")' (CommonJS).","cause":"Importing squel incorrectly (e.g., as a named import instead of default).","error":"TypeError: squel.select is not a function"},{"fix":"Run 'npm install squel' to install it.","cause":"squel is not installed.","error":"Cannot find module 'squel'"},{"fix":"Pass a positive integer to .limit() (e.g., .limit(10)).","cause":"Passing a non-integer or negative value to .limit().","error":"Invalid value for limit: Expected integer number, got ..."}],"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/hiddentao/squel#readme","github":"https://github.com/hiddentao/squel","docs":null,"changelog":null,"pypi":null,"npm":"safe-squel","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}}