Registry / database / node-sql-reader

node-sql-reader

JSON →
library0.1.3jsnpmunverified

v0.1.3 — A lightweight SQL file reader that parses SQL files or strings into an array of individual queries. Created to address TypeORM's lack of direct SQL file execution for seed/test data. Supports synchronous and asynchronous execution of queries via a runner function. Ships TypeScript types, no dependencies. Simple API, suitable for database seeding scripts and test initializers. Release cadence: infrequent, as it's a small utility.

npm install node-sql-reader
INSTALL
IMPORT
SIG · NODE-SQL-READER
N
node-sql-reader
databasejavascriptv0.1.3
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.

SqlReader
import { SqlReader } from 'node-sql-reader'
import SqlReader from 'node-sql-reader'
Named export, not default. TypeScript types included.
parseSqlString
import { parseSqlString } from 'node-sql-reader'
const { parseSqlString } = require('node-sql-reader')
Available as a standalone named import since v0.1.0. CommonJS require works but prefer ESM.
runSqlFile
import { runSqlFile } from 'node-sql-reader'
import { SqlReader } from 'node-sql-reader'; SqlReader.runSqlFile(...)
These are top-level named functions, not methods on SqlReader.
runSqlFileAsync
import { runSqlFileAsync } from 'node-sql-reader'
const { runSqlFileAsync } = require('node-sql-reader')
Async version of runSqlFile, returns Promise.

Reads a SQL file into an array and runs queries asynchronously using a custom runner function.

import { SqlReader, runSqlFileAsync } from 'node-sql-reader'; import * as path from 'path'; // Synchronous: parse SQL file to array const queries = SqlReader.readSqlFile(path.join(__dirname, 'seed.sql')); console.log(queries); // Asynchronous: run each query with a runner const runner = async (query: string) => { // Replace with your database query execution console.log(`Executing: ${query}`); }; runSqlFileAsync(path.join(__dirname, 'seed.sql'), runner) .then(() => console.log('All queries executed.')) .catch(err => console.error(err));
Debug
Known issues
gotchaThe parser splits on semicolons but does not handle semicolons inside string literals or comments perfectly.
fix
Ensure SQL statements do not contain semicolons within strings or use single statements per file if possible.
affects: <=0.1.3
gotchaNo support for SQL delimiters (e.g., stored procedures with custom delimiters).
fix
For multi-statement procedures, break them into separate files or use a more advanced parser.
affects: <=0.1.3
gotchaThe library does not validate SQL syntax; it merely splits on semicolons.
fix
Use with trusted SQL or validate separately before execution.
affects: <=0.1.3
gotchaFile reading is synchronous in readSqlFile and runSqlFile; avoid in event loops.
fix
Use runSqlFileAsync for non-blocking behavior.
affects: <=0.1.3
Errors
Common errors & fixes
TypeError: SqlReader.readSqlFile is not a function
Incorrect import: using default import instead of named import.
fix
Replace 'import SqlReader from ...' with 'import { SqlReader } from ...'
Error: Cannot find module 'node-sql-reader'
Package not installed or missing from node_modules.
fix
Run 'npm install node-sql-reader' in your project root.
SyntaxError: Unexpected token at ... (parsing SQL with semicolons in string)
Library incorrectly splits on semicolons inside string literals.
fix
Encode semicolons inside strings as literal characters or avoid them.
Upgrade
Version history
0.1.3latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
5 hits · last 30 days
node
4
Resources
node-sql-reader — npm install node-sql-reader · libregistry