Feat: AsyncLocalStorage for schema changing
This commit is contained in:
parent
e6059be8d2
commit
351d170c31
5 changed files with 55 additions and 27 deletions
12
lib/db.js
12
lib/db.js
|
|
@ -1,9 +1,11 @@
|
|||
const Pgp = require('pg-promise')
|
||||
const uuid = require('uuid')
|
||||
const _ = require('lodash/fp')
|
||||
|
||||
const psqlUrl = require('../lib/options').postgresql
|
||||
const logger = require('./logger')
|
||||
const eventBus = require('./event-bus')
|
||||
const { asyncLocalStorage, defaultStore } = require('./async-storage')
|
||||
|
||||
const stripDefaultDbFuncs = dbCtx => {
|
||||
return {
|
||||
|
|
@ -87,9 +89,13 @@ eventBus.subscribe('log', args => {
|
|||
|
||||
const sql = `insert into server_logs
|
||||
(id, device_id, message, log_level, meta) values ($1, $2, $3, $4, $5) returning *`
|
||||
|
||||
db.$one(sql, [uuid.v4(), '', msgToSave, level, meta])
|
||||
.then(_.mapKeys(_.camelCase))
|
||||
// need to set AsyncLocalStorage (ALS) for this function as well
|
||||
// because this module is imported before ALS is set up on app.js
|
||||
const store = defaultStore(true)
|
||||
asyncLocalStorage.run(store, () => {
|
||||
db.$one(sql, [uuid.v4(), '', msgToSave, level, meta])
|
||||
.then(_.mapKeys(_.camelCase))
|
||||
})
|
||||
})
|
||||
|
||||
module.exports = db
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue