Created
July 7, 2018 17:18
-
-
Save tym-xqo/e36b369bd57387b29f53b3b960ca7ce4 to your computer and use it in GitHub Desktop.
Cannery static report prototype
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require('dotenv').config() | |
const fs = require('fs') | |
const { | |
Client | |
} = require('pg') | |
const dbUri = process.env.DATABASE_URL | |
const queryName = process.env.QUERY_NAME | |
const db = new Client({ | |
connectionString: dbUri | |
}) | |
db.connect() | |
fs.readFile('./query_files/' + queryName + '.sql', 'utf8', function (err, data) { | |
if (err) throw err | |
db.query(data) | |
.then(res => { | |
fs.writeFile('./public/' + queryName + '.json', JSON.stringify(res.rows), () => { | |
console.log('done!') | |
}) | |
db.end() | |
}) | |
.catch(e => console.error(e.stack)) | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment