1
0
Fork 0
mirror of synced 2024-06-03 02:55:14 +12:00

Some quick work to make it function as required.

This commit is contained in:
mike12345567 2021-06-15 13:20:25 +01:00
parent 91de2fb78e
commit a056176050
4 changed files with 19 additions and 11 deletions

View file

@ -35,7 +35,7 @@ exports.save = async function (ctx) {
const PlusConnector = plusIntegrations[datasource.source].integration
const connector = new PlusConnector(ctx.request.body.config)
await connector.init()
await connector.init(datasource._id)
datasource.entities = connector.tables
}

View file

@ -38,7 +38,9 @@ async function handleRequest(
tableId,
{ id, row, filters, sort, paginate } = {}
) {
let [datasourceId, tableName] = tableId.split("_")
const parts = tableId.split("_")
let tableName = parts.pop()
let datasourceId = parts.join("_")
const table = await getTable(appId, datasourceId, tableName)
if (!table) {
throw `Unable to process query, table "${tableName}" not defined.`
@ -86,7 +88,9 @@ exports.save = async ctx => {
exports.fetchView = async ctx => {
// there are no views in external data sources, shouldn't ever be called
ctx.throw(501, "Not implemented")
// for now just fetch
ctx.params.tableId = ctx.params.viewName.split("all_")[1]
return exports.fetch(ctx)
}
exports.fetch = async ctx => {

View file

@ -38,7 +38,6 @@ router
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
rowController.search
)
.post(
"/api/:tableId/rows",
paramResource("tableId"),

View file

@ -79,12 +79,16 @@ class PostgresPlus extends Sql {
this.client = this.pool
}
async init() {
const primaryKeysResponse = await this.client.query(this.PRIMARY_KEYS_SQL)
const primaryKeys = {}
for (let table of primaryKeysResponse.rows) {
primaryKeys[table.primary_key] = table.column_name
async init(datasourceId) {
let keys = []
try {
const primaryKeysResponse = await this.client.query(this.PRIMARY_KEYS_SQL)
for (let table of primaryKeysResponse.rows) {
keys.push(table.column_name)
}
} catch (err) {
// TODO: this try catch method isn't right
keys = ["id"]
}
const columnsResponse = await this.client.query(this.COLUMNS_SQL)
@ -97,7 +101,8 @@ class PostgresPlus extends Sql {
// table key doesn't exist yet
if (!tables[tableName]) {
tables[tableName] = {
_id: primaryKeys[tableName],
_id: `${datasourceId}_${tableName}`,
primary: keys,
name: tableName,
schema: {},
}