{"id":42500,"library":"check-sql-query","title":"check-sql-query","description":"Utility library (v1.0.0) for detecting SQL operation types (SELECT, INSERT, UPDATE, DELETE, etc.), determining read-only status, and validating parameter binding. Supports positional ($1, ?) and named (@, :, $) parameter styles for PostgreSQL, MySQL, SQLite. Isomorphic (works in Node.js and browsers), with TypeScript support and 0 dependencies. Lightweight alternative to SQL parsers like sql-parser or node-sql-parser for simple query classification.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/beenotung/check-sql-query","tags":["javascript","sql","query","validator","readonly","parameter","binding","postgresql","mysql","typescript"],"install":[{"cmd":"npm install check-sql-query","lang":"bash","label":"npm"},{"cmd":"yarn add check-sql-query","lang":"bash","label":"yarn"},{"cmd":"pnpm add check-sql-query","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export. This is default-like but actually named. Mixed CJS/ESM via package.json exports.","wrong":"const checkSqlQuery = require('check-sql-query')","symbol":"checkSqlQuery","correct":"import { checkSqlQuery } from 'check-sql-query'"},{"note":"TypeScript type only. Do not import at runtime.","wrong":"import { SqlType } from 'check-sql-query'","symbol":"SqlType","correct":"import type { SqlType } from 'check-sql-query'"},{"note":"TypeScript type for the function's return value. Not exported as value.","wrong":"import { CheckSqlQueryResult } from 'check-sql-query'","symbol":"CheckSqlQueryResult","correct":"import type { CheckSqlQueryResult } from 'check-sql-query'"}],"quickstart":{"code":"import { checkSqlQuery } from 'check-sql-query';\n\n// Read-only SELECT with positional param\nconst result1 = checkSqlQuery('SELECT * FROM users WHERE id = $1', [1]);\nconsole.log(result1);\n// { readonly: true, types: ['select'] }\n\n// INSERT with named param\nconst result2 = checkSqlQuery('INSERT INTO users (name) VALUES (@name)', { name: 'Alice' });\nconsole.log(result2);\n// { readonly: false, types: ['insert'] }\n\n// Parameter count mismatch\nconst result3 = checkSqlQuery('SELECT * FROM users WHERE id = $1', [1, 2, 3]);\nconsole.log(result3);\n// { readonly: true, types: ['select'], error: 'too many parameter in array, expected 1, got 3' }","lang":"typescript","description":"Detects read-only SQL queries and validates parameter binding with positional and named placeholders."},"warnings":[{"fix":"Use only one style: either all $1 (PostgreSQL) or all ? (MySQL/SQLite)","message":"Mixed parameter styles ($1 and ?) in same query cause error","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"For accurate operation detection on CTEs or subqueries, consider using a full SQL parser.","message":"The function does not parse SQL syntax, only classifies by first keyword. Complex queries like 'WITH ... SELECT' may be misclassified.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Pin to ^1.0.0 during initial adoption.","message":"No breaking changes known as of v1.0.0 — minor version bumps may introduce new features.","severity":"breaking","affected_versions":">=1.0.0 <2.0.0"},{"fix":"N/A","message":"No deprecated APIs reported yet.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"When using named params, ensure all placeholders are covered; unmatched keys are silently ignored.","message":"Parameter validation only checks count for positional arrays; for objects, excess keys are ignored.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need to detect any SELECT-like operation, check 'types' array directly.","message":"The 'readonly' flag is true only if ALL operations are SELECT. Mixing SELECT with INSERT makes it false.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"search_vec":"'0':48 '1':29 'altern':51 'bind':26,74 'browser':43 'check':2 'check-sql-queri':1 'classif':67 'delet':16 'depend':49 'detect':9 'determin':18 'etc':17 'insert':14 'isomorph':38 'javascript':68 'librari':6 'lightweight':50 'like':55 'mysql':36,76 'name':31 'node':61 'node-sql-pars':60 'node.js':41 'oper':11 'paramet':25,32,73 'parser':54,58,63 'posit':28 'postgresql':35,75 'queri':4,66,70 'read':20 'read-on':19 'readon':72 'select':13 'simpl':65 'sql':3,10,53,57,62,69 'sql-parser':56 'sqlite':37 'status':22 'style':33 'support':27,46 'type':12 'typescript':45,77 'updat':15 'util':5 'v1.0.0':7 'valid':24,71 'work':39","created_at":"2026-06-05T16:55:16.921181+00:00","updated_at":"2026-06-05T16:55:16.921181+00:00","problems":[{"fix":"Choose one style: e.g., 'SELECT * FROM users WHERE id = ? AND name = ?' or 'SELECT * FROM users WHERE id = $1 AND name = $2'.","cause":"Using both $1 and ? placeholders in the same SQL query.","error":"Error: mixed \"$1\" and \"?\" style parameters"},{"fix":"Ensure the array length equals the placeholder count. For named parameters, use an object instead of an array.","cause":"Number of positional parameters in array does not match number of placeholders.","error":"Error: too many parameter in array, expected N, got M"},{"fix":"Include all named parameters in the object, e.g., { id: 1 }.","cause":"Missing value for a named placeholder (e.g., @id not provided in object).","error":"Error: expected parameter M but got undefined"},{"fix":"Use import { checkSqlQuery } from 'check-sql-query'.","cause":"Incorrect import: using default import instead of named import.","error":"TypeError: checkSqlQuery is not a function"}],"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/beenotung/check-sql-query#readme","github":"https://github.com/beenotung/check-sql-query","docs":null,"changelog":null,"pypi":null,"npm":"check-sql-query","openapi_spec":null,"status_page":null,"smithery":null,"categories":["database","security"],"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}}