PGeyer
PGeyer
DTDrizzle Team
Created by PGeyer on 5/27/2024 in #help
Casting column to enum type
Hi all, I create a schema like this:
export const typeEnum = taxSchema.enum("type", Object.values(OrderType) as any as [string, ...string[]]);
export const statusEnum = taxSchema.enum("status", Object.values(OrderStatus) as any as [string, ...string[]]);
export const currencyPairEnum = taxSchema.enum(
"currencyPair",
Object.values(CurrencyPair) as any as [string, ...string[]],
);
export const orders = taxSchema.table("orders", {
id: varchar("id").primaryKey(),
type: typeEnum("type"),...
export const typeEnum = taxSchema.enum("type", Object.values(OrderType) as any as [string, ...string[]]);
export const statusEnum = taxSchema.enum("status", Object.values(OrderStatus) as any as [string, ...string[]]);
export const currencyPairEnum = taxSchema.enum(
"currencyPair",
Object.values(CurrencyPair) as any as [string, ...string[]],
);
export const orders = taxSchema.table("orders", {
id: varchar("id").primaryKey(),
type: typeEnum("type"),...
However, when i run
const db = drizzle(new RDSDataClient({}), {
secretArn: process.env.RDS_SECRET_ARN!,
resourceArn: process.env.RDS_CLUSTER_ARN!,
database: 'taxservice'
});
return db.insert(orders).values(data);
const db = drizzle(new RDSDataClient({}), {
secretArn: process.env.RDS_SECRET_ARN!,
resourceArn: process.env.RDS_CLUSTER_ARN!,
database: 'taxservice'
});
return db.insert(orders).values(data);
I get the following error:
Error: ERROR: column "type" is of type type but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 782; SQLState: 42804
Error: ERROR: column "type" is of type type but expression is of type character varying
Hint: You will need to rewrite or cast the expression.
Position: 782; SQLState: 42804
Why is this happening? Shouldn't drizzle manage the casting for me? The value for type being passed in is just a string, but I feel like this should be mapped automatically, correct?
7 replies