loadsql
A minimalistic promise-based SQL loader for Node.js
Last updated 4 years ago by adriano.digiovanni .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install loadsql 
SYNC missed versions from official npm registry.

loadsql

NPM Version David David Build Status codecov Twitter Follow

Installation

npm install loadsql --save

Usage

Synchronous loading

import SQLLoader from 'loadsql'

const loader = new SQLLoader()

const data = loader.loadSync('query')

console.log(data) // SELECT ?? FROM ?? WHERE ?? = ?

Asynchronous loading using callbacks

import SQLLoader from 'loadsql'

const loader = new SQLLoader()

loader.load('query', (error, data) => {
  if (error) {
    throw error
  }
  console.log(data) // SELECT ?? FROM ?? WHERE ?? = ?
})

Asynchronous loading using promises

npm install bluebird --save
import Promise from 'bluebird'
import SQLLoader from 'loadsql'

SQLLoader.Promise = Promise

const loader = new SQLLoader()

loader.load('query')
  .then(data => {
    console.log(data) // SELECT ?? FROM ?? WHERE ?? = ?
  })

Custom base path and file extension

Examples above create instances of SQLLoader that

  • will use the default path.resolve() base path.
  • will use the default .sql file extension.

You can set your own base path and extension as follows:

import path from 'path'
import SQLLoader from 'loadsql'

const basePath = path.resolve(__dirname, './sql')
const ext = '.tpl'
const loader = new SQLLoader(basePath, ext)

License

The project is licensed under the MIT license.

Current Tags

  • 0.1.3                                ...           latest (4 years ago)

4 Versions

  • 0.1.3                                ...           4 years ago
  • 0.1.2                                ...           4 years ago
  • 0.1.1                                ...           4 years ago
  • 0.1.0                                ...           4 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 6
Dependencies (0)
None
Dev Dependencies (12)
Dependents (0)
None

Copyright 2014 - 2016 © taobao.org |