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

74 lines
1.2 KiB
JavaScript
Raw Normal View History

2020-11-27 03:43:56 +13:00
const { Client } = require("pg")
2020-12-19 07:19:43 +13:00
const DATASOURCE_CONFIG = {
2020-11-27 03:43:56 +13:00
host: {
type: "string",
default: "localhost",
2020-12-19 07:19:43 +13:00
required: true,
2020-11-27 03:43:56 +13:00
},
port: {
type: "number",
required: true,
default: 5432,
},
database: {
type: "string",
default: "postgres",
2020-12-19 07:19:43 +13:00
required: true,
2020-11-27 03:43:56 +13:00
},
username: {
type: "string",
default: "root",
2020-12-19 07:19:43 +13:00
required: true,
2020-11-27 03:43:56 +13:00
},
password: {
type: "password",
default: "root",
2020-11-27 05:46:36 +13:00
required: true,
},
2020-11-27 03:43:56 +13:00
}
2020-12-19 07:19:43 +13:00
const QUERY_CONFIG = {
sql: {
type: "sql",
},
gui: {
type: "config",
fields: {
something: "",
other: "",
},
},
}
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 query() {
2020-12-19 07:19:43 +13:00
const response = await this.client.query(this.queryString)
2020-11-27 03:43:56 +13:00
return response.rows
}
}
module.exports = {
2020-12-19 07:19:43 +13:00
schema: {
datasource: DATASOURCE_CONFIG,
query: QUERY_CONFIG,
},
2020-11-27 03:43:56 +13:00
integration: PostgresIntegration,
}