Skip to content

Commit

Permalink
fix: nullable fields are optional when inserting
Browse files Browse the repository at this point in the history
Fixes: #20
  • Loading branch information
rintaun committed Nov 30, 2020
1 parent 4684631 commit fba3e1c
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/generator/__tests__/__snapshots__/Generator.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ export interface TableWithNullableFields {
nullable_array_with_default: string[] | null;
}
export interface TableWithNullableFields$Insert {
nullable: string | null;
nullable?: string | null;
nullable_with_default?: string | null;
nullable_array: string[] | null;
nullable_array?: string[] | null;
nullable_array_with_default?: string[] | null;
}
export const TableWithNullableFields$Types: Record<keyof TableWithNullableFields, string> = {
Expand Down Expand Up @@ -122,9 +122,9 @@ export interface TableWithNullableFields {
nullableArrayWithDefault: string[] | null;
}
export interface TableWithNullableFields$Insert {
nullable: string | null;
nullable?: string | null;
nullableWithDefault?: string | null;
nullableArray: string[] | null;
nullableArray?: string[] | null;
nullableArrayWithDefault?: string[] | null;
}
export const TableWithNullableFields$Types: Record<keyof TableWithNullableFields, string> = {
Expand Down Expand Up @@ -161,9 +161,9 @@ export interface TableWithUuidId$Insert {
id?: string;
}
export interface TableWithNullableFields$Insert {
nullable: string | null;
nullable?: string | null;
nullable_with_default?: string | null;
nullable_array: string[] | null;
nullable_array?: string[] | null;
nullable_array_with_default?: string[] | null;
}
"
Expand Down
2 changes: 1 addition & 1 deletion src/generator/builders/InsertTypeBuilder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export default class InsertTypeBuilder extends TableBuilder {
const builder = new ColumnBuilder(columnInfo, this.types, this.transform)
let signature = builder.buildNode()

if (columnInfo.hasDefault) {
if (columnInfo.hasDefault || columnInfo.nullable) {
signature = factory.updatePropertySignature(
signature,
signature.modifiers,
Expand Down

0 comments on commit fba3e1c

Please sign in to comment.