Skip to content

Instantly share code, notes, and snippets.

@tym-xqo
Created July 7, 2018 17:18
Show Gist options
  • Save tym-xqo/e36b369bd57387b29f53b3b960ca7ce4 to your computer and use it in GitHub Desktop.
Save tym-xqo/e36b369bd57387b29f53b3b960ca7ce4 to your computer and use it in GitHub Desktop.
Cannery static report prototype
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