CrashChicken
CrashChicken
DTDrizzle Team
Created by CrashChicken on 8/13/2024 in #help
Using default values removes columns from insert and update types
export const testSchema = pgTable('test_table', {
defaultValue: integer('default_value').notNull().default(1),
nonDefaultValue: integer('non_default_value').notNull(),
});

db.insert(testSchema).values({
defaultValue: 2, // this errors
nonDefaultValue: 1,
});
export const testSchema = pgTable('test_table', {
defaultValue: integer('default_value').notNull().default(1),
nonDefaultValue: integer('non_default_value').notNull(),
});

db.insert(testSchema).values({
defaultValue: 2, // this errors
nonDefaultValue: 1,
});
Using the above schema makes the following error when I try to override the defaultValue with 2.
No overload matches this call.
Overload 1 of 2, '(value: { nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }): PgInsertBase<PgTableWithColumns<{ name: "test_table"; schema: undefined; columns: { defaultValue: PgColumn<{ name: "default_value"; ... 12 more ...; generated: GeneratedColumnConfig<...>; }, {}, {}>; nonDefaultValue: PgColumn<...>; }; dialect: "pg"; }>, NodePgQueryResultHKT, undefined, false, never>', gave the following error.
Object literal may only specify known properties, but 'defaultValue' does not exist in type '{ nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }'. Did you mean to write 'nonDefaultValue'?
Overload 2 of 2, '(values: { nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }[]): PgInsertBase<PgTableWithColumns<{ name: "test_table"; schema: undefined; columns: { defaultValue: PgColumn<{ name: "default_value"; ... 12 more ...; generated: GeneratedColumnConfig<...>; }, {}, {}>; nonDefaultValue: PgColumn<...>; }; dialect: "pg"; }>, NodePgQueryResultHKT, undefined, false, never>', gave the following error.
Object literal may only specify known properties, and 'defaultValue' does not exist in type '{ nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }[]'.
No overload matches this call.
Overload 1 of 2, '(value: { nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }): PgInsertBase<PgTableWithColumns<{ name: "test_table"; schema: undefined; columns: { defaultValue: PgColumn<{ name: "default_value"; ... 12 more ...; generated: GeneratedColumnConfig<...>; }, {}, {}>; nonDefaultValue: PgColumn<...>; }; dialect: "pg"; }>, NodePgQueryResultHKT, undefined, false, never>', gave the following error.
Object literal may only specify known properties, but 'defaultValue' does not exist in type '{ nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }'. Did you mean to write 'nonDefaultValue'?
Overload 2 of 2, '(values: { nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }[]): PgInsertBase<PgTableWithColumns<{ name: "test_table"; schema: undefined; columns: { defaultValue: PgColumn<{ name: "default_value"; ... 12 more ...; generated: GeneratedColumnConfig<...>; }, {}, {}>; nonDefaultValue: PgColumn<...>; }; dialect: "pg"; }>, NodePgQueryResultHKT, undefined, false, never>', gave the following error.
Object literal may only specify known properties, and 'defaultValue' does not exist in type '{ nonDefaultValue: number | SQL<unknown> | Placeholder<string, any>; }[]'.
And if I remove the notNull on the nonDefaultValue I get no intelisense at all. I can input any object and typescript shows no errors.
db.insert(testSchema).values({
defaultValue: 2,
nonDefaultValue: 1,
blabla: 'blabla', // no ts errors
});
db.insert(testSchema).values({
defaultValue: 2,
nonDefaultValue: 1,
blabla: 'blabla', // no ts errors
});
I hope you can help me. Thanks in advance!
14 replies