Type error when using `drizzle-zod` with sqlite table schema

I'm trying to do this:
const a = createSelectSchema(schema.deckInfo)
const a = createSelectSchema(schema.deckInfo)
My table is:
export const deckInfo = sqliteTable(
'deck_info',
{
id: integer().primaryKey(),
deckId: text().notNull(),
name: text().notNull(),
description: text(),
ownerUserId: text().notNull(),
color: integer().notNull(),
createdAt: integer({ mode: 'timestamp' }).notNull(),
updatedAt: integer({ mode: 'timestamp' }).notNull(),
aiAssisted: integer({ mode: 'boolean' }).notNull().default(false) // Whether AI was used at any point in making the deck
},
(table) => [check('singleton', sql`${table.id} = 1`)]
)
export const deckInfo = sqliteTable(
'deck_info',
{
id: integer().primaryKey(),
deckId: text().notNull(),
name: text().notNull(),
description: text(),
ownerUserId: text().notNull(),
color: integer().notNull(),
createdAt: integer({ mode: 'timestamp' }).notNull(),
updatedAt: integer({ mode: 'timestamp' }).notNull(),
aiAssisted: integer({ mode: 'boolean' }).notNull().default(false) // Whether AI was used at any point in making the deck
},
(table) => [check('singleton', sql`${table.id} = 1`)]
)
I get a type error on my input to createSelectSchema.
No overload matches this call.
The last overload gave the following error.
Argument of type 'SQLiteTableWithColumns<{ name: "deck_info"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "deck_info"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 7 more ...; aiAssisted: SQLiteColum...' is not assignable to parameter of type 'PgEnum<any>'.
Type 'SQLiteTable<{ name: "deck_info"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "deck_info"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 7 more ...; aiAssisted: SQLiteColumn<...>; }; ...' is missing the following properties from type 'PgEnum<any>': enumName, enumValues, schemats(2769)
No overload matches this call.
The last overload gave the following error.
Argument of type 'SQLiteTableWithColumns<{ name: "deck_info"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "deck_info"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 7 more ...; aiAssisted: SQLiteColum...' is not assignable to parameter of type 'PgEnum<any>'.
Type 'SQLiteTable<{ name: "deck_info"; schema: undefined; columns: { id: SQLiteColumn<{ name: "id"; tableName: "deck_info"; dataType: "number"; columnType: "SQLiteInteger"; data: number; driverParam: number; notNull: true; ... 7 more ...; generated: undefined; }, {}, {}>; ... 7 more ...; aiAssisted: SQLiteColumn<...>; }; ...' is missing the following properties from type 'PgEnum<any>': enumName, enumValues, schemats(2769)
Is drizzle-zod Postgres only or something?
4 Replies
KirbyTwister
KirbyTwister5mo ago
what's your Zod and drizzle-zod versions? @Shroom
Queen Elizabeth II
Queen Elizabeth IIOP5mo ago
all latest okay hmm so i decided to try using it in a schema anyway
Queen Elizabeth II
Queen Elizabeth IIOP5mo ago
No description
Queen Elizabeth II
Queen Elizabeth IIOP5mo ago
it works with one table. not with another the card one (the one that works) is this:
export const card = sqliteTable(
'card',
{
id: text()
.primaryKey()
.$default(() => crypto.randomUUID()),
text: text().notNull().default(''),
specialFeatures: integer().notNull().default(0),
aiAssisted: integer({ mode: 'boolean' }).notNull().default(false),
orderingId: text().notNull(),
introducingVersionId: integer()
.notNull()
.references(() => version.id),
previousId: text(),
deletedInVersion: integer().references(() => version.id)
},
(table) => [
index('card_textIndex').on(table.text),
index('card_deletedInVersionIndex').on(table.deletedInVersion),
index('card_orderingId+introducingVersion+deletedInVersionIndex').on(
table.orderingId,
table.introducingVersionId,
table.deletedInVersion
),
index('card_introducingVersion+deletedInVersionIndex').on(
table.introducingVersionId,
table.deletedInVersion
)
]
)
export const card = sqliteTable(
'card',
{
id: text()
.primaryKey()
.$default(() => crypto.randomUUID()),
text: text().notNull().default(''),
specialFeatures: integer().notNull().default(0),
aiAssisted: integer({ mode: 'boolean' }).notNull().default(false),
orderingId: text().notNull(),
introducingVersionId: integer()
.notNull()
.references(() => version.id),
previousId: text(),
deletedInVersion: integer().references(() => version.id)
},
(table) => [
index('card_textIndex').on(table.text),
index('card_deletedInVersionIndex').on(table.deletedInVersion),
index('card_orderingId+introducingVersion+deletedInVersionIndex').on(
table.orderingId,
table.introducingVersionId,
table.deletedInVersion
),
index('card_introducingVersion+deletedInVersionIndex').on(
table.introducingVersionId,
table.deletedInVersion
)
]
)
done further digging. it was the wrong card schema in that example lmao, so that's why it didn't show the error if i pull my entire schema into the file where i use the zod schema (which is in a different workspace), it's fine but in my worker (where my schema is currently defined, because it's used in a DO) it doesn't work. just moving the definitions to a different workspace leads to totally different results Okay I've kind of figured out Don't know the exact cause still But I had a bit of a mess with all my node_modules. I removed all of them (from all my workspaces), typed bun i, and then it worked and there were now no type issues Presumably some of them had like old versions of drizzle-orm that caused these issues?

Did you find this page helpful?