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

@ -2,8 +2,8 @@ const db = require('../../db')
function validateUser (username, password) {
return db.tx(t => {
const q1 = t.one('SELECT * FROM users WHERE username=$1 AND password=$2', [username, password])
const q2 = t.none('UPDATE users SET last_accessed = now() WHERE username=$1', [username])
const q1 = t.$one('SELECT * FROM users WHERE username=$1 AND password=$2', [username, password])
const q2 = t.$none('UPDATE users SET last_accessed = now() WHERE username=$1', [username])
return t.batch([q1, q2])
.then(([user]) => user)

View file

@ -25,7 +25,7 @@ function totem (name) {
const buf = Buffer.concat([caHash, token, Buffer.from(options.hostname)])
const sql = 'insert into pairing_tokens (token, name) values ($1, $3), ($2, $3)'
return db.none(sql, [hexToken, caHexToken, name])
return db.$none(sql, [hexToken, caHexToken, name])
.then(() => bsAlpha.encode(buf))
})
}

View file

@ -10,7 +10,7 @@ function getServerLogs (from = new Date(0).toISOString(), until = new Date().toI
limit $3
offset $4`
return db.any(sql, [ from, until, limit, offset ])
return db.$any(sql, [ from, until, limit, offset ])
.then(_.map(_.mapKeys(_.camelCase)))
}

View file

@ -93,8 +93,8 @@ function batch (
ORDER BY created DESC limit $4 offset $5`
return Promise.all([
db.any(cashInSql, [cashInTx.PENDING_INTERVAL, from, until, limit, offset, id, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status]),
db.any(cashOutSql, [REDEEMABLE_AGE, from, until, limit, offset, id, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status])
db.$any(cashInSql, [cashInTx.PENDING_INTERVAL, from, until, limit, offset, id, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status]),
db.$any(cashOutSql, [REDEEMABLE_AGE, from, until, limit, offset, id, txClass, machineName, customerName, fiatCode, cryptoCode, toAddress, status])
])
.then(packager)
}
@ -136,8 +136,8 @@ function getCustomerTransactionsBatch (ids) {
WHERE c.id IN ($1^)
ORDER BY created DESC limit $2`
return Promise.all([
db.any(cashInSql, [_.map(pgp.as.text, ids).join(','), cashInTx.PENDING_INTERVAL, NUM_RESULTS]),
db.any(cashOutSql, [_.map(pgp.as.text, ids).join(','), NUM_RESULTS, REDEEMABLE_AGE])
db.$any(cashInSql, [_.map(pgp.as.text, ids).join(','), cashInTx.PENDING_INTERVAL, NUM_RESULTS]),
db.$any(cashOutSql, [_.map(pgp.as.text, ids).join(','), NUM_RESULTS, REDEEMABLE_AGE])
])
.then(packager).then(transactions => {
const transactionMap = _.groupBy('customerId', transactions)
@ -180,8 +180,8 @@ function single (txId) {
WHERE id=$1`
return Promise.all([
db.oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]),
db.oneOrNone(cashOutSql, [txId, REDEEMABLE_AGE])
db.$oneOrNone(cashInSql, [cashInTx.PENDING_INTERVAL, txId]),
db.$oneOrNone(cashOutSql, [txId, REDEEMABLE_AGE])
])
.then(packager)
.then(_.head)