Registry / database / sql-query-factory

sql-query-factory

JSON →
library1.1.12jsnpmunverified

A typed SQL query builder for Node.js, v1.1.12 (latest). Provides a fluent API for generating SQL queries including SELECT, INSERT, UPDATE, CREATE TABLE, and DELETE, with support for WHERE conditions, ordering, joins, aggregations, and subqueries. Includes TypeScript definitions. Differentiator: lightweight with no dependencies, synchronous, and supports common SQL constructs like BETWEEN, IN, LIKE, and ORDER BY.

npm install sql-query-factory
INSTALL
IMPORT
SIG · SQL-QUERY-FACTORY
S
sql-query-factory
databasejavascriptv1.1.12
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-query-factory';
const sql = require('sql-query-factory'); sql.select(...)
Named import; library is ESM and CJS compatible.
insertInto
import { insertInto } from 'sql-query-factory';
import { insertInto } from 'sql-query-factory'; (no wrong pattern)
Named import for INSERT queries.
update
import { update } from 'sql-query-factory';
Named import for UPDATE queries.
createTable
import { createTable } from 'sql-query-factory';
Named import for CREATE TABLE queries.

Demonstrates SELECT, INSERT, UPDATE, DELETE, and CREATE TABLE queries using the fluent builder pattern.

import { select, insertInto, createTable, update, deleteFrom } from 'sql-query-factory'; // SELECT query const query = select('*') .from('users') .where('age') .greaterThan(18) .and('city') .equal('Paris') .orderBy('name') .limit(10) .build(); console.log(query); // SELECT * FROM users WHERE age > 18 AND city = 'Paris' ORDER BY name LIMIT 10; // INSERT const insertQuery = insertInto('users') .keys('name', 'age') .values('Alice', 30) .build(); console.log(insertQuery); // INSERT INTO users (name, age) VALUES('Alice', 30); // CREATE TABLE const createQuery = createTable('products') .column('id').type('INTEGER').primaryKey().autoIncrement() .column('name').type('TEXT').notNull() .build(); console.log(createQuery); // CREATE TABLE products ( id INTEGER PRIMARY KEY AUTO_INCREMENT, name TEXT NOT NULL); // UPDATE const updateQuery = update('users') .set('name', 'Bob') .where('id').equal(1) .build(); console.log(updateQuery); // UPDATE users SET name = 'Bob' WHERE id = 1; // DELETE const deleteQuery = deleteFrom().from('users').where('id').equal(1).build(); console.log(deleteQuery); // DELETE FROM users WHERE id = 1;
Debug
Known issues
gotchaAll string values are automatically quoted with single quotes, but numeric values are not quoted. Mixing types in values may produce unexpected quoting if you pass a number where a string is expected.
fix
Ensure values passed to .values() are consistent in type; use String() for explicit strings.
affects: >=1.0.0
gotchaThe .from() method for DELETE must be called after deleteFrom() as deleteFrom().from('table').build(), but deleteFrom() alone does not include FROM; omitting .from() will produce malformed SQL.
fix
Always chain .from('table') after deleteFrom() before .build().
affects: >=1.0.0
gotchaColumn names are not escaped; using reserved keywords or special characters (e.g., spaces) may produce invalid SQL.
fix
Manually escape column names (e.g., backticks) in the string if needed; the library does not handle quoting.
affects: >=1.0.0
gotchaThe .orderBy() method takes a single column name; it does not support multiple columns or ASC/DESC modifiers.
fix
Use .orderBy('column1 ASC').orderBy('column2 DESC') or concatenate manually.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: select(...).from is not a function
Forgetting to call .build() and using the object incorrectly, or incorrect import (default vs named).
fix
Ensure you use named imports: import { select } from 'sql-query-factory'; then select('*').from('table').build();
ReferenceError: select is not defined
Using the function without importing it.
fix
Import the function: import { select } from 'sql-query-factory'; or use require('sql-query-factory').select.
SyntaxError: Unexpected token '.' in JSON at position ...
Trying to .build() on a value that is not a query builder chain (e.g., calling .build() after a condition that returns a string).
fix
Ensure the chain is complete: .build() should only be called on the final query object, not on a conditional like .equal('value').build().
Upgrade
Version history
1.1.12latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
17 hits · last 30 days
node
12
Meta
2
OpenAI (training)
1
Resources
sql-query-factory — npm install sql-query-factory · libregistry