orderspec refactor for server and web

This commit is contained in:
Tim Olson
2023-12-07 18:37:11 -04:00
parent 597ab0b7b5
commit 6c8adab392
4 changed files with 37 additions and 14 deletions

17
db.js
View File

@@ -9,3 +9,20 @@ export const dbpool = new pg.Pool({
dbpool.on('connect', (client) => {
client.query("SET TIME ZONE 'UTC'")
})
export async function withDb(cb) {
const db = await dbpool.connect()
try {
return await cb(db)
}
finally {
db.release()
}
}
export async function sql(query) {
return await withDb(async (db)=>await db.query(query) )
}