orderspec refactor for server and web
This commit is contained in:
17
db.js
17
db.js
@@ -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) )
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user