How to make a text based timestamp type for sqlite with zod schema inference

Jjohtso3/31/2024
When I use the built in integer with mode timestamp, the generated zod schemas correctly declare that inserts take a Date and selects produce a Date. When I try and write a custom type like this:
const timestamp = customType<
{ data: Date; driverData: string; }
>({
dataType() {
return 'text';
},
fromDriver(value: string): Date {
return new Date(value);
},
toDriver(value: Date): string {
return value.toISOString();
},
});
const timestamp = customType<
{ data: Date; driverData: string; }
>({
dataType() {
return 'text';
},
fromDriver(value: string): Date {
return new Date(value);
},
toDriver(value: Date): string {
return value.toISOString();
},
});
The zod schema looks like this:
myIntegerDateColumn: ZodDate;
myTextDateColumn: ZodAny;
myIntegerDateColumn: ZodDate;
myTextDateColumn: ZodAny;

Looking for more? Join the community!