refactor(postgresql): use bindings to set run-time params

This commit is contained in:
Ali BARIN
2023-05-09 20:25:01 +00:00
parent f29ccace2a
commit 89752138be
5 changed files with 42 additions and 48 deletions

View File

@@ -1,6 +1,6 @@
import { IJSONObject } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import setConfig from '../../common/postgres-client';
import getClient from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
export default defineAction({
@@ -22,11 +22,11 @@ export default defineAction({
key: 'params',
type: 'dynamic' as const,
required: false,
description: 'Change a run-time configuration parameter with command SET',
description: 'Change run-time configuration parameters with SET command',
fields: [
{
label: 'Parameter ',
key: 'configParam',
label: 'Parameter name',
key: 'parameter',
type: 'string' as const,
required: true,
variables: false,
@@ -43,18 +43,17 @@ export default defineAction({
],
async run($) {
const pgClient = await setConfig($)
const params: any = $.step.parameters.params
if (params[0].configParam != '')
await setParams($, pgClient)
const pgClient = getClient($)
await setParams(pgClient, $.step.parameters.params)
const queryStatemnt = $.step.parameters.queryStatement
const response = await pgClient.raw(queryStatemnt);
const { rows } = await pgClient.raw(queryStatemnt);
const res = { msg: `SQL query: " ${$.step.parameters.queryStatement} " has been executed successfully` }
$.setActionItem({ raw: res as IJSONObject });
$.setActionItem({
raw: {
rows
}
});
},
});