1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00
budibase/packages/server/src/integrations/postgres.js

117 lines
2 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",
},
2021-01-12 10:01:21 +13:00
"Simple Query": {
type: "fields",
fields: {
2021-01-12 10:01:21 +13:00
table: {
type: "string",
},
column: {
type: "string",
},
condition: {
type: "options",
options: [
{
name: "Equals",
value: "=",
},
{
name: "Not Equals",
value: "!=",
},
{
name: "Greater Than",
value: ">",
},
{
name: "Less Than",
value: "<",
},
],
},
value: {
type: "string",
},
},
},
},
}
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()
}
2021-01-12 06:18:22 +13:00
// async create() {
// }
async read() {
const response = await this.client.query(this.queryString)
return response.rows
}
// async update() {
// }
// async delete() {
// }
2021-01-13 05:49:11 +13:00
// async query() {
// 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,
}