SQLite insert schema does not include nullable columns?

Hi, I am just tring out Drizzle with SQLite, but am running into some weird problem. I created a table like this
export const products = sqliteTable(
"products_table",
{
id: int().primaryKey(),
name: text().notNull(),
type: text(),
sku: text(),
externalId: text("external_id").notNull().unique(),
price: text(),
regularPrice: text("regular_price"),
salePrice: text("sale_price"),
manageStock: int("manage_stock", { mode: "boolean" }),
stockQuantity: int("stock_quantity"),
},
(table) => {
return {
nameIdx: index("sku_idx").on(table.sku),
};
}
);
export const products = sqliteTable(
"products_table",
{
id: int().primaryKey(),
name: text().notNull(),
type: text(),
sku: text(),
externalId: text("external_id").notNull().unique(),
price: text(),
regularPrice: text("regular_price"),
salePrice: text("sale_price"),
manageStock: int("manage_stock", { mode: "boolean" }),
stockQuantity: int("stock_quantity"),
},
(table) => {
return {
nameIdx: index("sku_idx").on(table.sku),
};
}
);
Now when I infer the insert schema, or just try to insert data, typescript allways throws an error as it expects this schema:
{
name: string;
sku: string;
price: string;
regularPrice: string;
}
{
name: string;
sku: string;
price: string;
regularPrice: string;
}
It seems like to only includes columns that are not optional (and indexed clumns). This is preventing me from buildung my application as typescript allways throws when I try to insert data into the db. Does someone know why this happens and how to prevent it?
1 Reply
nico
nicoOP4w ago
Seems like this is related to https://github.com/drizzle-team/drizzle-orm/issues/2636 The fix is to add strict:
"compilerOptions": {
"strict": true
},
"compilerOptions": {
"strict": true
},
to your tsconfig
GitHub
[BUG]: type obtained with $inferInsert is empty · Issue #2636 · dri...
What version of drizzle-orm are you using? 0.32.0 What version of drizzle-kit are you using? 0.23.0 Describe the Bug I defined a users table in my drizzle schema, and the NewUser type obtained with...
Want results from more Discord servers?
Add your server