{"id":43468,"library":"node-sql-reader","title":"node-sql-reader","description":"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.","status":"active","version":"0.1.3","language":"javascript","source_language":"en","source_url":"https://github.com/Halynsky/node-sql-reader","tags":["javascript","sql","file","parser","reader","typescript"],"install":[{"cmd":"npm install node-sql-reader","lang":"bash","label":"npm"},{"cmd":"yarn add node-sql-reader","lang":"bash","label":"yarn"},{"cmd":"pnpm add node-sql-reader","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Named export, not default. TypeScript types included.","wrong":"import SqlReader from 'node-sql-reader'","symbol":"SqlReader","correct":"import { SqlReader } from 'node-sql-reader'"},{"note":"Available as a standalone named import since v0.1.0. CommonJS require works but prefer ESM.","wrong":"const { parseSqlString } = require('node-sql-reader')","symbol":"parseSqlString","correct":"import { parseSqlString } from 'node-sql-reader'"},{"note":"These are top-level named functions, not methods on SqlReader.","wrong":"import { SqlReader } from 'node-sql-reader'; SqlReader.runSqlFile(...)","symbol":"runSqlFile","correct":"import { runSqlFile } from 'node-sql-reader'"},{"note":"Async version of runSqlFile, returns Promise.","wrong":"const { runSqlFileAsync } = require('node-sql-reader')","symbol":"runSqlFileAsync","correct":"import { runSqlFileAsync } from 'node-sql-reader'"}],"quickstart":{"code":"import { SqlReader, runSqlFileAsync } from 'node-sql-reader';\nimport * as path from 'path';\n\n// Synchronous: parse SQL file to array\nconst queries = SqlReader.readSqlFile(path.join(__dirname, 'seed.sql'));\nconsole.log(queries);\n\n// Asynchronous: run each query with a runner\nconst runner = async (query: string) => {\n  // Replace with your database query execution\n  console.log(`Executing: ${query}`);\n};\n\nrunSqlFileAsync(path.join(__dirname, 'seed.sql'), runner)\n  .then(() => console.log('All queries executed.'))\n  .catch(err => console.error(err));","lang":"typescript","description":"Reads a SQL file into an array and runs queries asynchronously using a custom runner function."},"warnings":[{"fix":"Ensure SQL statements do not contain semicolons within strings or use single statements per file if possible.","message":"The parser splits on semicolons but does not handle semicolons inside string literals or comments perfectly.","severity":"gotcha","affected_versions":"<=0.1.3"},{"fix":"For multi-statement procedures, break them into separate files or use a more advanced parser.","message":"No support for SQL delimiters (e.g., stored procedures with custom delimiters).","severity":"gotcha","affected_versions":"<=0.1.3"},{"fix":"Use with trusted SQL or validate separately before execution.","message":"The library does not validate SQL syntax; it merely splits on semicolons.","severity":"gotcha","affected_versions":"<=0.1.3"},{"fix":"Use runSqlFileAsync for non-blocking behavior.","message":"File reading is synchronous in readSqlFile and runSqlFile; avoid in event loops.","severity":"gotcha","affected_versions":"<=0.1.3"}],"env_vars":null,"search_vec":"'address':25 'api':54 'array':19 'asynchron':40 'cadenc':64 'creat':23 'data':36 'databas':57 'depend':52 'direct':30 'execut':33,41 'file':9,14,32,74 'function':47 'individu':21 'infrequ':65 'initi':62 'javascript':72 'lack':28 'lightweight':7 'node':2 'node-sql-read':1 'pars':12 'parser':75 'queri':22,43 'reader':4,10,76 'releas':63 'runner':46 'script':59 'seed':58 'seed/test':35 'ship':48 'simpl':53 'small':70 'sql':3,8,13,31,73 'string':16 'suitabl':55 'support':37 'synchron':38 'test':61 'type':50 'typeorm':26 'typescript':49,77 'util':71 'v0.1.3':5 'via':44","created_at":"2026-06-05T16:59:57.033455+00:00","updated_at":"2026-06-05T16:59:57.033455+00:00","problems":[{"fix":"Replace 'import SqlReader from ...' with 'import { SqlReader } from ...'","cause":"Incorrect import: using default import instead of named import.","error":"TypeError: SqlReader.readSqlFile is not a function"},{"fix":"Run 'npm install node-sql-reader' in your project root.","cause":"Package not installed or missing from node_modules.","error":"Error: Cannot find module 'node-sql-reader'"},{"fix":"Encode semicolons inside strings as literal characters or avoid them.","cause":"Library incorrectly splits on semicolons inside string literals.","error":"SyntaxError: Unexpected token at ... (parsing SQL with semicolons in string)"}],"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/Halynsky/node-sql-reader#readme","github":"https://github.com/Halynsky/node-sql-reader","docs":null,"changelog":null,"pypi":null,"npm":"node-sql-reader","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}}