Registry / database / sql-params-format

sql-params-format

JSON →
library2.0.0jsnpmunverified

sql-params-format v2.0.0 extends pg-format with named parameter support for SQL query formatting. It allows using %I, %s, and %L placeholders with both positional and named arguments, and automatically converts Moment.js objects to Date objects. The library is stable with low release cadence. Differs from pg-format by supporting named parameters, while being a thin wrapper; ideal for dynamic query building in Node.js.

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.

Default import is the named parameter formatter. The package is ESM-only as of v2? Actually package.json has no "type": "module", but the README shows CommonJS style. Assuming legacy CJS.

import format from 'sql-params-format';

CommonJS usage; no named export for 'format'. Actually the module exports a single function, so require returns it directly.

const { format } = require('sql-params-format');

Packages does not ship TypeScript types; may need @types/ manual.

import format from 'sql-params-format';

Demonstrates named parameter formatting for SQL queries using %I, %s, %L placeholders with an object of values. Also shows fallback positional usage.

const format = require('sql-params-format'); // Named parameters const sql = 'SELECT * FROM %I:table WHERE name = %L:name AND age > %L:age'; const formatted = format(sql, { table: 'users', name: 'John', age: 30 }); console.log(formatted); // => SELECT * FROM "users" WHERE name = 'John' AND age > 30 // Positional usage (like pg-format) const sql2 = 'INSERT INTO %I (%s) VALUES (%L)'; const formatted2 = format(sql2, 'table', 'col1, col2', 'value'); console.log(formatted2); // => INSERT INTO "table" (col1, col2) VALUES 'value'
Debug
Known footguns
gotchaNamed parameters are case-sensitive. Ensure case matches between placeholder and object keys.
gotchaUnused named parameters are silently ignored. This can hide typos in parameter names.
gotchaMoment.js objects are automatically converted to Date. May cause unexpected behavior if you rely on moment being serialized differently.
deprecatedMoment.js conversion may be removed in future versions. Rely on Date 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
9 hits · last 30 days
gptbot
3
ahrefsbot
2
mj12bot
1
Resources