Created
July 27, 2021 22:50
-
-
Save eoguvo/17de5a9d8e69e2a955a26f799ab38ed4 to your computer and use it in GitHub Desktop.
An filter proxy to db
This file contains 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"; | |
import 'dotenv/config' | |
const db = new Pool({ | |
connectionString: process.env.DATABASE_URL, | |
ssl: process.env.NODE_ENV === "development" ? false : { | |
rejectUnauthorized: false | |
} | |
}); | |
function async query(text, returning = '*') { | |
const sanitizeText = text.endsWith(';') | |
? text.slice(0, -1) | |
: text; | |
return await db.query(`${text} RETURNING ${returning}`); | |
} | |
export default { query }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment