pg-require-sql
Version:
Requires sql files and export functions for querying via pg
40 lines (32 loc) • 1.15 kB
Markdown
pg-require-sql
==============
[](https://github.com/feross/standard)
[](https://circleci.com/gh/lanetix/node-pg-require-sql)
[](https://david-dm.org/lanetix/node-pg-require-sql)
'Require' sql files for use with [pg-connect](https://www.npmjs.com/package/pg-connect).
Installation
------------
[](https://npmjs.org/package/pg-require-sql)
Usage
-----
Given a project like
```
|- index.js
|- sql-directory
|- get-record.sql
```
the following will query
```javascript
var Promise = require('bluebird')
var path = require('path')
var getConnection = require('pg-connect')(connectionString)
var requireSql = require('pg-require-sql')
var sql = requireSql(path.join(__dirname, 'sql-directory'))
Promise.using(
getConnection(),
sql.getRecord(['foo'])
).
then(function (results) {
// ... use the results
})
```