1
0
Fork 0
mirror of synced 2024-07-04 05:50:57 +12:00
budibase/packages/server/src/integrations/postgres.js

80 lines
1.4 KiB
JavaScript
Raw Normal View History

2020-11-27 03:43:56 +13:00
const { Client } = require("pg")
const SCHEMA = {
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-12 10:01:21 +13:00
SQL: {
type: "sql",
},
},
}
2020-11-27 03:43:56 +13:00
class PostgresIntegration {
2020-12-19 07:19:43 +13:00
constructor(config, query) {
2020-11-27 03:43:56 +13:00
this.config = config
2020-12-19 07:19:43 +13:00
this.queryString = this.buildQuery(query)
2020-11-27 03:43:56 +13:00
this.client = new Client(config)
this.connect()
}
2020-12-19 07:19:43 +13:00
buildQuery(query) {
// TODO: account for different types
return query
}
2020-11-27 03:43:56 +13:00
async connect() {
return this.client.connect()
}
async create() {
const response = await this.client.query(this.queryString)
return response.rows
}
2021-01-12 06:18:22 +13:00
async read() {
const response = await this.client.query(this.queryString)
return response.rows
}
async update() {
const response = await this.client.query(this.queryString)
return response.rows
}
2021-01-12 06:18:22 +13:00
async delete() {
const response = await this.client.query(this.queryString)
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,
}