Last active
November 3, 2018 04:02
-
-
Save mhkeller/c11aa12ea344251d4dd2fadd18a9f7cd to your computer and use it in GitHub Desktop.
Basic node-pg connection setup
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
import { Pool } from 'pg'; | |
export default function db (connectionString) { | |
const pool = new Pool(connectionString); | |
pool.on('error', err => { | |
console.error(err); | |
}); | |
return pool; | |
}; |
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
{ "connectionString": "postgres://localhost:5432" } |
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
import db from './_db.js'; | |
import connectionString from './connection-string.json'; | |
const pool = db(connectionString); | |
(async function () { | |
const result = await pool.query(`SELECT * FROM my_table`); | |
console.log(result); | |
}).call(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment