JSPM

node-sql-reader

0.1.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 1103
  • Score
    100M100P100Q111947F
  • License ISC

Library to parse pure sql file or sql string in to queries array

Package Exports

  • node-sql-reader

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-sql-reader) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

node-sql-reader

This library can parse pure sql file or sql string in to queries array.
The main use case that made me to create this library was inability of TypeOrm to run sql file. I needed to run sql file with test data each time when I restart a server to get same starting test data.

Install

npm install node-sql-reader

Usage

import { SqlReader } from 'node-sql-reader'
import * as path from 'path';

export class TestDataInitializer {
    initTestData() {
        let queries = SqlReader.readSqlFile(path.join(__dirname, "../database/test_data.sql"))
        for (let query of queries) {
            // replace it with your query runner
            SomeQuerryRunner.runQuerry(query)
        }
    }
}

API

  • parseSqlString(sqlString: string): string[]
    Parse all queries from sql string. Returns array of queries.
  • readSqlFile(filePath: string): string[]
    Reads all queries from file. Returns array of queries.
  • runSqlFile(filepath: string, runnerFn: (query: string) => void)
    Parse all queries from sql file and runs runnerFn for each of them. Has an async version.

Features requests / bugs

Feature requests and bugs on github