Merge branch 'feature/opinionated-sql' of github.com:Budibase/budibase into feature/opinionated-sql

This commit is contained in:
Martin McKeaveney 2021-06-17 12:49:17 +01:00
commit 50c083d8a6
3 changed files with 10 additions and 8 deletions

View File

@ -136,9 +136,6 @@ exports.patch = async ctx => {
exports.save = async ctx => {
const appId = ctx.appId
const inputs = ctx.request.body
if (inputs._id) {
return exports.patch(ctx)
}
const tableId = ctx.params.tableId
return handleRequest(appId, DataSourceOperation.CREATE, tableId, {
row: inputs,

View File

@ -24,6 +24,11 @@ function getTableId(ctx) {
exports.patch = async ctx => {
const appId = ctx.appId
const tableId = getTableId(ctx)
const body = ctx.request.body
// if it doesn't have an _id then its save
if (body && !body._id) {
return exports.save(ctx)
}
try {
const { row, table } = await pickApi(tableId).patch(ctx)
ctx.eventEmitter &&
@ -38,6 +43,11 @@ exports.patch = async ctx => {
exports.save = async function (ctx) {
const appId = ctx.appId
const tableId = getTableId(ctx)
const body = ctx.request.body
// if it has an ID already then its a patch
if (body && body._id) {
return exports.patch(ctx)
}
try {
const { row, table } = await pickApi(tableId).save(ctx)
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)

View File

@ -95,11 +95,6 @@ exports.save = async function (ctx) {
let inputs = ctx.request.body
inputs.tableId = ctx.params.tableId
// if the row obj had an _id then it will have been retrieved
if (inputs._id && inputs._rev) {
return exports.patch(ctx)
}
if (!inputs._rev && !inputs._id) {
inputs._id = generateRowID(inputs.tableId)
}