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

@ -29,7 +29,7 @@ function saveAccounts (accounts) {
})
}
function resetAccounts (schemaVersion) {
return db.none(
return db.$none(
accountsSql,
[
'accounts',
@ -49,7 +49,7 @@ function loadAccounts (schemaVersion) {
order by id desc
limit 1`
return db.oneOrNone(sql, ['accounts', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.$oneOrNone(sql, ['accounts', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(_.compose(_.defaultTo({}), _.get('data.accounts')))
}
@ -70,12 +70,12 @@ function saveConfig (config) {
return loadLatestConfigOrNone()
.then(currentConfig => {
const newConfig = _.assign(currentConfig, config)
return db.none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.$none(configSql, ['config', { config: newConfig }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION])
})
}
function resetConfig (schemaVersion) {
return db.none(
return db.$none(
configSql,
[
'config',
@ -103,7 +103,7 @@ function loadLatestConfig () {
order by id desc
limit 1`
return db.one(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.$one(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row ? row.data.config : {})
.catch(err => {
throw err
@ -118,7 +118,7 @@ function loadLatestConfigOrNone (schemaVersion) {
order by id desc
limit 1`
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.$oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row ? row.data.config : {})
}
@ -130,7 +130,7 @@ function loadConfig (versionId) {
and schema_version=$3
and valid`
return db.one(sql, [versionId, 'config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
return db.$one(sql, [versionId, 'config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
.then(row => row.data.config)
.catch(err => {
if (err.name === 'QueryResultError') {