Registry / database / embrace-sql

embrace-sql

JSON →
library2.0.1jsnpmunverified

Embrace SQL is a JavaScript library for composing SQL queries programmatically using a chainable, fluent API. Current stable version is 2.0.1. It focuses on composing dynamic SQL with a simple, intuitive API that leverages tagged template literals. Key differentiators include zero dependencies, support for PostgreSQL style queries, and a lightweight footprint compared to full ORMs. The library is released as a single package with CJS and ESM exports. It is ideal for projects that need to build SQL queries without the overhead of an ORM.

npm install embrace-sql
INSTALL
IMPORT
SIG · EMBRACE-SQL
E
embrace-sql
databasejavascriptv2.0.1
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.

default
import sql from 'embrace-sql'
import { sql } from 'embrace-sql'
Default export is the main query builder. Named export does not exist.
sql
const sql = require('embrace-sql')
CJS require works for default export.
types
import type { QueryBuilder } from 'embrace-sql'
TypeScript types are available; QueryBuilder is an internal type.

Demonstrates basic usage: creating parameterized queries and chaining methods.

import sql from 'embrace-sql'; const query = sql`SELECT * FROM users WHERE age > ${21}`; console.log(query.text); // 'SELECT * FROM users WHERE age > $1' console.log(query.values); // [21] // Chainable API const q = sql`SELECT * FROM users` .where`age > ${18}` .orderBy`name` .limit(10); console.log(q.compile()); // { text: 'SELECT * FROM users WHERE age > $1 ORDER BY name LIMIT $2', values: [18, 10] }
Debug
Known issues
gotchaTagged template literals must be used correctly; values are automatically parameterized.
fix
Always use backticks with the tag: sql`...${value}...`
affects: >=1.0.0
breakingVersion 2.0.0 changed the chainable API: previously `.where(sql\`...\`)` was used, now it's `.where\`...\`.
fix
Update to use tagged template syntax: `.where\`condition\``
affects: <2.0.0
deprecatedThe `.and` and `.or` methods were deprecated in 2.0.1 in favor of combining conditions with `.where`.
fix
Use `.where\`cond1 AND cond2\`` instead.
affects: >=2.0.1
gotchaThe `compile()` method returns an object with `text` and `values`; not a string.
fix
Use `query.text` and `query.values` when passing to a database driver.
affects: >=1.0.0
breakingVersion 2.0 removed support for Node.js < 14.
fix
Upgrade Node.js to >=14.
affects: >=2.0.0
gotchaIdentifier interpolation (e.g., column names) must be done differently; direct variable interpolation is treated as values.
fix
Use `sql.raw` for identifiers: sql`SELECT ${sql.raw('col')} FROM table`
affects: >=1.0.0
securityUsing `sql.raw` with unsanitized user input can lead to SQL injection.
fix
Never pass user-generated strings to `sql.raw` without validation.
affects: >=1.0.0
Errors
Common errors & fixes
SyntaxError: Unexpected template string
Using tagged template without backticks or forgetting the tag
fix
Write: sql`SELECT * FROM users`
TypeError: sql is not a function
Importing named export instead of default
fix
Use: import sql from 'embrace-sql'
Cannot find module 'embrace-sql'
Package not installed or not in node_modules
fix
Run: npm install embrace-sql
Upgrade
Version history
2.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
8
Resources
embrace-sql — npm install embrace-sql · libregistry