chore: SQL formatting
This commit is contained in:
parent
083a7764d2
commit
446ac9f8db
1 changed files with 37 additions and 36 deletions
|
|
@ -56,9 +56,10 @@ const addTermsHash = configs => {
|
|||
)(terms)
|
||||
}
|
||||
|
||||
const accountsSql = `update user_config set data = $2, valid = $3, schema_version = $4 where type = $1;
|
||||
insert into user_config (type, data, valid, schema_version)
|
||||
select $1, $2, $3, $4 where $1 not in (select type from user_config)`
|
||||
const accountsSql = `UPDATE user_config SET data = $2, valid = $3, schema_version = $4 WHERE type = $1;
|
||||
INSERT INTO user_config (type, data, valid, schema_version)
|
||||
SELECT $1, $2, $3, $4 WHERE $1 NOT IN (SELECT type FROM user_config)`
|
||||
|
||||
function saveAccounts (accounts) {
|
||||
return Promise.all([loadAccounts(), getOperatorId('middleware')])
|
||||
.then(([currentAccounts, operatorId]) => {
|
||||
|
|
@ -92,13 +93,13 @@ function resetAccounts (schemaVersion) {
|
|||
}
|
||||
|
||||
function loadAccounts (schemaVersion) {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
and valid
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE type = $1
|
||||
AND schema_version = $2
|
||||
AND valid
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.oneOrNone(sql, ['accounts', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(_.compose(_.defaultTo({}), _.get('data.accounts')))
|
||||
|
|
@ -116,7 +117,7 @@ function showAccounts (schemaVersion) {
|
|||
})
|
||||
}
|
||||
|
||||
const configSql = 'insert into user_config (type, data, valid, schema_version) values ($1, $2, $3, $4)'
|
||||
const configSql = 'INSERT INTO user_config (type, data, valid, schema_version) VALUES ($1, $2, $3, $4)'
|
||||
function saveConfig (config) {
|
||||
return Promise.all([loadLatestConfigOrNone(), getOperatorId('middleware')])
|
||||
.then(([currentConfig, operatorId]) => {
|
||||
|
|
@ -170,13 +171,13 @@ function loadLatest (schemaVersion) {
|
|||
}
|
||||
|
||||
function loadLatestConfig () {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
and valid
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE type = $1
|
||||
AND schema_version = $2
|
||||
AND valid
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.one(sql, ['config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row ? row.data.config : {})
|
||||
|
|
@ -186,36 +187,36 @@ function loadLatestConfig () {
|
|||
}
|
||||
|
||||
function loadLatestConfigOrNoneReturningVersion (schemaVersion) {
|
||||
const sql = `select data, id
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data, id
|
||||
FROM user_config
|
||||
WHERE type = $1
|
||||
AND schema_version = $2
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row ? { config: row.data.config, version: row.id } : {})
|
||||
}
|
||||
|
||||
function loadLatestConfigOrNone (schemaVersion) {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where type=$1
|
||||
and schema_version=$2
|
||||
order by id desc
|
||||
limit 1`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE type = $1
|
||||
AND schema_version = $2
|
||||
ORDER BY id DESC
|
||||
LIMIT 1`
|
||||
|
||||
return db.oneOrNone(sql, ['config', schemaVersion || NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row ? row.data.config : {})
|
||||
}
|
||||
|
||||
function loadConfig (versionId) {
|
||||
const sql = `select data
|
||||
from user_config
|
||||
where id=$1
|
||||
and type=$2
|
||||
and schema_version=$3
|
||||
and valid`
|
||||
const sql = `SELECT data
|
||||
FROM user_config
|
||||
WHERE id = $1
|
||||
AND type = $2
|
||||
AND schema_version = $3
|
||||
AND valid`
|
||||
|
||||
return db.one(sql, [versionId, 'config', NEW_SETTINGS_LOADER_SCHEMA_VERSION])
|
||||
.then(row => row.data.config)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue