Skip to content

Commit

Permalink
Merge pull request #125 from UN-OCHA/flow-insert-id
Browse files Browse the repository at this point in the history
Allow to specify flow ID when inserting new rows
  • Loading branch information
Pl217 authored Sep 22, 2023
2 parents 31b12c1 + b354f71 commit 843cef5
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@unocha/hpc-api-core",
"version": "6.0.0",
"version": "6.1.0",
"description": "Core libraries supporting HPC.Tools API Backend",
"license": "Apache-2.0",
"private": false,
Expand Down
2 changes: 1 addition & 1 deletion src/db/models/flow.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const FLOW_ID = brandedType<number, FlowId>(t.number);
export default defineIDModel({
tableName: 'flow',
fields: {
generated: {
generatedCompositeKey: {
id: { kind: 'branded-integer', brand: FLOW_ID },
},
required: {
Expand Down
3 changes: 2 additions & 1 deletion src/db/util/id-model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ export type { FieldsWithSequelize as FieldsWithId };
export const defineIDModel =
<
F extends FieldDefinition,
IDField extends string & keyof F['generated'],
IDField extends string &
(keyof F['generated'] | keyof F['generatedCompositeKey']),
SoftDeletionEnabled extends boolean
>(opts: {
tableName: string;
Expand Down
10 changes: 9 additions & 1 deletion src/db/util/model-definition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ export type FieldDefinition = {
* such ids that use autoIncrement.
*/
generated?: FieldSet;
/**
* Same as `generated`, but indicates that auto-incremented ID is used as
* part of a composite primary key on the table, thus we need to make it
* possible for client code to specify these IDs when inserting new rows.
*/
generatedCompositeKey?: FieldSet;
nonNullWithDefault?: FieldSet;
optional?: FieldSet;
accidentallyOptional?: FieldSet;
Expand All @@ -68,14 +74,16 @@ export type FieldValuesOfSet<Set extends FieldSet | undefined> =
export type InstanceDataOf<F extends FieldDefinition> = FieldValuesOfSet<
F['generated']
> &
FieldValuesOfSet<F['generatedCompositeKey']> &
FieldValuesOfSet<F['nonNullWithDefault']> &
FieldValuesOfSet<F['required']> &
Nullable<FieldValuesOfSet<F['optional']>> &
Nullable<FieldValuesOfSet<F['accidentallyOptional']>>;

export type UserDataOf<F extends FieldDefinition> = Partial<
FieldValuesOfSet<F['nonNullWithDefault']>
FieldValuesOfSet<F['generatedCompositeKey']>
> &
Partial<FieldValuesOfSet<F['nonNullWithDefault']>> &
FieldValuesOfSet<F['required']> &
FieldValuesOfSet<F['accidentallyOptional']> &
Partial<Nullable<FieldValuesOfSet<F['optional']>>>;

0 comments on commit 843cef5

Please sign in to comment.