Skip to content

Instantly share code, notes, and snippets.

@eoguvo
Created July 27, 2021 22:50
Show Gist options
  • Save eoguvo/17de5a9d8e69e2a955a26f799ab38ed4 to your computer and use it in GitHub Desktop.
Save eoguvo/17de5a9d8e69e2a955a26f799ab38ed4 to your computer and use it in GitHub Desktop.
An filter proxy to db
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