Chore: refactor to use new schema changing queries

This commit is contained in:
csrapr 2021-03-01 15:55:29 +00:00 committed by Josh Harvey
parent 304f792484
commit e6059be8d2
44 changed files with 185 additions and 171 deletions

View file

@ -192,7 +192,7 @@ function plugins (settings, deviceId) {
order by id desc
limit 1`
return db.one(sql, ['config'])
return db.$one(sql, ['config'])
.then(row => row.id)
}
@ -281,9 +281,9 @@ function plugins (settings, deviceId) {
}
return Promise.all([
db.none(`insert into machine_pings(device_id, device_time) values($1, $2)
db.$none(`insert into machine_pings(device_id, device_time) values($1, $2)
ON CONFLICT (device_id) DO UPDATE SET device_time = $2, updated = now()`, [deviceId, deviceTime]),
db.none(pgp.helpers.update(devices, null, 'devices') + 'WHERE device_id = ${deviceId}', {
db.$none(pgp.helpers.update(devices, null, 'devices') + 'WHERE device_id = ${deviceId}', {
deviceId
})
])
@ -364,7 +364,7 @@ function plugins (settings, deviceId) {
const sql = 'update cash_out_txs set notified=$1 where id=$2'
const values = [true, tx.id]
return db.none(sql, values)
return db.$none(sql, values)
})
}
@ -379,7 +379,7 @@ function plugins (settings, deviceId) {
}
function pong () {
return db.none(`UPDATE server_events SET created=now() WHERE event_type=$1;
return db.$none(`UPDATE server_events SET created=now() WHERE event_type=$1;
INSERT INTO server_events (event_type) SELECT $1
WHERE NOT EXISTS (SELECT 1 FROM server_events WHERE event_type=$1);`, ['ping'])
.catch(logger.error)
@ -583,8 +583,8 @@ function plugins (settings, deviceId) {
)
const tradeEntry = massage(_tradeEntry, error)
const sql = pgp.helpers.insert(tradeEntry, null, 'trades') + 'RETURNING *'
db.tx(t => {
return t.oneOrNone(sql)
db.$tx(t => {
return t.$oneOrNone(sql)
.then(newTrade => recordTradeAndTx(newTrade.id, _tradeEntry, t))
})
}
@ -735,7 +735,7 @@ function plugins (settings, deviceId) {
const sql = `update cash_out_txs set swept='t'
where id=$1`
return db.none(sql, row.id)
return db.$none(sql, row.id)
}
})
.catch(err => logger.error('[%s] Sweep error: %s', cryptoCode, err.message))
@ -745,7 +745,7 @@ function plugins (settings, deviceId) {
const sql = `select id, crypto_code, hd_index from cash_out_txs
where hd_index is not null and not swept and status in ('confirmed', 'instant')`
return db.any(sql)
return db.$any(sql)
.then(rows => Promise.all(rows.map(sweepHdRow)))
.catch(err => logger.error(err))
}