
Security News
rv Is a New Rust-Powered Ruby Version Manager Inspired by Python's uv
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
sql-query-identifier
Advanced tools
Identifies the types of each statement in a SQL query (also provide the start, end and the query text).
This uses AST and parser techniques to identify the SQL query type. Although it will not validate the whole query as a fully implemented AST+parser would do. Instead, it validates only the required tokens to identify the SQL query type. In summary it identifies the type by:
So the best approach using this module is only applying it after executing the query over the SQL client. This way you have sure is a valid query before trying to identify the types.
For the show statements, please refer to the MySQL Docs about SHOW Statements.
Execution types allow to know what is the query behavior
LISTING:
is when the query list the dataMODIFICATION:
is when the query modificate the database somehow (structure or data)INFORMATION:
is show some data information such as a profile dataANON_BLOCK:
is for an anonymous block query which may contain multiple statements of unknown type (BigQuery and Oracle dialects only)UNKNOWN
: (only available if strict mode is disabled)Install via npm:
$ npm install sql-query-identifier
import { identify } from 'sql-query-identifier';
const statements = identify(`
INSERT INTO Persons (PersonID, Name) VALUES (1, 'Jack');
SELECT * FROM Persons;
`);
console.log(statements);
[
{
start: 9,
end: 64,
text: 'INSERT INTO Persons (PersonID, Name) VALUES (1, \'Jack\');',
type: 'INSERT',
executionType: 'MODIFICATION',
parameters: []
},
{
start: 74,
end: 95,
text: 'SELECT * FROM Persons;',
type: 'SELECT',
executionType: 'LISTING',
parameters: []
}
]
identify
arguments:
input (string)
: the whole SQL script text to be processedoptions (object)
: allow to set different configurations
strict (bool)
: allow disable strict mode which will ignore unknown types (default=true)dialect (string)
: Specify your database dialect, values: generic
, mysql
, oracle
, psql
, sqlite
and mssql
. (default=generic)It is required to use editorconfig and please write and run specs before pushing any changes:
npm test
Copyright (c) 2016-2021 The SQLECTRON Team. This software is licensed under the MIT License.
FAQs
A SQL query identifier
The npm package sql-query-identifier receives a total of 1,972 weekly downloads. As such, sql-query-identifier popularity was classified as popular.
We found that sql-query-identifier demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 4 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Ruby maintainers from Bundler and rbenv teams are building rv to bring Python uv's speed and unified tooling approach to Ruby development.
Security News
Following last week’s supply chain attack, Nx published findings on the GitHub Actions exploit and moved npm publishing to Trusted Publishers.
Security News
AGENTS.md is a fast-growing open format giving AI coding agents a shared, predictable way to understand project setup, style, and workflows.