Add query quota increment to rows CRUD
This commit is contained in:
parent
d17cbb011a
commit
879a62c989
|
@ -31,7 +31,9 @@ export async function patch(ctx: any): Promise<any> {
|
||||||
return save(ctx)
|
return save(ctx)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const { row, table } = await pickApi(tableId).patch(ctx)
|
const { row, table } = await quotas.addQuery(() =>
|
||||||
|
pickApi(tableId).patch(ctx)
|
||||||
|
)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.eventEmitter &&
|
ctx.eventEmitter &&
|
||||||
ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
|
ctx.eventEmitter.emitRow(`row:update`, appId, row, table)
|
||||||
|
@ -42,7 +44,7 @@ export async function patch(ctx: any): Promise<any> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveRow = async (ctx: any) => {
|
export const save = async (ctx: any) => {
|
||||||
const appId = ctx.appId
|
const appId = ctx.appId
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
const body = ctx.request.body
|
const body = ctx.request.body
|
||||||
|
@ -51,7 +53,9 @@ const saveRow = async (ctx: any) => {
|
||||||
return patch(ctx)
|
return patch(ctx)
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
const { row, table } = await pickApi(tableId).save(ctx)
|
const { row, table } = await quotas.addRow(() =>
|
||||||
|
quotas.addQuery(() => pickApi(tableId).save(ctx))
|
||||||
|
)
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:save`, appId, row, table)
|
||||||
ctx.message = `${table.name} saved successfully`
|
ctx.message = `${table.name} saved successfully`
|
||||||
|
@ -61,14 +65,10 @@ const saveRow = async (ctx: any) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function save(ctx: any) {
|
|
||||||
await quotas.addRow(() => saveRow(ctx))
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function fetchView(ctx: any) {
|
export async function fetchView(ctx: any) {
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
try {
|
try {
|
||||||
ctx.body = await pickApi(tableId).fetchView(ctx)
|
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetchView(ctx))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ export async function fetchView(ctx: any) {
|
||||||
export async function fetch(ctx: any) {
|
export async function fetch(ctx: any) {
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
try {
|
try {
|
||||||
ctx.body = await pickApi(tableId).fetch(ctx)
|
ctx.body = await quotas.addQuery(() => pickApi(tableId).fetch(ctx))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
|
@ -86,7 +86,7 @@ export async function fetch(ctx: any) {
|
||||||
export async function find(ctx: any) {
|
export async function find(ctx: any) {
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
try {
|
try {
|
||||||
ctx.body = await pickApi(tableId).find(ctx)
|
ctx.body = await quotas.addQuery(() => pickApi(tableId).find(ctx))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
|
@ -98,14 +98,16 @@ export async function destroy(ctx: any) {
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
let response, row
|
let response, row
|
||||||
if (inputs.rows) {
|
if (inputs.rows) {
|
||||||
let { rows } = await pickApi(tableId).bulkDestroy(ctx)
|
let { rows } = await quotas.addQuery(() =>
|
||||||
|
pickApi(tableId).bulkDestroy(ctx)
|
||||||
|
)
|
||||||
await quotas.removeRows(rows.length)
|
await quotas.removeRows(rows.length)
|
||||||
response = rows
|
response = rows
|
||||||
for (let row of rows) {
|
for (let row of rows) {
|
||||||
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
|
ctx.eventEmitter && ctx.eventEmitter.emitRow(`row:delete`, appId, row)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
let resp = await pickApi(tableId).destroy(ctx)
|
let resp = await quotas.addQuery(() => pickApi(tableId).destroy(ctx))
|
||||||
await quotas.removeRow()
|
await quotas.removeRow()
|
||||||
response = resp.response
|
response = resp.response
|
||||||
row = resp.row
|
row = resp.row
|
||||||
|
@ -121,7 +123,7 @@ export async function search(ctx: any) {
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
try {
|
try {
|
||||||
ctx.status = 200
|
ctx.status = 200
|
||||||
ctx.body = await pickApi(tableId).search(ctx)
|
ctx.body = await quotas.addQuery(() => pickApi(tableId).search(ctx))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
|
@ -139,7 +141,9 @@ export async function validate(ctx: any) {
|
||||||
export async function fetchEnrichedRow(ctx: any) {
|
export async function fetchEnrichedRow(ctx: any) {
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
try {
|
try {
|
||||||
ctx.body = await pickApi(tableId).fetchEnrichedRow(ctx)
|
ctx.body = await quotas.addQuery(() =>
|
||||||
|
pickApi(tableId).fetchEnrichedRow(ctx)
|
||||||
|
)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
|
@ -148,7 +152,7 @@ export async function fetchEnrichedRow(ctx: any) {
|
||||||
export const exportRows = async (ctx: any) => {
|
export const exportRows = async (ctx: any) => {
|
||||||
const tableId = getTableId(ctx)
|
const tableId = getTableId(ctx)
|
||||||
try {
|
try {
|
||||||
ctx.body = await pickApi(tableId).exportRows(ctx)
|
ctx.body = await quotas.addQuery(() => pickApi(tableId).exportRows(ctx))
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
ctx.throw(400, err)
|
ctx.throw(400, err)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1014,10 +1014,10 @@
|
||||||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||||
|
|
||||||
"@budibase/backend-core@1.0.147":
|
"@budibase/backend-core@1.0.149":
|
||||||
version "1.0.147"
|
version "1.0.149"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.147.tgz#fc93a803e97e304170b33bd28b4f5deda32bec18"
|
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa"
|
||||||
integrity sha512-0GcF9G/tTAsko9g352MB8K3EtMTVb7v7Av6RdsYyKBdVtOD42HKFzSOD0n/RQUL4v70YByiu99zJAB6z1m1Pcg==
|
integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@techpass/passport-openidconnect" "^0.3.0"
|
"@techpass/passport-openidconnect" "^0.3.0"
|
||||||
aws-sdk "^2.901.0"
|
aws-sdk "^2.901.0"
|
||||||
|
@ -1091,12 +1091,12 @@
|
||||||
svelte-flatpickr "^3.2.3"
|
svelte-flatpickr "^3.2.3"
|
||||||
svelte-portal "^1.0.0"
|
svelte-portal "^1.0.0"
|
||||||
|
|
||||||
"@budibase/pro@1.0.147":
|
"@budibase/pro@1.0.149":
|
||||||
version "1.0.147"
|
version "1.0.149"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.147.tgz#c1ec9d92ffaa40285a83c57ddbec1f32802cd9a1"
|
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e"
|
||||||
integrity sha512-e4im6Byqeeit/QFHkVhVdRmgIlJJY/W06cQrOuiG/1ngO4PGnXeJqtjQjHVfvchD5Xi3y1MgQ4AtH2Bzb5LEhw==
|
integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@budibase/backend-core" "1.0.147"
|
"@budibase/backend-core" "1.0.149"
|
||||||
node-fetch "^2.6.1"
|
node-fetch "^2.6.1"
|
||||||
|
|
||||||
"@budibase/standard-components@^0.9.139":
|
"@budibase/standard-components@^0.9.139":
|
||||||
|
|
|
@ -293,10 +293,10 @@
|
||||||
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
|
||||||
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
|
||||||
|
|
||||||
"@budibase/backend-core@1.0.147":
|
"@budibase/backend-core@1.0.149":
|
||||||
version "1.0.147"
|
version "1.0.149"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.147.tgz#fc93a803e97e304170b33bd28b4f5deda32bec18"
|
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-1.0.149.tgz#44e00dc718ef3f5c2f8021a13799c05b89f03cfa"
|
||||||
integrity sha512-0GcF9G/tTAsko9g352MB8K3EtMTVb7v7Av6RdsYyKBdVtOD42HKFzSOD0n/RQUL4v70YByiu99zJAB6z1m1Pcg==
|
integrity sha512-RudWkU6I+AoiARKcjDAKYmKgpW99VAmw8cULyL2QexFtrJaPwRX6UXDqP3Et887rAN+ee3t3tFIWEui51LAVPg==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@techpass/passport-openidconnect" "^0.3.0"
|
"@techpass/passport-openidconnect" "^0.3.0"
|
||||||
aws-sdk "^2.901.0"
|
aws-sdk "^2.901.0"
|
||||||
|
@ -321,12 +321,12 @@
|
||||||
uuid "^8.3.2"
|
uuid "^8.3.2"
|
||||||
zlib "^1.0.5"
|
zlib "^1.0.5"
|
||||||
|
|
||||||
"@budibase/pro@1.0.147":
|
"@budibase/pro@1.0.149":
|
||||||
version "1.0.147"
|
version "1.0.149"
|
||||||
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.147.tgz#c1ec9d92ffaa40285a83c57ddbec1f32802cd9a1"
|
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-1.0.149.tgz#6d3cc93635baffad4f425576c452bf9b8c6eb15e"
|
||||||
integrity sha512-e4im6Byqeeit/QFHkVhVdRmgIlJJY/W06cQrOuiG/1ngO4PGnXeJqtjQjHVfvchD5Xi3y1MgQ4AtH2Bzb5LEhw==
|
integrity sha512-zS+xIezmcJEB2yXzwSNI0OVDmFsBtE4r8ZVHKw+pGo1KqdJ1i11DEsfoAp9VxKOoo1ENDultujALfZQYlesMww==
|
||||||
dependencies:
|
dependencies:
|
||||||
"@budibase/backend-core" "1.0.147"
|
"@budibase/backend-core" "1.0.149"
|
||||||
node-fetch "^2.6.1"
|
node-fetch "^2.6.1"
|
||||||
|
|
||||||
"@cspotcode/source-map-consumer@0.8.0":
|
"@cspotcode/source-map-consumer@0.8.0":
|
||||||
|
|
Loading…
Reference in New Issue