{"id":43950,"library":"sql-statement","title":"sql-statement","description":"sql-statement is a tiny, tree-shakeable SQL statement builder (v1.1.0, last updated 2025) that safely escapes identifiers and values using placeholders (? for values, ?? for identifiers). Unlike ORMs or full query builders, it provides minimal abstraction: you write raw SQL fragments and use append, appendList, and appendPairs to compose queries. Ships TypeScript definitions and supports MySQL, PostgreSQL, and SQLite quoting styles via named exports (mysql, Pg, Sqlite). No database connectivity — generates final SQL strings for use with any driver. Release cadence is low; package is stable and lightweight (no dependencies).","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/kawanet/sql-statement","tags":["javascript","mysql","pg","placeholder","postgresql","sql","sqlite","typescript"],"install":[{"cmd":"npm install sql-statement","lang":"bash","label":"npm"},{"cmd":"yarn add sql-statement","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-statement","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The package exports dialect-specific builders. `mysql` is a function that constructs a SQL instance with MySQL quoting. The default export does not exist.","wrong":"import SQL from 'sql-statement'","symbol":"SQL","correct":"import { mysql as SQL } from 'sql-statement'"},{"note":"For PostgreSQL quoting, use the named export Pg. CommonJS require works but is not preferred with ESM.","wrong":"const { Pg } = require('sql-statement')","symbol":"Pg","correct":"import { Pg as SQL } from 'sql-statement'"},{"note":"Sqlite is the correct named export for SQLite quoting. The generic SQL name is not exported.","wrong":"import { SQL } from 'sql-statement'","symbol":"Sqlite","correct":"import { Sqlite } from 'sql-statement'"}],"quickstart":{"code":"import { mysql as SQL } from 'sql-statement';\n\nconst tableName = 'users';\nconst id = 'AC3C21E7';\nconst sql = new SQL();\nsql.append('SELECT * FROM ?? WHERE id = ?', tableName, id);\n\nconsole.log(String(sql)); // => \"SELECT * FROM `users` WHERE id = 'AC3C21E7'\"","lang":"typescript","description":"Shows basic usage: instantiating a MySQL-dialect SQL builder, appending a query with placeholders, and converting to final string."},"warnings":[{"fix":"Import the dialect: import { mysql as SQL } from 'sql-statement'","message":"SQL class is not exported directly; use dialect-specific named exports like mysql, Pg, or Sqlite.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Always use '??' for column/table names and '?' for values. Example: sql.append('SELECT ?? FROM ?? WHERE ?', 'name', 'users', {id: 1})","message":"Placeholder '??' escapes identifiers, '?' escapes values. Using them incorrectly can lead to SQL injection or syntax errors.","severity":"gotcha","affected_versions":">=0.1.0"},{"fix":"Explicitly pass separator: sql.appendPairs('?? = ?', obj, ' AND ')","message":"The appendList and appendPairs methods are stable but the separator for appendPairs defaults to ', '; ensure you pass the correct separator when needed.","severity":"deprecated","affected_versions":">=0.2.0"}],"env_vars":null,"search_vec":"'2025':19 'abstract':41 'append':49 'appendlist':50 'appendpair':52 'builder':15,37 'cadenc':86 'compos':54 'connect':75 'databas':74 'definit':58 'depend':95 'driver':84 'escap':22 'export':69 'final':77 'fragment':46 'full':35 'generat':76 'identifi':23,31 'javascript':96 'last':17 'lightweight':93 'low':88 'minim':40 'mysql':61,70,97 'name':68 'orm':33 'packag':89 'pg':71,98 'placehold':27,99 'postgresql':62,100 'provid':39 'queri':36,55 'quot':65 'raw':44 'releas':85 'safe':21 'shakeabl':12 'ship':56 'sql':2,5,13,45,78,101 'sql-statement':1,4 'sqlite':64,72,102 'stabl':91 'statement':3,6,14 'string':79 'style':66 'support':60 'tini':9 'tree':11 'tree-shak':10 'typescript':57,103 'unlik':32 'updat':18 'use':26,48,81 'v1.1.0':16 'valu':25,29 'via':67 'write':43","created_at":"2026-06-05T17:02:15.232681+00:00","updated_at":"2026-06-05T17:02:15.232681+00:00","problems":[{"fix":"Change import to: import { mysql as SQL } from 'sql-statement'","cause":"Importing default export instead of named dialect export.","error":"TypeError: (intermediate value) is not a constructor"},{"fix":"Ensure the number of placeholders matches the number of arguments after the SQL string.","cause":"Mixing up placeholder order or passing extra arguments.","error":"Error: Unknown placeholder: \"?\""},{"fix":"Use placeholders instead: sql.append('SELECT * FROM users WHERE name = ?', name)","cause":"Manual string concatenation without escaping quotes.","error":"SyntaxError: Unterminated string constant"}],"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":"https://github.com/kawanet/sql-statement","github":"https://github.com/kawanet/sql-statement","docs":null,"changelog":null,"pypi":null,"npm":"sql-statement","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-05","next_check":"2026-09-03","install_tag":null}}