Registry / database / dbgate-query-splitter

dbgate-query-splitter

JSON →
library4.12.0jsnpmunverified

dbgate-query-splitter is a utility library designed to efficiently break down long SQL queries into individual statements. Currently at version 4.12.0, it is actively maintained with a focus on high performance and a zero-dependency footprint. The library supports a wide array of SQL dialects including MySQL, PostgreSQL, SQLite, Microsoft SQL Server, and Oracle, handling complex syntax elements like comments, dollar strings, GO separators, custom delimiters, and `SET SQLTERMINATOR`. A key differentiator is its robust streaming support for Node.js environments, allowing processing of large SQL files without loading them entirely into memory. It also provides an option to return rich metadata, including line and column numbers, for each split statement, which is useful for tooling and error reporting.

npm install dbgate-query-splitter
INSTALL
IMPORT
SIG · DBGATE-QUERY-SPLIT
D
dbgate-query-splitter
databasejavascriptv4.12.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

splitQuery
import { splitQuery } from 'dbgate-query-splitter';
const splitQuery = require('dbgate-query-splitter').splitQuery;
Primary function for splitting a complete string query. Use named import for ESM. CommonJS users often misuse object destructuring from a direct require.
mysqlSplitterOptions
import { mysqlSplitterOptions } from 'dbgate-query-splitter';
import mysqlSplitterOptions from 'dbgate-query-splitter/mysqlSplitterOptions';
Dialect-specific options are named exports from the main package. Do not try to import them from subpaths.
splitQueryStream
import { splitQueryStream } from 'dbgate-query-splitter/lib/splitQueryStream';
import { splitQueryStream } from 'dbgate-query-splitter';
The streaming functionality `splitQueryStream` is located in a specific subpath. Incorrectly importing from the main package path will result in undefined or module not found errors.

Demonstrates splitting a multi-statement SQL string using MSSQL dialect options and retrieving rich position information for each statement.

import { splitQuery, mssqlSplitterOptions } from 'dbgate-query-splitter'; const complexSqlQuery = ` -- This is a comment SELECT * FROM Users WHERE isActive = 1; GO -- Another statement block DECLARE @myVar INT = 10; SELECT @myVar AS Result; GO /* Multi-line comment followed by an empty statement */ SELECT COUNT(*) FROM Products; `; // Split the query, returning rich information including positions for MS SQL Server dialect const statements = splitQuery(complexSqlQuery, { ...mssqlSplitterOptions, returnRichInfo: true, }); statements.forEach(stmt => { console.log(`Statement:\n'${stmt.text}'\n Start: { line: ${stmt.start.line}, column: ${stmt.start.column} }\n End: { line: ${stmt.end.line}, column: ${stmt.end.column} }\n`); }); /* Expected output (simplified): Statement: 'SELECT * FROM Users WHERE isActive = 1;'... Statement: 'DECLARE @myVar INT = 10;\nSELECT @myVar AS Result;'... Statement: 'SELECT COUNT(*) FROM Products;'... */
Debug
Known issues
breakingThe API for `splitQueryStream` was simplified in version 4.9.0. Explicitly piping a `byline` stream is no longer required and should be removed from your code.
fix
Remove any manual `byline` piping when using `splitQueryStream`. The function now directly accepts a Node.js readable stream and returns an object stream.
affects: >=4.9.0
gotchaWhen using `splitQueryStream`, ensure you are importing it from `dbgate-query-splitter/lib/splitQueryStream` and not directly from the main package. This specific import path is necessary for the streaming functionality.
fix
Correct the import statement: `import { splitQueryStream } from 'dbgate-query-splitter/lib/splitQueryStream';` (ESM) or `const { splitQueryStream } = require('dbgate-query-splitter/lib/splitQueryStream');` (CJS).
affects: >=3.0.0
gotchaThe `splitQuery` function requires a second argument specifying the dialect options. Forgetting this argument or passing `null`/`undefined` will result in incorrect splitting or runtime errors.
fix
Always provide a valid splitter options object, e.g., `mysqlSplitterOptions`, `mssqlSplitterOptions`, or a custom configuration object, as the second argument to `splitQuery`.
affects: >=3.0.0
Errors
Common errors & fixes
TypeError: Cannot destructure property 'splitQueryStream' of 'dbgate-query-splitter__WEBPACK_IMPORTED_MODULE_0__' as it is undefined.
Attempting to import `splitQueryStream` directly from the main `dbgate-query-splitter` package using ESM syntax, but it's located in a subpath.
fix
Change your import statement to `import { splitQueryStream } from 'dbgate-query-splitter/lib/splitQueryStream';`
TypeError: splitQuery is not a function
Incorrect CommonJS `require` syntax when trying to access named exports, or attempting to use `require` on an ESM-only package (less likely for this package which supports both).
fix
For CommonJS, use `const { splitQuery } = require('dbgate-query-splitter');`. For ESM, ensure `import { splitQuery } from 'dbgate-query-splitter';` is used in an ESM context.
Upgrade
Version history
4.12.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
2
Resources
dbgate-query-splitter — npm install dbgate-query-splitter · libregistry