Add ability to auto-generate PK before insert
All checks were successful
continuous-integration/drone Build is passing

This commit is contained in:
Garrett Mills 2022-12-09 04:42:35 -06:00
parent 30e31b2dd3
commit 53087f08a5
3 changed files with 7 additions and 0 deletions

View File

@ -58,6 +58,7 @@ export interface ResourceConfiguration {
key: string,
collection: string,
primaryKey: string,
generateKeyOnInsert?: () => string|number,
display: {
field?: string,
singular: string,

View File

@ -1,3 +1,4 @@
import {uuid4} from '@extollo/lib'
import {allResourceActions, FieldType, Renderer, ResourceAction, ResourceConfiguration} from '../cobalt'
export default {
@ -178,6 +179,7 @@ export default {
{
key: 'feedPost',
primaryKey: 'feed_post_id',
generateKeyOnInsert: uuid4,
collection: 'feed_posts',
display: {
// field: '',

View File

@ -83,6 +83,10 @@ export class ResourceAPI extends Controller {
queryRow[field.key] = this.castValue(field, value)
}
if ( config.generateKeyOnInsert ) {
queryRow[config.primaryKey] = config.generateKeyOnInsert()
}
// Create insert query
const result = await this.make<Builder>(Builder)
.table(config.collection)