Registry / database / sql-client

sql-client

JSON →
library3.0.0jsnpmunverified

A Node.js library (v3.0.0) that provides a consistent, simplified abstraction over PostgreSQL, MySQL, and SQLite3 databases. Released under MIT license on GitHub, with irregular release cadence. Key differentiators: unified ?-based bind variables across all backends, optional connection pooling with configurable limits and keep-alive, a batch SQL runner, and a transaction API that abstracts over connections. Smaller footprint than knex or sequelize but offers lower-level control.

npm install sql-client
INSTALL
IMPORT
SIG · SQL-CLIENT
S
sql-client
databasejavascriptv3.0.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.

default (require)
const sqlClient = require('sql-client');
import sqlClient from 'sql-client';
Package does not ship ESM. Use CommonJS require().
PostgreSQLClient
const { PostgreSQLClient } = require('sql-client');
const { postgresql: PostgreSQLClient } = require('sql-client');
Direct named export; no nested namespaces.
PostgreSQLClientPool
const { PostgreSQLClientPool } = require('sql-client');
const pool = new sqlClient.PostgreSQLClientPool()
Also accessible as sqlClient.PostgreSQLClientPool after require().
MySQLClient
const { MySQLClient } = require('sql-client');
const mysql = new (require('sql-client').MySQLClient)()
Direct named export. Use destructuring or sqlClient.MySQLClient.

Demonstrates basic query execution with PostgreSQLClient and connection pooling with PostgreSQLClientPool using environment variable for connection string.

const sqlClient = require('sql-client'); // PostgreSQL example const client = new sqlClient.PostgreSQLClient(process.env.DATABASE_URL ?? 'postgres://user:pass@localhost/dbname'); client.execute('SELECT 1 + ? AS sum', [2], (err, result) => { if (err) throw err; console.log('Sum:', result.rows[0].sum); // 3 client.disconnect(); }); // Connection pool example const pool = new sqlClient.PostgreSQLClientPool(process.env.DATABASE_URL ?? 'postgres://user:pass@localhost/dbname'); pool.open({ max_idle: 3, max_active: 5 }, () => { pool.execute('SELECT ? + ? AS total', [10, 20], (err, result) => { if (err) throw err; console.log('Total:', result.rows[0].total); // 30 pool.close(); }); });
Debug
Known issues
gotchaBind variables use ? syntax for all backends. Do NOT use PostgreSQL's $1 style unless you explicitly parameterize.
fix
Always use ? for bind parameters. For PostgreSQL, avoid $1, $2 unless you want literal text.
affects: >=1.0.0
gotchaClient connection string must be a valid URL. Improperly encoded passwords or special characters will cause connection failures.
fix
Ensure URI components are properly percent-encoded. Use Node's url.parse or new URL() to validate.
affects: >=1.0.0
breakingv3.0 removed support for Node.js <12. Older Node versions will fail to load native addons.
fix
Update Node.js to version 12 or later.
affects: >=3.0.0
deprecatedThe Transaction class is deprecated in v3.0. Use explicit BEGIN/COMMIT via client.execute instead.
fix
Replace new Transaction(client) with manual execute('BEGIN'), execute('COMMIT') etc.
affects: >=3.0.0
gotchaWhen using pool.borrow(), you must call pool.return() even on error to avoid exhausting the pool.
fix
Use try/finally or a callback that always returns the connection.
affects: >=1.0.0
gotchaResultSet object may have different property names depending on database driver. Some use 'rows', others 'rows' as array of objects.
fix
Check the documentation or console.log(resultset) to inspect structure.
affects: >=1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'sql-client'
Package not installed or Node.js cannot resolve it.
fix
Run npm install sql-client or ensure node_modules contains the package.
Error: getaddrinfo ENOTFOUND localhost
Database host 'localhost' not resolvable or database not running.
fix
Start your database server or check the connection string in DATABASE_URL.
TypeError: pool.borrow is not a function
Using pool object incorrectly; likely not an instance of ClientPool class.
fix
Ensure you created a pool: const pool = new sqlClient.PostgreSQLClientPool(url); pool.open(options, callback);
Error: bind message supplies 2 parameters but prepared statement requires 1
Mismatch between number of ? placeholders and provided array elements.
fix
Ensure array length matches placeholder count: execute('SELECT ?, ?', [1, 2], ...).
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
18 hits · last 30 days
node
14
Meta
2
OpenAI (training)
1
Resources
sql-client — npm install sql-client · libregistry