2020-11-26 15:43:56 +01:00
|
|
|
const { Client } = require("pg")
|
|
|
|
|
2021-01-08 13:06:37 +01:00
|
|
|
const SCHEMA = {
|
2021-01-15 18:29:46 +01:00
|
|
|
docs: "https://node-postgres.com",
|
2021-01-08 13:06:37 +01:00
|
|
|
datasource: {
|
|
|
|
host: {
|
|
|
|
type: "string",
|
|
|
|
default: "localhost",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
port: {
|
|
|
|
type: "number",
|
|
|
|
required: true,
|
|
|
|
default: 5432,
|
|
|
|
},
|
|
|
|
database: {
|
|
|
|
type: "string",
|
|
|
|
default: "postgres",
|
|
|
|
required: true,
|
|
|
|
},
|
2021-01-20 14:23:06 +01:00
|
|
|
user: {
|
2021-01-08 13:06:37 +01:00
|
|
|
type: "string",
|
|
|
|
default: "root",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
password: {
|
|
|
|
type: "password",
|
|
|
|
default: "root",
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
2021-01-11 16:34:43 +01:00
|
|
|
query: {
|
2021-01-13 15:11:53 +01:00
|
|
|
create: {
|
2021-01-22 13:22:28 +01:00
|
|
|
type: "sql",
|
2021-01-13 15:11:53 +01:00
|
|
|
},
|
|
|
|
read: {
|
2021-01-22 13:22:28 +01:00
|
|
|
type: "sql",
|
2021-01-13 15:11:53 +01:00
|
|
|
},
|
|
|
|
update: {
|
2021-01-22 13:22:28 +01:00
|
|
|
type: "sql",
|
2021-01-13 15:11:53 +01:00
|
|
|
},
|
|
|
|
delete: {
|
2021-01-22 13:22:28 +01:00
|
|
|
type: "sql",
|
2021-01-08 13:06:37 +01:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
|
2020-11-26 15:43:56 +01:00
|
|
|
class PostgresIntegration {
|
2021-01-13 15:11:53 +01:00
|
|
|
constructor(config) {
|
2020-11-26 15:43:56 +01:00
|
|
|
this.config = config
|
|
|
|
this.client = new Client(config)
|
|
|
|
this.connect()
|
|
|
|
}
|
|
|
|
|
|
|
|
async connect() {
|
|
|
|
return this.client.connect()
|
|
|
|
}
|
|
|
|
|
2021-01-13 15:11:53 +01:00
|
|
|
async create({ sql }) {
|
|
|
|
const response = await this.client.query(sql)
|
2021-01-12 18:45:43 +01:00
|
|
|
return response.rows
|
|
|
|
}
|
2021-01-11 18:18:22 +01:00
|
|
|
|
2021-01-13 15:11:53 +01:00
|
|
|
async read({ sql }) {
|
|
|
|
const response = await this.client.query(sql)
|
2021-01-11 18:18:22 +01:00
|
|
|
return response.rows
|
|
|
|
}
|
|
|
|
|
2021-01-13 15:11:53 +01:00
|
|
|
async update({ sql }) {
|
|
|
|
const response = await this.client.query(sql)
|
2021-01-12 18:45:43 +01:00
|
|
|
return response.rows
|
|
|
|
}
|
2021-01-11 18:18:22 +01:00
|
|
|
|
2021-01-13 15:11:53 +01:00
|
|
|
async delete({ sql }) {
|
|
|
|
const response = await this.client.query(sql)
|
2021-01-12 18:45:43 +01:00
|
|
|
return response.rows
|
|
|
|
}
|
2020-11-26 15:43:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = {
|
2021-01-11 16:34:43 +01:00
|
|
|
schema: SCHEMA,
|
2020-11-26 15:43:56 +01:00
|
|
|
integration: PostgresIntegration,
|
|
|
|
}
|