Add ability to auto-generate PK before insert
continuous-integration/drone Build is passing Details

master
Garrett Mills 1 year ago
parent 30e31b2dd3
commit 53087f08a5

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

@ -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: '',

@ -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)

Loading…
Cancel
Save