loadsql
v0.1.3
Published
A minimalistic promise-based SQL loader for Node.js
Downloads
4
Maintainers
Readme
loadsql
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.