Some quick work to make it function as required.
This commit is contained in:
parent
91de2fb78e
commit
a056176050
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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 => {
|
||||
|
|
|
@ -38,7 +38,6 @@ router
|
|||
authorized(PermissionTypes.TABLE, PermissionLevels.READ),
|
||||
rowController.search
|
||||
)
|
||||
|
||||
.post(
|
||||
"/api/:tableId/rows",
|
||||
paramResource("tableId"),
|
||||
|
|
|
@ -79,12 +79,16 @@ class PostgresPlus extends Sql {
|
|||
this.client = this.pool
|
||||
}
|
||||
|
||||
async init() {
|
||||
async init(datasourceId) {
|
||||
let keys = []
|
||||
try {
|
||||
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
|
||||
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: {},
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue