feat: Implement PostgreSQL connection
This commit is contained in:
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 |
38
packages/backend/src/apps/postgresql/index.ts
Normal file
38
packages/backend/src/apps/postgresql/index.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { Client } from 'pg';
|
||||||
|
import App from '../../models/app';
|
||||||
|
|
||||||
|
export default class PostgreSQL {
|
||||||
|
client: any
|
||||||
|
connectionData: any
|
||||||
|
appData: any
|
||||||
|
|
||||||
|
constructor(connectionData: any) {
|
||||||
|
this.client = new Client({
|
||||||
|
host: connectionData.host,
|
||||||
|
port: connectionData.port,
|
||||||
|
database: connectionData.database,
|
||||||
|
user: connectionData.username,
|
||||||
|
password: connectionData.password,
|
||||||
|
})
|
||||||
|
|
||||||
|
this.connectionData = connectionData;
|
||||||
|
this.appData = App.findOneByKey('postgresql');
|
||||||
|
}
|
||||||
|
|
||||||
|
async verifyCredentials() {
|
||||||
|
await this.client.connect()
|
||||||
|
|
||||||
|
return {
|
||||||
|
screenName: this.connectionData.database
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async isStillVerified() {
|
||||||
|
try {
|
||||||
|
await this.client.connect()
|
||||||
|
return true;
|
||||||
|
} catch(error) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
180
packages/backend/src/apps/postgresql/info.json
Normal file
180
packages/backend/src/apps/postgresql/info.json
Normal file
@@ -0,0 +1,180 @@
|
|||||||
|
{
|
||||||
|
"name": "PostgreSQL",
|
||||||
|
"key": "postgresql",
|
||||||
|
"iconUrl": "{BASE_URL}/apps/postgresql/assets/favicon.svg",
|
||||||
|
"docUrl": "https://automatisch.io/docs/postgresql",
|
||||||
|
"primaryColor": "2DAAE1",
|
||||||
|
"fields": [
|
||||||
|
{
|
||||||
|
"key": "host",
|
||||||
|
"label": "Host",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": "The host information Automatisch will connect to.",
|
||||||
|
"docUrl": "https://automatisch.io/docs/postgresql#host",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "port",
|
||||||
|
"label": "Port",
|
||||||
|
"type": "integer",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": 5432,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": null,
|
||||||
|
"docUrl": "https://automatisch.io/docs/postgresql#port",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "database",
|
||||||
|
"label": "Database",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": "The name of the database.",
|
||||||
|
"docUrl": "https://automatisch.io/docs/postgresql#password",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "username",
|
||||||
|
"label": "Username",
|
||||||
|
"type": "string",
|
||||||
|
"required": true,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": null,
|
||||||
|
"docUrl": "https://automatisch.io/docs/postgresql#username",
|
||||||
|
"clickToCopy": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"key": "password",
|
||||||
|
"label": "Password",
|
||||||
|
"type": "string",
|
||||||
|
"required": false,
|
||||||
|
"readOnly": false,
|
||||||
|
"value": null,
|
||||||
|
"placeholder": null,
|
||||||
|
"description": null,
|
||||||
|
"docUrl": "https://automatisch.io/docs/postgresql#password",
|
||||||
|
"clickToCopy": false
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"authenticationSteps": [
|
||||||
|
{
|
||||||
|
"step": 1,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "createConnection",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"name": "key",
|
||||||
|
"value": "{key}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"value": null,
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "host",
|
||||||
|
"value": "{fields.host}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "port",
|
||||||
|
"value": "{fields.port}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "database",
|
||||||
|
"value": "{fields.database}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "username",
|
||||||
|
"value": "{fields.username}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "password",
|
||||||
|
"value": "{fields.password}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 2,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{createConnection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"reconnectionSteps": [
|
||||||
|
{
|
||||||
|
"step": 1,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "resetConnection",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 2,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "updateConnection",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "data",
|
||||||
|
"value": null,
|
||||||
|
"properties": [
|
||||||
|
{
|
||||||
|
"name": "host",
|
||||||
|
"value": "{fields.host}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "port",
|
||||||
|
"value": "{fields.port}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "database",
|
||||||
|
"value": "{fields.database}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "username",
|
||||||
|
"value": "{fields.username}"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "password",
|
||||||
|
"value": "{fields.password}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"step": 3,
|
||||||
|
"type": "mutation",
|
||||||
|
"name": "verifyConnection",
|
||||||
|
"arguments": [
|
||||||
|
{
|
||||||
|
"name": "id",
|
||||||
|
"value": "{connection.id}"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Reference in New Issue
Block a user