Registry / database / like-sql

like-sql

JSON →
library0.3.0jsnpmunverified

like-sql is a lightweight SQL query builder for Node.js (v0.3.0). It provides a simple API for building common SQL statements (CREATE/DROP DATABASE, INSERT, SELECT, SELECT ONE, EXISTS, COUNT, UPDATE, DELETE) with parameterized queries. It is designed to be extended for specific database drivers (e.g., mysql2). The library uses a builder pattern returning arrays of [sql, values]. It has a small footprint, no runtime dependencies, and is released under MIT. Compared to larger ORMs, like-sql focuses on minimal syntax and direct SQL generation.

npm install like-sql
INSTALL
IMPORT
SIG · LIKE-SQL
L
like-sql
databasejavascriptv0.3.0
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.

SQL
const SQL = require('like-sql')
import SQL from 'like-sql'
This library uses CommonJS; no ESM export. Use require.
Default export (new SQL())
const SQL = require('like-sql'); const builder = new SQL()
const { SQL } = require('like-sql')
The module exports a class directly, not a named export.
Library usage in ESM (if bundler allows)
import likeSql from 'like-sql'; const builder = new likeSql()
import { SQL } from 'like-sql'
If using a bundler that supports default imports from CJS, use default import.

Shows basic usage of like-sql to build INSERT, SELECT, UPDATE, and EXISTS queries.

const SQL = require('like-sql'); const builder = new SQL(); // Insert an IP address const [sql, values] = builder.insert('ips', { addr: '192.168.1.1', hits: 0 }); console.log(sql); // INSERT INTO `ips` (`addr`, `hits`) VALUES (?, ?) console.log(values); // ['192.168.1.1', 0] // Select with condition const [selectSql, selectValues] = builder.select('ips', ['addr', 'hits'], 'addr = ?', '192.168.1.1'); console.log(selectSql); // SELECT `addr`, `hits` FROM `ips` WHERE addr = ? console.log(selectValues); // ['192.168.1.1'] // Update with simple value const [updateSql, updateValues] = builder.update('ips', { hits: 1 }, 'addr = ?', '192.168.1.1'); console.log(updateSql); // UPDATE `ips` SET `hits` = ? WHERE addr = ? console.log(updateValues); // [1, '192.168.1.1'] // Exists check const [existsSql, existsValues] = builder.exists('ips', 'addr = ?', '192.168.1.1'); console.log(existsSql); // SELECT EXISTS(SELECT 1 FROM `ips` WHERE addr = ? LIMIT 1) console.log(existsValues); // ['192.168.1.1']
Debug
Known issues
gotchaAll table and column names are backtick-quoted automatically, which may cause issues if the identifier contains a backtick.
fix
Ensure identifiers do not contain backticks, or sanitize them before passing.
affects: >=0.0.0
gotchaThe update method with expression syntax requires an array: [{ column: 'expr' }, ...args]
fix
Use builder.update('ips', [{ hits: 'hits + ?' }, 1], 'addr = ?', req.ip)
affects: >=0.0.0
gotchaThe library does not validate SQL injection; it only uses parameterized placeholders. User-supplied identifiers (table/column names) are not parameterized.
fix
Do not pass user input directly as table/column names; validate or use a whitelist.
affects: >=0.0.0
gotchaThe query builder does not escape input values; it relies on the underlying driver to handle parameterization.
fix
Always use the parameterized values in the array; never concatenate user input into the SQL string.
affects: >=0.0.0
Errors
Common errors & fixes
TypeError: SQL is not a constructor
Incorrect import; possibly destructured or used default import incorrectly.
fix
Use const SQL = require('like-sql'); const builder = new SQL();
ReferenceError: SQL is not defined
Missing require statement or typo in package name.
fix
Ensure you have installed 'like-sql' and added const SQL = require('like-sql');
Upgrade
Version history
0.3.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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