From d3d4042d97d641aeaf801a42bccfb69c0a3f1730 Mon Sep 17 00:00:00 2001 From: siiky Date: Tue, 17 Sep 2024 16:48:27 +0100 Subject: [PATCH] refactor: inline query parameters --- lib/new-settings-loader.js | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/lib/new-settings-loader.js b/lib/new-settings-loader.js index 229ed2dd..70768037 100644 --- a/lib/new-settings-loader.js +++ b/lib/new-settings-loader.js @@ -62,11 +62,11 @@ const notifyReload = (dbOrTx, operatorId) => ['reload', JSON.stringify({ schema: asyncLocalStorage.getStore().get('schema'), operatorId })] ) -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) { + const accountsSql = `UPDATE user_config SET data = $1, valid = TRUE, schema_version = $2 WHERE type = 'accounts'; + INSERT INTO user_config (type, data, valid, schema_version) + SELECT 'accounts', $1, TRUE, $2 WHERE 'accounts' NOT IN (SELECT type FROM user_config)` + return Promise.all([loadAccounts(), getOperatorId('middleware')]) .then(([currentAccounts, operatorId]) => { const newAccounts = _.merge(currentAccounts, accounts) @@ -80,10 +80,10 @@ function saveAccounts (accounts) { newAccounts.elliptic.enabled = false } - return db.tx(t => { - return t.none(accountsSql, ['accounts', { accounts: newAccounts }, true, NEW_SETTINGS_LOADER_SCHEMA_VERSION]) + return db.tx(t => + t.none(accountsSql, [{ accounts: newAccounts }, NEW_SETTINGS_LOADER_SCHEMA_VERSION]) .then(() => notifyReload(t, operatorId)) - }).catch(console.error) + ).catch(console.error) }) }