Guilherme Rosado
Guilherme Rosado
Explore posts from servers
DTDrizzle Team
Created by Guilherme Rosado on 9/15/2023 in #help
[HELP]: I'm trying to re-create a CTE-insert in drizzle, having some difficulties
with cart_products as (
select * from cart_product where cart_id = ${cartId}
)
insert into order_product (order_id, cart_product_id)
select ${orderId}, id from cart_products
returning
id,
order_id as "orderId",
cart_product_id as "cartProductId";
with cart_products as (
select * from cart_product where cart_id = ${cartId}
)
insert into order_product (order_id, cart_product_id)
select ${orderId}, id from cart_products
returning
id,
order_id as "orderId",
cart_product_id as "cartProductId";
How does the query above translate to drizzle? I think more examples that translates to the above would be awesome in the docs, I've been fighting a bit with the API. I know from the start how to do it on sql, but sometimes it gets really hard translating to drizzle. I feel this could be solved with more examples, maybe?
114 replies
DTDrizzle Team
Created by Guilherme Rosado on 8/28/2023 in #help
Bug on custom type inference? Maybe I'm doing something wrong.
export const timez = customType<
{
data: Date;
driverData: string;
config: { precision?: number };
}
>({
dataType(config) {
const precision = typeof config?.precision !== 'undefined'
? ` (${config.precision})`
: '';
return `time${precision} with time zone`;
},
fromDriver(value: string): Date {
return new Date(value);
},
});
export const timez = customType<
{
data: Date;
driverData: string;
config: { precision?: number };
}
>({
dataType(config) {
const precision = typeof config?.precision !== 'undefined'
? ` (${config.precision})`
: '';
return `time${precision} with time zone`;
},
fromDriver(value: string): Date {
return new Date(value);
},
});
Then if I:
endTime: timez("end_time"),

// I get from inference

type Type = {
endTime?: any;
}
endTime: timez("end_time"),

// I get from inference

type Type = {
endTime?: any;
}
The type on endTime should be Date not any I'm using drizzle-orm 0.28.5
14 replies