Registry / database / sql-wizard

sql-wizard

JSON →
library1.6.1jsnpmunverified

Generate SQL queries and Express REST routes from JavaScript objects. Version 1.6.1 provides sqlFind, sqlCreate, sqlUpdate, sqlDelete, sqlPopulate helpers for PostgreSQL (pg) with support for joins, sorting, pagination, OR/AND searches, wildcards, and debug mode. Also includes createSqlRestRoutesServerless for serverless Next.js/Vercel endpoints and Express route generation. Differentiator: minimal configuration, wraps raw SQL generation with option-based filtering, and supports serverless deployment out of the box.

npm install sql-wizard
INSTALL
IMPORT
SIG · SQL-WIZARD
S
sql-wizard
databasejavascriptv1.6.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.

sqlFind
import { sql } from 'sql-wizard'; const { sqlFind } = sql;
const { sqlFind } = require('sql-wizard');
ESM named export: import { sql } then destructure. CJS require works but not recommended.
createSqlRestRoutesServerless
import { createSqlRestRoutesServerless } from 'sql-wizard';
const createSqlRestRoutesServerless = require('sql-wizard').createSqlRestRoutesServerless;
ESM-only since v1.5.0? README shows import syntax. CJS require requires .default on some versions.
Server
const server = require('express')(); /* use from another package */
const { Server } = require('sql-wizard');
No Server symbol in sql-wizard; it uses Express routes via server functions.

Shows sqlCreate, sqlFind with OR search, and debug mode for generating SQL queries.

import { sql } from 'sql-wizard'; const { sqlFind, sqlCreate } = sql; import { Pool } from 'pg'; const pool = new Pool({ connectionString: process.env.DATABASE_URL ?? '' }); async function main() { // Create a new record const newPerson = await sqlCreate(pool, 'person', { name: 'Alice', email: 'alice@example.com' }); console.log('Created:', newPerson); // Find records with OR search const people = await sqlFind(pool, 'person', { name: 'Alice', email: 'alice' }, { any: true }); console.log('Found:', people); // Find with debug to see SQL const person = await sqlFind(pool, 'person', { id: 1 }, { debug: true }); console.log('Person:', person); } main().catch(console.error);
Debug
Known issues
breakingFrom version 1.5.0, options like limit, sort, group, join, fields, any, startsWith, endsWith, contains must be placed in `options` object instead of `query`.
fix
Move these parameters to the fourth argument (options) of sqlFind and similar functions.
affects: >=1.5.0
gotchasqlFind with `any: true` performs OR search on all provided conditions, which may return more results than expected if not used carefully.
fix
Add more specific conditions or use `any: false` for AND behavior.
affects: >=0.0.0
gotchaThe `startsWith`, `endsWith`, `contains` options are case-sensitive unless the database collation is case-insensitive.
fix
Use ILIKE or LOWER() in custom queries if case-insensitive search is needed.
affects: >=0.0.0
deprecatedThe `require` syntax for importing named exports may stop working in future ESM-only versions.
fix
Use ES module imports (import { sql } from 'sql-wizard') instead of require.
affects: >=1.6.0
Errors
Common errors & fixes
TypeError: sqlFind is not a function
Incorrect import: using destructured import directly without accessing the `sql` namespace.
fix
Use: import { sql } from 'sql-wizard';
const { sqlFind } = sql;
Error: password authentication failed for user '...'
Invalid DATABASE_URL or missing pg password.
fix
Set DATABASE_URL environment variable to a valid PostgreSQL connection string, e.g., postgres://user:pass@host:5432/db
TypeError: options.limit is not a number
Passing `limit` as a string instead of number in the options object.
fix
Use { limit: 10 } (number) instead of { limit: '10' }.
Upgrade
Version history
1.6.1latest on npm
Audit
Dependencies
pgrequiredsql helpers designed for pg pool.query interface
Agent activity
16 hits · last 30 days
node
14
Meta
1
OpenAI (training)
1
Resources
sql-wizard — npm install sql-wizard · libregistry