Registry / database / safe-squel

safe-squel

JSON →
library5.12.5jsnpmunverified

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.

npm install safe-squel
INSTALL
IMPORT
SIG · SAFE-SQUEL
S
safe-squel
databasejavascriptv5.12.5
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

squel
import squel from 'squel'
import { squel } from 'squel'
Default import; squel is a default export. For CommonJS: const squel = require('squel').
select
import { select } from 'squel'
const select = require('squel').select
Named export for individual query builders. CommonJS: const { select } = require('squel').
str
import { str } from 'squel'
const str = require('squel').str
Utility to build custom SQL expressions with parameters. CommonJS: const { str } = require('squel').

Builds a SELECT query and a parameterized query using method chaining.

import squel from 'squel'; // Build a SELECT query const query = squel.select() .from('users') .field('id') .field('name') .where('age > ?', 18) .limit(10) .toString(); console.log(query); // SELECT `id`, `name` FROM `users` WHERE (age > 18) LIMIT 10 // Parameterized version const param = squel.select() .from('users') .where('age BETWEEN ? AND ?', 20, 30) .toParam(); console.log(param.text); // SELECT * FROM `users` WHERE (age BETWEEN ? AND ?) console.log(param.values); // [20, 30]
Debug
Known issues
gotchaAuto-quoting field names is off by default. Many users expect table.field to be quoted but it isn't unless autoQuoteFieldNames is set.
fix
Pass { autoQuoteFieldNames: true } to squel.select() or the constructor.
affects: *
gotchaUsing 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.
fix
Use squel.str() inside the where clause with ? placeholders: .where('col = ?', squel.str('RANGE(?, ?)', a, b)).
affects: *
deprecatedThe 'squel' package is no longer actively developed. The maintainer recommends considering alternatives like Knex.
fix
Migrate to Knex or another actively maintained query builder.
affects: >=5.0.0
gotchaWhen 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.
fix
Pass the squel instance directly, e.g., .from(squel.select().from('students'), 's').
affects: *
gotchaThe .order() method defaults to ASC. Specifying 'DESC' incorrectly (e.g., .order('col', 'DESC')) works but requires three arguments to match the method signature.
fix
Use .order('col', true, 'DESC') or .order('col', null, 'DESC') properly.
affects: *
Errors
Common errors & fixes
squel is not defined
Using squel without importing or requiring it.
fix
Add 'import squel from "squel"' (ESM) or 'const squel = require("squel")' (CJS) at the top of your file.
TypeError: squel.select is not a function
Importing squel incorrectly (e.g., as a named import instead of default).
fix
Use 'import squel from "squel"' (default import) or 'const squel = require("squel")' (CommonJS).
Cannot find module 'squel'
squel is not installed.
fix
Run 'npm install squel' to install it.
Invalid value for limit: Expected integer number, got ...
Passing a non-integer or negative value to .limit().
fix
Pass a positive integer to .limit() (e.g., .limit(10)).
Upgrade
Version history
5.12.5latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
8
Meta
2
Resources
safe-squel — npm install safe-squel · libregistry