Add ability to auto-generate PK before insert
All checks were successful
continuous-integration/drone Build is passing
All checks were successful
continuous-integration/drone Build is passing
This commit is contained in:
parent
30e31b2dd3
commit
53087f08a5
@ -58,6 +58,7 @@ export interface ResourceConfiguration {
|
|||||||
key: string,
|
key: string,
|
||||||
collection: string,
|
collection: string,
|
||||||
primaryKey: string,
|
primaryKey: string,
|
||||||
|
generateKeyOnInsert?: () => string|number,
|
||||||
display: {
|
display: {
|
||||||
field?: string,
|
field?: string,
|
||||||
singular: string,
|
singular: string,
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import {uuid4} from '@extollo/lib'
|
||||||
import {allResourceActions, FieldType, Renderer, ResourceAction, ResourceConfiguration} from '../cobalt'
|
import {allResourceActions, FieldType, Renderer, ResourceAction, ResourceConfiguration} from '../cobalt'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
@ -178,6 +179,7 @@ export default {
|
|||||||
{
|
{
|
||||||
key: 'feedPost',
|
key: 'feedPost',
|
||||||
primaryKey: 'feed_post_id',
|
primaryKey: 'feed_post_id',
|
||||||
|
generateKeyOnInsert: uuid4,
|
||||||
collection: 'feed_posts',
|
collection: 'feed_posts',
|
||||||
display: {
|
display: {
|
||||||
// field: '',
|
// field: '',
|
||||||
|
@ -83,6 +83,10 @@ export class ResourceAPI extends Controller {
|
|||||||
queryRow[field.key] = this.castValue(field, value)
|
queryRow[field.key] = this.castValue(field, value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( config.generateKeyOnInsert ) {
|
||||||
|
queryRow[config.primaryKey] = config.generateKeyOnInsert()
|
||||||
|
}
|
||||||
|
|
||||||
// Create insert query
|
// Create insert query
|
||||||
const result = await this.make<Builder>(Builder)
|
const result = await this.make<Builder>(Builder)
|
||||||
.table(config.collection)
|
.table(config.collection)
|
||||||
|
Loading…
Reference in New Issue
Block a user