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