Some quick updates after testing.
This commit is contained in:
parent
a056176050
commit
765e38aafc
|
@ -53,6 +53,10 @@ async function handleRequest(
|
||||||
entityId: tableName,
|
entityId: tableName,
|
||||||
operation,
|
operation,
|
||||||
},
|
},
|
||||||
|
resource: {
|
||||||
|
// not specifying any fields means "*"
|
||||||
|
fields: [],
|
||||||
|
},
|
||||||
filters: idFilters != null ? idFilters : filters,
|
filters: idFilters != null ? idFilters : filters,
|
||||||
sort,
|
sort,
|
||||||
paginate,
|
paginate,
|
||||||
|
@ -68,7 +72,7 @@ exports.patch = async ctx => {
|
||||||
const id = inputs._id
|
const id = inputs._id
|
||||||
// don't save the ID to db
|
// don't save the ID to db
|
||||||
delete inputs._id
|
delete inputs._id
|
||||||
ctx.body = await handleRequest(appId, DataSourceOperation.UPDATE, tableId, {
|
return handleRequest(appId, DataSourceOperation.UPDATE, tableId, {
|
||||||
id,
|
id,
|
||||||
row: inputs,
|
row: inputs,
|
||||||
})
|
})
|
||||||
|
@ -81,7 +85,7 @@ exports.save = async ctx => {
|
||||||
return exports.patch(ctx)
|
return exports.patch(ctx)
|
||||||
}
|
}
|
||||||
const tableId = ctx.params.tableId
|
const tableId = ctx.params.tableId
|
||||||
ctx.body = await handleRequest(appId, DataSourceOperation.CREATE, tableId, {
|
return handleRequest(appId, DataSourceOperation.CREATE, tableId, {
|
||||||
row: inputs,
|
row: inputs,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -96,14 +100,14 @@ exports.fetchView = async ctx => {
|
||||||
exports.fetch = async ctx => {
|
exports.fetch = async ctx => {
|
||||||
const appId = ctx.appId
|
const appId = ctx.appId
|
||||||
const tableId = ctx.params.tableId
|
const tableId = ctx.params.tableId
|
||||||
ctx.body = await handleRequest(appId, DataSourceOperation.READ, tableId)
|
return handleRequest(appId, DataSourceOperation.READ, tableId)
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.find = async ctx => {
|
exports.find = async ctx => {
|
||||||
const appId = ctx.appId
|
const appId = ctx.appId
|
||||||
const id = ctx.params.rowId
|
const id = ctx.params.rowId
|
||||||
const tableId = ctx.params.tableId
|
const tableId = ctx.params.tableId
|
||||||
ctx.body = await handleRequest(appId, DataSourceOperation.READ, tableId, {
|
return handleRequest(appId, DataSourceOperation.READ, tableId, {
|
||||||
id,
|
id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -111,7 +115,7 @@ exports.find = async ctx => {
|
||||||
exports.destroy = async ctx => {
|
exports.destroy = async ctx => {
|
||||||
const appId = ctx.appId
|
const appId = ctx.appId
|
||||||
const tableId = ctx.params.tableId
|
const tableId = ctx.params.tableId
|
||||||
ctx.body = await handleRequest(appId, DataSourceOperation.DELETE, tableId, {
|
return handleRequest(appId, DataSourceOperation.DELETE, tableId, {
|
||||||
id: ctx.request.body._id,
|
id: ctx.request.body._id,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
@ -128,7 +132,7 @@ exports.bulkDestroy = async ctx => {
|
||||||
}))
|
}))
|
||||||
}
|
}
|
||||||
await Promise.all(promises)
|
await Promise.all(promises)
|
||||||
ctx.body = { response: { ok: true }, rows }
|
return { response: { ok: true }, rows }
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.search = async ctx => {
|
exports.search = async ctx => {
|
||||||
|
@ -153,7 +157,7 @@ exports.search = async ctx => {
|
||||||
[params.sort]: direction,
|
[params.sort]: direction,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ctx.body = await handleRequest(appId, DataSourceOperation.READ, tableId, {
|
return handleRequest(appId, DataSourceOperation.READ, tableId, {
|
||||||
filters: query,
|
filters: query,
|
||||||
sort,
|
sort,
|
||||||
paginate: paginateObj,
|
paginate: paginateObj,
|
||||||
|
@ -162,10 +166,10 @@ exports.search = async ctx => {
|
||||||
|
|
||||||
exports.validate = async ctx => {
|
exports.validate = async ctx => {
|
||||||
// can't validate external right now - maybe in future
|
// can't validate external right now - maybe in future
|
||||||
ctx.body = { valid: true }
|
return { valid: true }
|
||||||
}
|
}
|
||||||
|
|
||||||
exports.fetchEnrichedRow = async ctx => {
|
exports.fetchEnrichedRow = async ctx => {
|
||||||
// TODO: How does this work
|
// TODO: How does this work
|
||||||
ctx.throw(501, "Not implemented")
|
throw "Not Implemented"
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,7 +18,7 @@ validateJs.extend(validateJs.validators.datetime, {
|
||||||
|
|
||||||
exports.makeExternalQuery = async (appId, json) => {
|
exports.makeExternalQuery = async (appId, json) => {
|
||||||
const datasourceId = json.endpoint.datasourceId
|
const datasourceId = json.endpoint.datasourceId
|
||||||
const database = new CouchDB(ctx.appId)
|
const database = new CouchDB(appId)
|
||||||
const datasource = await database.get(datasourceId)
|
const datasource = await database.get(datasourceId)
|
||||||
const Integration = integrations[datasource.source]
|
const Integration = integrations[datasource.source]
|
||||||
// query is the opinionated function
|
// query is the opinionated function
|
||||||
|
|
|
@ -3,8 +3,6 @@ const { DataSourceOperation, SortDirection } = require("../../constants")
|
||||||
const BASE_LIMIT = 5000
|
const BASE_LIMIT = 5000
|
||||||
|
|
||||||
function addFilters(query, filters) {
|
function addFilters(query, filters) {
|
||||||
// if all or specified in filters, then everything is an or
|
|
||||||
const allOr = !!filters.allOr
|
|
||||||
function iterate(structure, fn) {
|
function iterate(structure, fn) {
|
||||||
for (let [key, value] of Object.entries(structure)) {
|
for (let [key, value] of Object.entries(structure)) {
|
||||||
fn(key, value)
|
fn(key, value)
|
||||||
|
@ -13,6 +11,8 @@ function addFilters(query, filters) {
|
||||||
if (!filters) {
|
if (!filters) {
|
||||||
return query
|
return query
|
||||||
}
|
}
|
||||||
|
// if all or specified in filters, then everything is an or
|
||||||
|
const allOr = !!filters.allOr
|
||||||
if (filters.string) {
|
if (filters.string) {
|
||||||
iterate(filters.string, (key, value) => {
|
iterate(filters.string, (key, value) => {
|
||||||
const fnc = allOr ? "orWhere" : "where"
|
const fnc = allOr ? "orWhere" : "where"
|
||||||
|
|
|
@ -53,7 +53,7 @@ const SCHEMA = {
|
||||||
|
|
||||||
async function internalQuery(client, sql) {
|
async function internalQuery(client, sql) {
|
||||||
try {
|
try {
|
||||||
return await client.query(sql)
|
return await client.query(sql.sql, sql.bindings)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err)
|
throw new Error(err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ function internalQuery(client, query) {
|
||||||
// Node MySQL is callback based, so we must wrap our call in a promise
|
// Node MySQL is callback based, so we must wrap our call in a promise
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
client.connect()
|
client.connect()
|
||||||
return client.query(query, (error, results) => {
|
return client.query(query.sql, query.bindings, (error, results) => {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error)
|
reject(error)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -119,7 +119,7 @@ class PostgresPlus extends Sql {
|
||||||
async query(json) {
|
async query(json) {
|
||||||
const operation = this._operation(json).toLowerCase()
|
const operation = this._operation(json).toLowerCase()
|
||||||
const sql = this._query(json)
|
const sql = this._query(json)
|
||||||
const response = await this.client.query(sql)
|
const response = await this.client.query(sql.sql, sql.bindings)
|
||||||
return response.rows.length ? response.rows : [{ [operation]: true }]
|
return response.rows.length ? response.rows : [{ [operation]: true }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,7 +57,7 @@ const SCHEMA = {
|
||||||
|
|
||||||
async function internalQuery(client, sql) {
|
async function internalQuery(client, sql) {
|
||||||
try {
|
try {
|
||||||
return await client.query(sql)
|
return await client.query(sql.sql, sql.bindings)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw new Error(err)
|
throw new Error(err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue