Registry / database / sql-bricks

sql-bricks

JSON →
library3.0.1jsnpmunverified

SQL Bricks.js is a transparent, schemaless library for building and composing SQL-92 statements (SELECT, INSERT, UPDATE, DELETE) in JavaScript. Current stable version is 3.0.1. It has no production dependencies, single file (~1,100 lines), over 200 tests, and ships TypeScript types. Compared to Knex (20k lines, schema-based) and Squel (1.7k lines), sql-bricks offers a minimal, zero-dependency alternative with dialect-specific extensions for PostgreSQL, MySQL, and SQLite via separate packages.

npm install sql-bricks
INSTALL
IMPORT
SIG · SQL-BRICKS
S
sql-bricks
databasejavascriptv3.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.

select
import { select } from 'sql-bricks'
const select = require('sql-bricks').select;
ESM import is preferred; CJS still works but is legacy. The library exports named functions, not a default export.
insert
import { insert } from 'sql-bricks'
import insert from 'sql-bricks';
There is no default export; must use named import.
SqlBricks (full object)
import * as SqlBricks from 'sql-bricks'
import SqlBricks from 'sql-bricks'
Use namespace import to access all functions, since there is no default export.
toParams
const query = select().from('table').toParams()
const query = select().from('table').toString()
toParams() is safer (parameterized) and recommended over toString().

Shows how to build SELECT, INSERT, UPDATE, DELETE queries with toParams() (parameterized) and toString(). Uses named imports and demonstrates basic WHERE, ORDER BY, LIMIT, OFFSET.

import { select, insert, update, delete as del } from 'sql-bricks'; // Build a SELECT query const query = select('id', 'name') .from('users') .where({ age: 25 }) .orderBy('name') .limit(10) .offset(0); // Get parameterized query (recommended) const params = query.toParams(); console.log(params.text); // "SELECT id, name FROM users WHERE age = $1 ORDER BY name LIMIT $2 OFFSET $3" console.log(params.values); // [25, 10, 0] // Or get raw SQL string (less safe) console.log(query.toString()); // "SELECT id, name FROM users WHERE age = 25 ORDER BY name LIMIT 10 OFFSET 0" // INSERT const ins = insert('users', { id: 1, name: 'John' }); console.log(ins.toString()); // "INSERT INTO users (id, name) VALUES (1, 'John')" // UPDATE const upd = update('users').set({ name: 'Jane' }).where({ id: 1 }); console.log(upd.toString()); // "UPDATE users SET name = 'Jane' WHERE id = 1" // DELETE const delQuery = del('users').where({ id: 1 }); console.log(delQuery.toString()); // "DELETE FROM users WHERE id = 1"
Debug
Known issues
gotchaPostgreSQL extensions (LIMIT, OFFSET, etc.) are NOT included in core sql-bricks. Use sql-bricks-postgres for full Postgres support.
fix
Install sql-bricks-postgres and import from that package instead.
affects: >=3.0.0
gotchatoString() does NOT parameterize values; it does basic escaping only. Use toParams() for SQL injection protection.
fix
Use .toParams() instead of .toString() for all queries that include user input.
affects: >=1.0.0
gotchadelete is a reserved word in JavaScript; you cannot use it as a variable name directly. Must alias when importing.
fix
Use `import { delete as del } from 'sql-bricks'` or access via `SqlBricks.delete`.
affects: >=1.0.0
deprecatedCJS require() style is not recommended; ESM imports are preferred.
fix
Switch to `import { ... } from 'sql-bricks'` in ESM environments.
affects: >=3.0.0
gotchaorderBy() does not support ASC/DESC/COLLATE options per issue #73 (still unresolved).
fix
Manually append ' ASC' or ' DESC' to the column string, e.g., .orderBy('name DESC').
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'select')
Using namespace import incorrectly (e.g., import SqlBricks from 'sql-bricks' which gives undefined).
fix
Use import * as SqlBricks from 'sql-bricks' or import { select } from 'sql-bricks'.
ReferenceError: delete is not defined
Using 'delete' as a variable name (reserved keyword).
fix
Alias the import: import { delete as del } from 'sql-bricks'.
Error: LIMIT clause not yet implemented
Using core sql-bricks which does not support LIMIT (it's in dialect extensions).
fix
Install sql-bricks-postgres (or -sqlite, -mysql) and import from that package.
Upgrade
Version history
3.0.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
16 hits · last 30 days
node
12
Meta
1
OpenAI (training)
1
Resources
sql-bricks — npm install sql-bricks · libregistry