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 PlusConnector = plusIntegrations[datasource.source].integration
const connector = new PlusConnector(ctx.request.body.config) const connector = new PlusConnector(ctx.request.body.config)
await connector.init() await connector.init(datasource._id)
datasource.entities = connector.tables datasource.entities = connector.tables
} }

View File

@ -38,7 +38,9 @@ async function handleRequest(
tableId, tableId,
{ id, row, filters, sort, paginate } = {} { 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) const table = await getTable(appId, datasourceId, tableName)
if (!table) { if (!table) {
throw `Unable to process query, table "${tableName}" not defined.` throw `Unable to process query, table "${tableName}" not defined.`
@ -86,7 +88,9 @@ exports.save = async ctx => {
exports.fetchView = async ctx => { exports.fetchView = async ctx => {
// there are no views in external data sources, shouldn't ever be called // 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 => { exports.fetch = async ctx => {

View File

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

View File

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