chore(postgresql): rename app folder and add icon

This commit is contained in:
Ali BARIN
2023-05-09 19:37:06 +00:00
parent 0c8343e76f
commit f29ccace2a
19 changed files with 214 additions and 263 deletions

View File

@@ -1,85 +0,0 @@
import verifyCredentials from './verify-credentials';
import isStillVerified from './is-still-verified';
export default {
fields: [
{
key: 'version',
label: 'Postgres Version',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'The version of postgres database that user want to connect with.',
clickToCopy: false,
},
{
key: 'host',
label: 'Host',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'The host of postgres database.',
clickToCopy: false,
},
{
key: 'port',
label: 'Port',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'The port of postgres database.',
clickToCopy: false,
},
{
key: 'database',
label: 'Database Name',
type: 'string' as const,
required: true,
readOnly: false,
value: null,
placeholder: null,
description:
'The name of postgres database.',
clickToCopy: false,
},
{
key: 'user',
label: 'Database User Name',
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,
description:
'The password of the user.',
clickToCopy: false,
},
],
verifyCredentials,
isStillVerified
};

View File

@@ -1,22 +0,0 @@
// import { IGlobalVariable } from '@automatisch/types';
// import verifyCredentials from './verify-credentials';
// import { Knex } from 'knex';
// const isStillVerified = async ($: IGlobalVariable) => {
// await $.auth.data.pgClient.raw('SELECT 1')
// // await verifyCredentials($);
// return true;
// };
// export default isStillVerified;
import { IGlobalVariable } from '@automatisch/types';
import verifyCredentials from './verify-credentials';
const isStillVerified = async ($: IGlobalVariable) => {
await verifyCredentials($);
return true;
};
export default isStillVerified;

View File

@@ -1,57 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import logger from '../../../helpers/logger';
import setConfig from '../common/postgres-configuration';
const verifyCredentials = async ($: IGlobalVariable) => {
const pgClient = await setConfig($)
const checkConnection = await pgClient.raw('SELECT 1')
logger.debug(checkConnection)
await $.auth.set({
screenName: `${$.auth.data.database} DB`,
client: 'pg',
version: $.auth.data.version,
host : $.auth.data.host,
port : $.auth.data.port,
user : $.auth.data.user,
password : $.auth.data.password,
database : $.auth.data.database
});
};
export default verifyCredentials;
/*
mutation Login($input: LoginInput) { login(input: $input) { token user { id email __typename } __typename }}
mutation CreateConnection($input: CreateConnectionInput) { createConnection(input: $input) { id key verified formattedData { screenName __typename } __typename }}
{
"input":
{
"key": "postgres",
"formattedData": {
"version":"15",
"host":"127.0.0.1",
"port":"6500",
"database":"bbs",
"user":"test",
"password":"@Test123"
}
}
}
mutation VerifyConnection($input: VerifyConnectionInput) { verifyConnection(input: $input) { id key verified formattedData { screenName __typename } createdAt app { key __typename } __typename }}
{
"input":
{"id": "18309778-ef78-41ae-be1b-ff51781134c0"}
}
*/

View File

@@ -1,22 +0,0 @@
import { IGlobalVariable } from '@automatisch/types';
import knex, { Knex } from 'knex'
const setConfig = async ($: IGlobalVariable) : Promise<Knex<any, unknown[]>> => {
const pgClient = knex({
client: 'pg',
version: $.auth.data.version as string,
connection: {
host : $.auth.data.host as string,
port : $.auth.data.port as number,
user : $.auth.data.user as string,
password : $.auth.data.password as string,
database : $.auth.data.database as string
}
})
return pgClient;
};
export default setConfig;

View File

@@ -1,17 +0,0 @@
import { IGlobalVariable, IJSONObject } from '@automatisch/types';
import { Knex } from 'knex'
import logger from '../../../helpers/logger';
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;

View File

@@ -1,17 +0,0 @@
import defineApp from '../../helpers/define-app';
import auth from './auth';
import actions from './actions';
export default defineApp({
name: 'PostgreSQL DataBase',
key: 'postgres',
iconUrl: '{BASE_URL}/apps/thecatapi/assets/favicon.svg',
authDocUrl: 'https://automatisch.io/docs/apps/thecatapi/connection',
supportsConnections: true,
baseUrl: '', // https://thecatapi.com
apiBaseUrl: '', // https://api.thecatapi.com
primaryColor: '000000',
auth,
actions
});

View File

@@ -1,6 +1,6 @@
import { IJSONObject, IJSONArray } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import setConfig from '../../common/postgres-configuration';
import setConfig from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
export default defineAction({
@@ -61,9 +61,9 @@ export default defineAction({
async run($) {
const pgClient = await setConfig($)
const params : any = $.step.parameters.params
if (params[0].configParam != '')
await setParams($, pgClient)
const params: any = $.step.parameters.params
if (params[0].configParam != '')
await setParams($, pgClient)
const whereStatemennt = $.step.parameters.whereStatement as string
const whereParts = whereStatemennt.split(",")
@@ -73,13 +73,13 @@ export default defineAction({
const conditionValue = whereParts[2]
const response = await pgClient(`${$.step.parameters.schema}.${$.step.parameters.table}`)
.returning('*')
.where(conditionColumn, RelationalOperator, conditionValue)
.del() as IJSONArray
.returning('*')
.where(conditionColumn, RelationalOperator, conditionValue)
.del() as IJSONArray
let deletedData : IJSONObject = {}
response.forEach( (ele: IJSONObject, i : number) => { deletedData[`record${i}`] = ele } )
let deletedData: IJSONObject = {}
response.forEach((ele: IJSONObject, i: number) => { deletedData[`record${i}`] = ele })
$.setActionItem({ raw: deletedData as IJSONObject });
$.setActionItem({ raw: deletedData as IJSONObject });
},
});

View File

@@ -1,6 +1,6 @@
import { IJSONObject } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import setConfig from '../../common/postgres-configuration';
import setConfig from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
export default defineAction({
@@ -76,18 +76,18 @@ export default defineAction({
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 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
.returning('*')
.insert(data) as IJSONObject
$.setActionItem({ raw: response[0] as IJSONObject });
$.setActionItem({ raw: response[0] as IJSONObject });
},
});

View File

@@ -1,6 +1,6 @@
import { IJSONObject } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import setConfig from '../../common/postgres-configuration';
import setConfig from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
export default defineAction({
@@ -45,16 +45,16 @@ export default defineAction({
async run($) {
const pgClient = await setConfig($)
const params : any = $.step.parameters.params
if (params[0].configParam != '')
await setParams($, pgClient)
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 });
const res = { msg: `SQL query: " ${$.step.parameters.queryStatement} " has been executed successfully` }
$.setActionItem({ raw: res as IJSONObject });
},
});

View File

@@ -1,6 +1,6 @@
import { IJSONObject, IJSONArray } from '@automatisch/types';
import defineAction from '../../../../helpers/define-action';
import setConfig from '../../common/postgres-configuration';
import setConfig from '../../common/postgres-client';
import setParams from '../../common/set-run-time-parameters';
export default defineAction({
@@ -84,9 +84,9 @@ export default defineAction({
async run($) {
const pgClient = await setConfig($)
const params : any = $.step.parameters.params
if (params[0].configParam != '')
await setParams($, pgClient)
const params: any = $.step.parameters.params
if (params[0].configParam != '')
await setParams($, pgClient)
const whereStatemennt = $.step.parameters.whereStatement as string
const whereParts = whereStatemennt.split(",")
@@ -95,18 +95,18 @@ export default defineAction({
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 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
.returning('*')
.where(conditionColumn, RelationalOperator, conditionValue)
.update(data) as IJSONArray
let updatedData : IJSONObject = {}
response.forEach( (ele: IJSONObject, i : number) => { updatedData[`record${i}`] = ele } )
let updatedData: IJSONObject = {}
response.forEach((ele: IJSONObject, i: number) => { updatedData[`record${i}`] = ele })
$.setActionItem({ raw: updatedData as IJSONObject });
$.setActionItem({ raw: updatedData as IJSONObject });
},
});

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 13 KiB

View 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
};

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View 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
});