chore(postgresql): rename app folder and add icon
This commit is contained in:
85
packages/backend/src/apps/postgresql/actions/delete/index.ts
Normal file
85
packages/backend/src/apps/postgresql/actions/delete/index.ts
Normal file
@@ -0,0 +1,85 @@
|
||||
import { IJSONObject, IJSONArray } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import setConfig from '../../common/postgres-client';
|
||||
import setParams from '../../common/set-run-time-parameters';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Delete',
|
||||
key: 'delete',
|
||||
description: 'Cteate new item in a table in specific schema in postgreSQL.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Schema name',
|
||||
key: 'schema',
|
||||
type: 'string' as const,
|
||||
value: 'public',
|
||||
required: true,
|
||||
description: 'The name of the schema.',
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Table name',
|
||||
key: 'table',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'The name of the table.',
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Where statement',
|
||||
key: 'whereStatement',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'The condition column and relational operator and condition value - For example: id,=,1',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Run-time parameters',
|
||||
key: 'params',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
description: 'Change a run-time configuration parameter with command SET',
|
||||
fields: [
|
||||
{
|
||||
label: 'Parameter ',
|
||||
key: 'configParam',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const pgClient = await setConfig($)
|
||||
|
||||
const params: any = $.step.parameters.params
|
||||
if (params[0].configParam != '')
|
||||
await setParams($, pgClient)
|
||||
|
||||
const whereStatemennt = $.step.parameters.whereStatement as string
|
||||
const whereParts = whereStatemennt.split(",")
|
||||
|
||||
const conditionColumn = whereParts[0]
|
||||
const RelationalOperator = whereParts[1]
|
||||
const conditionValue = whereParts[2]
|
||||
|
||||
const response = await pgClient(`${$.step.parameters.schema}.${$.step.parameters.table}`)
|
||||
.returning('*')
|
||||
.where(conditionColumn, RelationalOperator, conditionValue)
|
||||
.del() as IJSONArray
|
||||
|
||||
let deletedData: IJSONObject = {}
|
||||
response.forEach((ele: IJSONObject, i: number) => { deletedData[`record${i}`] = ele })
|
||||
|
||||
$.setActionItem({ raw: deletedData as IJSONObject });
|
||||
},
|
||||
});
|
6
packages/backend/src/apps/postgresql/actions/index.ts
Normal file
6
packages/backend/src/apps/postgresql/actions/index.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import insertAction from './insert';
|
||||
import updateAction from './update';
|
||||
import deleteAction from './delete';
|
||||
import SQLQuery from './sql-query'
|
||||
|
||||
export default [insertAction, updateAction, deleteAction, SQLQuery];
|
93
packages/backend/src/apps/postgresql/actions/insert/index.ts
Normal file
93
packages/backend/src/apps/postgresql/actions/insert/index.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import setConfig from '../../common/postgres-client';
|
||||
import setParams from '../../common/set-run-time-parameters';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Insert',
|
||||
key: 'insert',
|
||||
description: 'Cteate new item in a table in specific schema in postgreSQL.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Schema name',
|
||||
key: 'schema',
|
||||
type: 'string' as const,
|
||||
value: 'public',
|
||||
required: true,
|
||||
description: 'The name of the schema.',
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Table name',
|
||||
key: 'table',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'The name of the table.',
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Fields',
|
||||
key: 'fields',
|
||||
type: 'dynamic' as const,
|
||||
required: true,
|
||||
description: 'Table columns with values',
|
||||
fields: [
|
||||
{
|
||||
label: 'Column name',
|
||||
key: 'columnName',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Run-time parameters',
|
||||
key: 'params',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
description: 'Change a run-time configuration parameter with command SET',
|
||||
fields: [
|
||||
{
|
||||
label: 'Parameter ',
|
||||
key: 'configParam',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const pgClient = await setConfig($)
|
||||
|
||||
const params: any = $.step.parameters.params
|
||||
if (params[0].configParam != '')
|
||||
await setParams($, pgClient)
|
||||
|
||||
const fields: any = $.step.parameters.fields
|
||||
let data: IJSONObject = {}
|
||||
fields.forEach((ele: any) => { data[ele.columnName] = ele.value })
|
||||
|
||||
const response = await pgClient(`${$.step.parameters.schema}.${$.step.parameters.table}`)
|
||||
.returning('*')
|
||||
.insert(data) as IJSONObject
|
||||
|
||||
$.setActionItem({ raw: response[0] as IJSONObject });
|
||||
},
|
||||
});
|
@@ -0,0 +1,60 @@
|
||||
import { IJSONObject } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import setConfig from '../../common/postgres-client';
|
||||
import setParams from '../../common/set-run-time-parameters';
|
||||
|
||||
export default defineAction({
|
||||
name: 'SQL query',
|
||||
key: 'SQLQuery',
|
||||
description: 'Cteate new item in a table in specific schema in postgreSQL.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'SQL statement',
|
||||
key: 'queryStatement',
|
||||
type: 'string' as const,
|
||||
value: 'public',
|
||||
required: true,
|
||||
description: 'Execute SQL query sttement directly.',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Run-time parameters',
|
||||
key: 'params',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
description: 'Change a run-time configuration parameter with command SET',
|
||||
fields: [
|
||||
{
|
||||
label: 'Parameter ',
|
||||
key: 'configParam',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const pgClient = await setConfig($)
|
||||
|
||||
const params: any = $.step.parameters.params
|
||||
if (params[0].configParam != '')
|
||||
await setParams($, pgClient)
|
||||
|
||||
|
||||
const queryStatemnt = $.step.parameters.queryStatement
|
||||
const response = await pgClient.raw(queryStatemnt);
|
||||
|
||||
const res = { msg: `SQL query: " ${$.step.parameters.queryStatement} " has been executed successfully` }
|
||||
|
||||
$.setActionItem({ raw: res as IJSONObject });
|
||||
},
|
||||
});
|
112
packages/backend/src/apps/postgresql/actions/update/index.ts
Normal file
112
packages/backend/src/apps/postgresql/actions/update/index.ts
Normal file
@@ -0,0 +1,112 @@
|
||||
import { IJSONObject, IJSONArray } from '@automatisch/types';
|
||||
import defineAction from '../../../../helpers/define-action';
|
||||
import setConfig from '../../common/postgres-client';
|
||||
import setParams from '../../common/set-run-time-parameters';
|
||||
|
||||
export default defineAction({
|
||||
name: 'Update',
|
||||
key: 'update',
|
||||
description: 'Cteate new item in a table in specific schema in postgreSQL.',
|
||||
arguments: [
|
||||
{
|
||||
label: 'Schema name',
|
||||
key: 'schema',
|
||||
type: 'string' as const,
|
||||
value: 'public',
|
||||
required: true,
|
||||
description: 'The name of the schema.',
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Table name',
|
||||
key: 'table',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'The name of the table.',
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Where statement',
|
||||
key: 'whereStatement',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
description: 'The condition column and relational operator and condition value - For example: id,=,1',
|
||||
variables: true,
|
||||
},
|
||||
{
|
||||
label: 'Fields',
|
||||
key: 'fields',
|
||||
type: 'dynamic' as const,
|
||||
required: true,
|
||||
description: 'Table columns with values',
|
||||
fields: [
|
||||
{
|
||||
label: 'Column name',
|
||||
key: 'columnName',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
},
|
||||
{
|
||||
label: 'Run-time parameters',
|
||||
key: 'params',
|
||||
type: 'dynamic' as const,
|
||||
required: false,
|
||||
description: 'Change a run-time configuration parameter with command SET',
|
||||
fields: [
|
||||
{
|
||||
label: 'Parameter ',
|
||||
key: 'configParam',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: false,
|
||||
},
|
||||
{
|
||||
label: 'Value',
|
||||
key: 'value',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
variables: true,
|
||||
}
|
||||
],
|
||||
}
|
||||
],
|
||||
|
||||
async run($) {
|
||||
const pgClient = await setConfig($)
|
||||
|
||||
const params: any = $.step.parameters.params
|
||||
if (params[0].configParam != '')
|
||||
await setParams($, pgClient)
|
||||
|
||||
const whereStatemennt = $.step.parameters.whereStatement as string
|
||||
const whereParts = whereStatemennt.split(",")
|
||||
|
||||
const conditionColumn = whereParts[0]
|
||||
const RelationalOperator = whereParts[1]
|
||||
const conditionValue = whereParts[2]
|
||||
|
||||
const fields: any = $.step.parameters.fields
|
||||
let data: IJSONObject = {}
|
||||
fields.forEach((ele: any) => { data[ele.columnName] = ele.value })
|
||||
|
||||
const response = await pgClient(`${$.step.parameters.schema}.${$.step.parameters.table}`)
|
||||
.returning('*')
|
||||
.where(conditionColumn, RelationalOperator, conditionValue)
|
||||
.update(data) as IJSONArray
|
||||
|
||||
let updatedData: IJSONObject = {}
|
||||
response.forEach((ele: IJSONObject, i: number) => { updatedData[`record${i}`] = ele })
|
||||
|
||||
$.setActionItem({ raw: updatedData as IJSONObject });
|
||||
},
|
||||
});
|
10
packages/backend/src/apps/postgresql/assets/favicon.svg
Normal file
10
packages/backend/src/apps/postgresql/assets/favicon.svg
Normal file
File diff suppressed because one or more lines are too long
After Width: | Height: | Size: 13 KiB |
75
packages/backend/src/apps/postgresql/auth/index.ts
Normal file
75
packages/backend/src/apps/postgresql/auth/index.ts
Normal file
@@ -0,0 +1,75 @@
|
||||
import verifyCredentials from './verify-credentials';
|
||||
import isStillVerified from './is-still-verified';
|
||||
|
||||
export default {
|
||||
fields: [
|
||||
{
|
||||
key: 'version',
|
||||
label: 'PostgreSQL version',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description:
|
||||
'The version of PostgreSQL database that user want to connect with.',
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'host',
|
||||
label: 'Host',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: '127.0.0.1',
|
||||
placeholder: null,
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'port',
|
||||
label: 'Port',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: '5432',
|
||||
placeholder: null,
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'database',
|
||||
label: 'Database Name',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'user',
|
||||
label: 'Database username',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
description:
|
||||
'The user who has access on postgres database.',
|
||||
clickToCopy: false,
|
||||
},
|
||||
{
|
||||
key: 'password',
|
||||
label: 'Password',
|
||||
type: 'string' as const,
|
||||
required: true,
|
||||
readOnly: false,
|
||||
value: null,
|
||||
placeholder: null,
|
||||
clickToCopy: false,
|
||||
},
|
||||
|
||||
],
|
||||
|
||||
verifyCredentials,
|
||||
isStillVerified
|
||||
};
|
@@ -0,0 +1,10 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import verifyCredentials from './verify-credentials';
|
||||
|
||||
const isStillVerified = async ($: IGlobalVariable) => {
|
||||
await verifyCredentials($);
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
export default isStillVerified;
|
@@ -0,0 +1,23 @@
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
import logger from '../../../helpers/logger';
|
||||
import getClient from '../common/postgres-client';
|
||||
|
||||
const verifyCredentials = async ($: IGlobalVariable) => {
|
||||
const pgClient = getClient($);
|
||||
const checkConnection = await pgClient.raw('SELECT 1');
|
||||
|
||||
logger.debug(checkConnection);
|
||||
|
||||
await $.auth.set({
|
||||
screenName: `${$.auth.data.user}@${$.auth.data.host}:${$.auth.data.port}/${$.auth.data.database}`,
|
||||
client: 'pg',
|
||||
version: $.auth.data.version,
|
||||
host: $.auth.data.host,
|
||||
port: Number($.auth.data.port),
|
||||
user: $.auth.data.user,
|
||||
password: $.auth.data.password,
|
||||
database: $.auth.data.database
|
||||
});
|
||||
};
|
||||
|
||||
export default verifyCredentials;
|
@@ -0,0 +1,20 @@
|
||||
import knex, { Knex } from 'knex';
|
||||
import { IGlobalVariable } from '@automatisch/types';
|
||||
|
||||
const getClient = ($: IGlobalVariable): Knex<any, unknown[]> => {
|
||||
const pgClient = knex({
|
||||
client: 'pg',
|
||||
version: $.auth.data.version as string,
|
||||
connection: {
|
||||
host: $.auth.data.host as string,
|
||||
port: Number($.auth.data.port),
|
||||
user: $.auth.data.user as string,
|
||||
password: $.auth.data.password as string,
|
||||
database: $.auth.data.database as string,
|
||||
}
|
||||
})
|
||||
|
||||
return pgClient;
|
||||
};
|
||||
|
||||
export default getClient;
|
@@ -0,0 +1,16 @@
|
||||
import { Knex } from 'knex';
|
||||
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
|
||||
|
||||
const setParams = async ($: IGlobalVariable, client: Knex<any, unknown[]>): Promise<Knex.Raw<any>> => {
|
||||
|
||||
const params: any = $.step.parameters.params
|
||||
let paramsObj: IJSONObject = {}
|
||||
params.forEach((ele: any) => { paramsObj[ele.configParam] = ele.value })
|
||||
|
||||
for (const key in paramsObj) {
|
||||
const res = await client.raw(`SET ${key} = '${paramsObj[key]}'`);
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
export default setParams;
|
0
packages/backend/src/apps/postgresql/index.d.ts
vendored
Normal file
0
packages/backend/src/apps/postgresql/index.d.ts
vendored
Normal file
17
packages/backend/src/apps/postgresql/index.ts
Normal file
17
packages/backend/src/apps/postgresql/index.ts
Normal file
@@ -0,0 +1,17 @@
|
||||
import defineApp from '../../helpers/define-app';
|
||||
import auth from './auth';
|
||||
import actions from './actions';
|
||||
|
||||
export default defineApp({
|
||||
name: 'PostgreSQL database',
|
||||
key: 'postgresql',
|
||||
iconUrl: '{BASE_URL}/apps/postgresql/assets/favicon.svg',
|
||||
authDocUrl: 'https://automatisch.io/docs/apps/postgresql/connection',
|
||||
supportsConnections: true,
|
||||
baseUrl: '',
|
||||
apiBaseUrl: '',
|
||||
primaryColor: '336791',
|
||||
|
||||
auth,
|
||||
actions
|
||||
});
|
Reference in New Issue
Block a user