johtso
johtso
Explore posts from servers
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
I'm not really using effect schema with drizzle. I think I'm just not using the zod schema at all, instead just explicitly passing the relevant key/values as the values argument in my query..
14 replies
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
ahh.. I think it's exactOptionalPropertyTypes in tsconfig
14 replies
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
Types of property 'membershipEndDate' are incompatible.
Type 'Date | null | undefined' is not assignable to type 'Date | SQL<unknown> | Placeholder<string, any> | null'.
Type 'undefined' is not assignable to type 'Date | SQL<unknown> | Placeholder<string, any> | null'.
Types of property 'membershipEndDate' are incompatible.
Type 'Date | null | undefined' is not assignable to type 'Date | SQL<unknown> | Placeholder<string, any> | null'.
Type 'undefined' is not assignable to type 'Date | SQL<unknown> | Placeholder<string, any> | null'.
14 replies
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
export const createEmail = async (
db: dbType,
email: InsertEmail
): Promise<boolean> => {
const result = await db
.insert(emails)
.values(email)
return result.results.length > 0;
}
export const createEmail = async (
db: dbType,
email: InsertEmail
): Promise<boolean> => {
const result = await db
.insert(emails)
.values(email)
return result.results.length > 0;
}
14 replies
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
export const insertEmailSchema = createInsertSchema(emails, {
timeSent: z.date(),
membershipEndDate: z.date(),
}).strict();
export type InsertEmail = z.infer<typeof insertEmailSchema>;
export const insertEmailSchema = createInsertSchema(emails, {
timeSent: z.date(),
membershipEndDate: z.date(),
}).strict();
export type InsertEmail = z.infer<typeof insertEmailSchema>;
14 replies
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
export const emails = sqliteTable('emails', {
idempotencyKey: text('idempotency_key').primaryKey(),
membershipEndDate: date('membership_end_date')
});
export const emails = sqliteTable('emails', {
idempotencyKey: text('idempotency_key').primaryKey(),
membershipEndDate: date('membership_end_date')
});
14 replies
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
const date = customType<
{ data: Date; driverData: string; }
>({
dataType() {
return 'text';
},
fromDriver(value: string): Date {
return new Date(value);
},
toDriver(value: Date): string {
if (value.getHours() !== 0 || value.getMinutes() !== 0 || value.getSeconds() !== 0 || value.getMilliseconds() !== 0) {
throw new Error('Date must have a time of 00:00:00.000');
}
try {
return value.toISOString().split('T')[0] as string;
} catch (e) {
console.log(`failed to covert ${JSON.stringify(value)} to iso string`)
throw e;
}
},
});
const date = customType<
{ data: Date; driverData: string; }
>({
dataType() {
return 'text';
},
fromDriver(value: string): Date {
return new Date(value);
},
toDriver(value: Date): string {
if (value.getHours() !== 0 || value.getMinutes() !== 0 || value.getSeconds() !== 0 || value.getMilliseconds() !== 0) {
throw new Error('Date must have a time of 00:00:00.000');
}
try {
return value.toISOString().split('T')[0] as string;
} catch (e) {
console.log(`failed to covert ${JSON.stringify(value)} to iso string`)
throw e;
}
},
});
14 replies
DTDrizzle Team
Created by Simon on 6/11/2024 in #help
Drizzle with Zod throws type errors with simple `numeric` example
@Simon did you find a solution? I'm having the same problem with a custom Date datatype
14 replies
DTDrizzle Team
Created by johtso on 3/31/2024 in #help
How do I access config in fromDriver and toDriver when defining a custom type using customType?
Yeah, should be able to switch to that.. although Date is kind of dodgy on cloudflare workers
11 replies
DTDrizzle Team
Created by johtso on 3/31/2024 in #help
How do I access config in fromDriver and toDriver when defining a custom type using customType?
ends up being given something like this instead of a Date, I guess the sql query for the default value:
{\"decoder\":{},\"shouldInlineParams\":false,\"queryChunks\":[{\"value\":[\"(CURRENT_TIMESTAMP)\"]}]}
{\"decoder\":{},\"shouldInlineParams\":false,\"queryChunks\":[{\"value\":[\"(CURRENT_TIMESTAMP)\"]}]}
11 replies
DTDrizzle Team
Created by johtso on 3/31/2024 in #help
How do I access config in fromDriver and toDriver when defining a custom type using customType?
hmm.. this doesn't work when you have a column like this:
timestamp('last_updated').default(sql`(CURRENT_TIMESTAMP)`).$onUpdate(() => sql`(CURRENT_TIMESTAMP)`).notNull(),
timestamp('last_updated').default(sql`(CURRENT_TIMESTAMP)`).$onUpdate(() => sql`(CURRENT_TIMESTAMP)`).notNull(),
11 replies
DTDrizzle Team
Created by johtso on 3/31/2024 in #help
How do I access config in fromDriver and toDriver when defining a custom type using customType?
Yep, but was going to generate a date or a datetime string based on config
11 replies
DTDrizzle Team
Created by johtso on 3/31/2024 in #help
How do I access config in fromDriver and toDriver when defining a custom type using customType?
I was hoping to do something like this, except for a custom type that would store the time as an ISO string https://github.com/drizzle-team/drizzle-orm/blob/0ddab656ed99f80f7ca2a6f02e96d739f20ccf8b/drizzle-orm/src/sqlite-core/columns/integer.ts#L142-L155
11 replies