Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions drizzle-zod/src/column.ts
Original file line number Diff line number Diff line change
Expand Up @@ -119,11 +119,11 @@ export function columnToSchema(
} else if (column.dataType === 'string') {
schema = stringColumnToSchema(column, z, coerce);
} else if (column.dataType === 'json') {
schema = jsonSchema;
schema = z.union([z.union([z.string(), z.number(), z.boolean(), z.null()]), z.record(z.string(), z.any()), z.array(z.any())]);
} else if (column.dataType === 'custom') {
schema = z.any();
} else if (column.dataType === 'buffer') {
schema = bufferSchema;
schema = z.custom<Buffer>((v) => v instanceof Buffer);
}
}

Expand Down
8 changes: 4 additions & 4 deletions drizzle-zod/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@ function handleColumns(
refinements: Record<string, any>,
conditions: Conditions,
factory?: CreateSchemaFactoryOptions<
Partial<Record<'bigint' | 'boolean' | 'date' | 'number' | 'string', true>> | true | undefined
Partial<Record<'bigint' | 'boolean' | 'date' | 'number' | 'string', true>> | true | undefined
>,
): z.ZodType {
const columnSchemas: Record<string, z.ZodType> = {};
const zod: typeof z = factory?.zodInstance ?? z;

for (const [key, selected] of Object.entries(columns)) {
if (!is(selected, Column) && !is(selected, SQL) && !is(selected, SQL.Aliased) && typeof selected === 'object') {
Expand All @@ -40,7 +41,7 @@ function handleColumns(
}

const column = is(selected, Column) ? selected : undefined;
const schema = column ? columnToSchema(column, factory) : z.any();
const schema = column ? columnToSchema(column, factory) : zod.any();
const refined = typeof refinement === 'function' ? refinement(schema) : schema;

if (conditions.never(column)) {
Expand All @@ -59,8 +60,7 @@ function handleColumns(
}
}
}

return z.object(columnSchemas) as any;
return zod.object(columnSchemas) as any;
}

function handleEnum(
Expand Down