Using drizzle-zod with superforms

I am working on a SvelteKit app where i use Drizzle (0.30.2), drizzle-zod (0.8.2) and Svelte superforms (2.27.1) This is my drizzle SQLite schema:
export const dataset = sqliteTable('dataset', {
id: integer('id').primaryKey(),
name: text('name'),
columnClasses: text('column_classes'),
data: text('data'),
createdAt: integer('created_at', { mode: "timestamp_ms" }).notNull().default(sql`(CURRENT_TIMESTAMP)`),
updatedAt: integer('updated_at', { mode: "timestamp_ms" }).notNull().default(sql`(CURRENT_TIMESTAMP)`)
});
export const dataset = sqliteTable('dataset', {
id: integer('id').primaryKey(),
name: text('name'),
columnClasses: text('column_classes'),
data: text('data'),
createdAt: integer('created_at', { mode: "timestamp_ms" }).notNull().default(sql`(CURRENT_TIMESTAMP)`),
updatedAt: integer('updated_at', { mode: "timestamp_ms" }).notNull().default(sql`(CURRENT_TIMESTAMP)`)
});
And i try to create a zod schema with
import { createSelectSchema } from 'drizzle-zod';
...
export const datasetZodSchema = createSelectSchema(dataset);
import { createSelectSchema } from 'drizzle-zod';
...
export const datasetZodSchema = createSelectSchema(dataset);
When i import this into a different file, and try to use it with
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { datasetZodSchema } from '$lib/server/db/schema/dataset.js';
...
form: await superValidate(zod(datasetZodSchema)),
import { superValidate } from 'sveltekit-superforms';
import { zod } from 'sveltekit-superforms/adapters';
import { datasetZodSchema } from '$lib/server/db/schema/dataset.js';
...
form: await superValidate(zod(datasetZodSchema)),
I get the error:
Argument of type 'BuildSchema<"select", { id: SQLiteColumn<{ name: "id"; tableName:...'

is not assignable to parameter of type 'ZodObjectType'.
Argument of type 'BuildSchema<"select", { id: SQLiteColumn<{ name: "id"; tableName:...'

is not assignable to parameter of type 'ZodObjectType'.
What am i doing wrong here? All the examples i am finding use it like this.
1 Reply
Tobias
Tobias4w ago
I think that drizzle-zod might be using zod4. If that is the case you need to use the zo4 adapter instead. import { zod4 } from 'sveltekit-superforms/adapters'; await superValidate(zod4(datasetZodSchema)), And the same for client validation if you are using that import { zod4Client } from 'sveltekit-superforms/adapters';

Did you find this page helpful?