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.

database
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.

Package does not ship ESM. Use CommonJS require().

const sqlClient = require('sql-client');

Direct named export; no nested namespaces.

const { PostgreSQLClient } = require('sql-client');

Also accessible as sqlClient.PostgreSQLClientPool after require().

const { PostgreSQLClientPool } = require('sql-client');

Direct named export. Use destructuring or sqlClient.MySQLClient.

const { MySQLClient } = require('sql-client');

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 footguns
gotchaBind variables use ? syntax for all backends. Do NOT use PostgreSQL's $1 style unless you explicitly parameterize.
gotchaClient connection string must be a valid URL. Improperly encoded passwords or special characters will cause connection failures.
breakingv3.0 removed support for Node.js <12. Older Node versions will fail to load native addons.
deprecatedThe Transaction class is deprecated in v3.0. Use explicit BEGIN/COMMIT via client.execute instead.
gotchaWhen using pool.borrow(), you must call pool.return() even on error to avoid exhausting the pool.
gotchaResultSet object may have different property names depending on database driver. Some use 'rows', others 'rows' as array of objects.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources