Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/littlstar/redshift-query
Simple function to query Redshift
https://github.com/littlstar/redshift-query
Last synced: about 1 month ago
JSON representation
Simple function to query Redshift
- Host: GitHub
- URL: https://github.com/littlstar/redshift-query
- Owner: littlstar
- License: mit
- Created: 2017-06-16T18:31:06.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2017-06-16T19:38:58.000Z (over 7 years ago)
- Last Synced: 2024-11-18T11:49:29.364Z (about 2 months ago)
- Language: JavaScript
- Size: 4.88 KB
- Stars: 1
- Watchers: 12
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
redshift-query
=============Library which allows you to query Redshift using parameterized SQL files and promises.
## Install
```bash
npm install redshift-query --save
```## Initialization:
`connection` is your Redshift connection info. `queryPath` is where your SQL files are located at.
```javascript
const RedshiftQuery = require('redshift-query')const redshift = new RedshiftQuery({
connection: {
user: 'super_cool_dev_person',
database: 'rad_database',
password: 'horse_battery_staple',
port: 5439,
host: 'rad_redshift'
},
queryPath: './sql'
})
```
## API### redshift#queryByFile(queryFile, parametersObj)
**Warning**: Do not use raw user input as parameter input, it opens you up to [SQL injection attacks](https://en.wikipedia.org/wiki/SQL_injection).
```javascript
redshift.queryByFile('count_unicorns.sql', { type: 'flying' })
.then((stable) => {
stable.rows.forEach((unicorn) => {
console.log('Name: ', unicorn.name)
})
})
```### redshift#queryByString(queryString)
**Warning**: Do not use raw user input as parameter input, it opens you up to [SQL injection attacks](https://en.wikipedia.org/wiki/SQL_injection).
```javascript
redshift.queryByString(`SELECT type, name FROM unicorns WHERE type='flying'`)
.then((stable) => {
stable.rows.forEach((unicorn) => {
console.log('Name: ', unicorn.name)
})
})
```## SQL file example:
```sql
SELECT type, name
FROM unicorns
WHERE type='${type}'
```Yep, nothing fancy. No need to make it a template string, just put a bunch of text in there (preferably Redshift-compliant SQL)