{"id":41998,"library":"sql-params-format","title":"sql-params-format","description":"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.","status":"active","version":"2.0.0","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install sql-params-format","lang":"bash","label":"npm"},{"cmd":"yarn add sql-params-format","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-params-format","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core formatting engine; sql-params-format delegates to pg-format after resolving named parameters.","package":"pg-format","optional":false}],"imports":[{"note":"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.","wrong":"const format = require('sql-params-format');","symbol":"format","correct":"import format from 'sql-params-format';"},{"note":"CommonJS usage; no named export for 'format'. Actually the module exports a single function, so require returns it directly.","wrong":"const format = require('sql-params-format').default;","symbol":"format","correct":"const { format } = require('sql-params-format');"},{"note":"Packages does not ship TypeScript types; may need @types/ manual.","wrong":"","symbol":"TypeScript types","correct":"import format from 'sql-params-format';"}],"quickstart":{"code":"const format = require('sql-params-format');\n\n// Named parameters\nconst sql = 'SELECT * FROM %I:table WHERE name = %L:name AND age > %L:age';\nconst formatted = format(sql, { table: 'users', name: 'John', age: 30 });\nconsole.log(formatted);\n// => SELECT * FROM \"users\" WHERE name = 'John' AND age > 30\n\n// Positional usage (like pg-format)\nconst sql2 = 'INSERT INTO %I (%s) VALUES (%L)';\nconst formatted2 = format(sql2, 'table', 'col1, col2', 'value');\nconsole.log(formatted2);\n// => INSERT INTO \"table\" (col1, col2) VALUES 'value'","lang":"javascript","description":"Demonstrates named parameter formatting for SQL queries using %I, %s, %L placeholders with an object of values. Also shows fallback positional usage."},"warnings":[{"fix":"Use exact casing for parameter names in SQL string and object keys.","message":"Named parameters are case-sensitive. Ensure case matches between placeholder and object keys.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Review SQL string for all placeholder names; consider linting or validation.","message":"Unused named parameters are silently ignored. This can hide typos in parameter names.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pass plain Date objects or strings to avoid automatic conversion.","message":"Moment.js objects are automatically converted to Date. May cause unexpected behavior if you rely on moment being serialized differently.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use Date objects instead of Moment instances.","message":"Moment.js conversion may be removed in future versions. Rely on Date objects.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"search_vec":"'allow':23 'argument':35 'automat':37 'build':70 'cadenc':51 'convert':38 'date':42 'differ':52 'dynam':68 'extend':10 'format':4,8,13,21,56 'ideal':66 'javascript':73 'l':28 'librari':45 'low':49 'moment.js':39 'name':15,34,59 'node.js':72 'object':40,43 'param':3,7 'paramet':16,60 'pg':12,55 'pg-format':11,54 'placehold':29 'posit':32 'queri':20,69 'releas':50 'sql':2,6,19 'sql-params-format':1,5 'stabl':47 'support':17,58 'thin':64 'use':24 'v2.0.0':9 'wrapper':65","created_at":"2026-06-04T18:55:07.559664+00:00","updated_at":"2026-06-04T18:55:07.559664+00:00","problems":[{"fix":"Use `import format from 'sql-params-format'` (default) or `const format = require('sql-params-format');` in CJS.","cause":"Importing the default export incorrectly in ESM environment.","error":"TypeError: format is not a function"},{"fix":"Add the missing key to the params object: `format(sql, { foo: 'value' })`.","cause":"Attempted to use a named parameter that isn't provided in the params object.","error":"SyntaxError: Named parameter not found: foo"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":null,"github":null,"docs":null,"changelog":null,"pypi":null,"npm":"sql-params-format","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-04","next_check":"2026-09-02","install_tag":null}}