{"id":43937,"library":"sql-query-identifier","title":"sql-query-identifier","description":"A SQL query identifier that parses SQL statements to determine their type (e.g., SELECT, INSERT, CREATE_TABLE) by scanning and parsing tokens. Version 3.1.0 supports a wide range of SQL dialects including MySQL, PostgreSQL, BigQuery, and Oracle, with over 50 recognized statement types. Unlike full SQL parsers, it focuses on fast identification by checking only the initial keywords and structure, making it suitable for applications that need quick classification without full validation. It is actively maintained with regular releases and includes TypeScript type definitions. The package works in both Node.js and browser environments.","status":"active","version":"3.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/coresql/sql-query-identifier","tags":["javascript","typescript"],"install":[{"cmd":"npm install sql-query-identifier","lang":"bash","label":"npm"},{"cmd":"yarn add sql-query-identifier","lang":"bash","label":"yarn"},{"cmd":"pnpm add sql-query-identifier","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The function is a named export, not a default export.","wrong":"import identify from 'sql-query-identifier'","symbol":"identify","correct":"import { identify } from 'sql-query-identifier'"},{"note":"CommonJS require returns an object with the named export.","wrong":"const identify = require('sql-query-identifier')","symbol":"identify (CommonJS)","correct":"const { identify } = require('sql-query-identifier')"},{"note":"Use import type for type-only imports to avoid runtime overhead.","wrong":"import { IdentifiedQuery } from 'sql-query-identifier'","symbol":"TypeScript types","correct":"import type { IdentifiedQuery } from 'sql-query-identifier'"}],"quickstart":{"code":"import { identify } from 'sql-query-identifier';\n\nconst queries = [\n  'SELECT * FROM users',\n  'INSERT INTO logs (id, message) VALUES (1, \\'test\\')',\n  'CREATE TABLE items (id INT PRIMARY KEY)',\n  'DROP VIEW active_users',\n];\n\nfor (const query of queries) {\n  const results = identify(query);\n  console.log(results);\n  // Example output: [{ type: 'SELECT', start: 0, end: 20, text: 'SELECT * FROM users', executionType: 'LISTING' }]\n}\n\n// With options for MySQL dialect\nconst mysqlQuery = 'SHOW TABLES';\nconst results = identify(mysqlQuery, { strict: false, dialect: 'mysql' });\nconsole.log(results);\n// Output: [{ type: 'SHOW_TABLES', start: 0, end: 10, text: 'SHOW TABLES', executionType: 'LISTING' }]","lang":"typescript","description":"Demonstrates basic usage of identify() to classify SQL statements, including handling multiple queries and dialect-specific options."},"warnings":[{"fix":"Always execute the query against a database server before relying on the identifier for classification, especially for complex or dialect-specific statements.","message":"The identifier does not validate SQL syntax; it only scans initial tokens. Invalid SQL may produce incorrect classification.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set the dialect option to 'mysql' when working with MySQL SHOW statements, or use 'generic' for basic support.","message":"SHOW statements are only recognized for MySQL and generic dialects by default. Using other dialects will return UNKNOWN for SHOW queries.","severity":"gotcha","affected_versions":">=3.0.0"},{"fix":"Update calls from identify(query, strictMode) to identify(query, { strict: strictMode }).","message":"In v3.0.0, the function signature changed: the second parameter is now an options object instead of a boolean for strict mode.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Access queryResult.type directly instead of queryResult.type.type.","message":"The old 'type' property on results is deprecated in favor of the 'type' string directly.","severity":"deprecated","affected_versions":">=3.0.0"}],"env_vars":null,"search_vec":"'3.1.0':28 '50':44 'activ':79 'applic':69 'bigqueri':39 'browser':96 'check':58 'classif':73 'creat':20 'definit':88 'determin':14 'dialect':35 'e.g':17 'environ':97 'fast':55 'focus':53 'full':49,75 'identif':56 'identifi':4,8 'includ':36,85 'initi':61 'insert':19 'javascript':98 'keyword':62 'maintain':80 'make':65 'mysql':37 'need':71 'node.js':94 'oracl':41 'packag':90 'pars':10,25 'parser':51 'postgresql':38 'queri':3,7 'quick':72 'rang':32 'recogn':45 'regular':82 'releas':83 'scan':23 'select':18 'sql':2,6,11,34,50 'sql-query-identifi':1 'statement':12,46 'structur':64 'suitabl':67 'support':29 'tabl':21 'token':26 'type':16,47,87 'typescript':86,99 'unlik':48 'valid':76 'version':27 'wide':31 'without':74 'work':91","created_at":"2026-06-05T17:02:12.093704+00:00","updated_at":"2026-06-05T17:02:12.093704+00:00","problems":[{"fix":"Ensure the query string is non-empty before calling identify() or wrap in a try-catch.","cause":"Passing an empty string or null query to identify()","error":"TypeError: Cannot destructure property 'type' of 'undefined' or 'null'"},{"fix":"Use one of the supported dialects: 'mysql', 'postgresql', 'bigquery', 'oracle', or 'generic'.","cause":"Using a dialect string not in the supported list (mysql, postgresql, bigquery, oracle, generic)","error":"Error: Unsupported SQL dialect: 'mssql'"},{"fix":"Change from identify(query, true) to identify(query, { strict: true })","cause":"Passing strict mode as a second boolean argument instead of an options object in v3","error":"TS2345: Argument of type 'string' is not assignable to parameter of type 'Options'"}],"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/coresql/sql-query-identifier#readme","github":"https://github.com/coresql/sql-query-identifier","docs":null,"changelog":null,"pypi":null,"npm":"sql-query-identifier","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}}