Registry / database / tsparser

tsparser

JSON →
library1.0.2jsnpmunverified

TSParser (v1.0.2) is a lightweight SQL parser that splits multi-statement SQL queries into individual statements. Supports MySQL, PostgreSQL, and Microsoft SQL Server. Handles stored procedures, functions, views, and custom delimiters (semicolon for MySQL/PG, GO for MSSQL). Ships TypeScript definitions. Maintained by TeamSQL. A viable alternative to sql-parser or node-sql-parser for multi-statement splitting without full AST support.

npm install tsparser
INSTALL
IMPORT
SIG · TSPARSER
T
tsparser
databasejavascriptv1.0.2
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

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

TSParser
✓ import { TSParser } from 'tsparser'
✗ import TSParser from 'tsparser'
TSParser is a named export, not default.
TSParser
✓ const { TSParser } = require('tsparser')
✗ const TSParser = require('tsparser')
CommonJS destructuring required; exports default is an object with TSParser property.
results
✓ const results: string[] = TSParser.parse(query, 'mysql', ';')
✗ const results = TSParser.parse(query, 'mysql', ';') // missing type
TypeScript users should annotate return type for better IDE support.

Parse a multi-statement MySQL query into an array of individual SQL statements.

import { TSParser } from 'tsparser'; const queries = 'SELECT * FROM users;SELECT * FROM orders;'; const statements = TSParser.parse(queries, 'mysql', ';'); statements.forEach((stmt, i) => { console.log(`Statement ${i+1}: ${stmt}`); });
Debug
Known issues
breakingThe 'dbType' parameter must be lower-case exactly 'mysql', 'pg', or 'mssql'. Using uppercase like 'MySQL' will throw an error.
fix
Ensure dbType is exactly 'mysql', 'pg', or 'mssql'.
affects: >=1.0
gotchaFor MSSQL, the delimiter is 'GO' (case-insensitive in practice, but should be uppercase). Using ';' will not split and may cause syntax error.
fix
Use 'GO' as delimiter for MSSQL.
affects: >=1.0
gotchaThe parser does not validate SQL syntax; it only splits based on delimiter and context-aware handling of procedures/functions. Invalid SQL will still be split.
fix
Validate SQL separately if needed.
affects: >=1.0
Errors
Common errors & fixes
TSParser.parse is not a function
Probably used default import instead of named import.
fix
Use import { TSParser } from 'tsparser'.
Cannot find module 'tsparser'
Package not installed or import path wrong.
fix
Run 'npm install tsparser' and ensure import path is 'tsparser' (case-sensitive).
Unsupported database type: MySQL
dbType must be lower-case; 'MySQL' is invalid.
fix
Use 'mysql' instead of 'MySQL'.
Upgrade
Version history
1.0.2latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
Amazon
1
OpenAI (training)
1
Resources
tsparser — npm install tsparser · libregistry