How to narrow type in select from enum?

During select I need to narrow enum type from multiple choices to one choice eg just 'product' schema
export const typAsortymentuEnum = pgEnum('typ_asortymentu', ['produkt', 'usluga']);
export const asortyment = pgTable('asortyment', {
id: serial('id').primaryKey().notNull(),
typ: typAsortymentuEnum('typ').notNull(),

})
export const typAsortymentuEnum = pgEnum('typ_asortymentu', ['produkt', 'usluga']);
export const asortyment = pgTable('asortyment', {
id: serial('id').primaryKey().notNull(),
typ: typAsortymentuEnum('typ').notNull(),

})
query
const produkt = alias(asortyment, "produkt")
const results = await db
.select({
id: produkt.id,
typ: produkt.typ,
})
.from(produkt)
.where(eq(produkt.typ, 'produkt'))
.execute()
const produkt = alias(asortyment, "produkt")
const results = await db
.select({
id: produkt.id,
typ: produkt.typ,
})
.from(produkt)
.where(eq(produkt.typ, 'produkt'))
.execute()
result typ value is typed as typ: "produkt" | "usluga"; and I need to narrow it to just product I would be glad for any tip how to accomplish this. Thanks!
1 Reply
tzezar
tzezarOP5mo ago
My attempt was to use sql operator like this:
typ: sql<'produkt'>`${produkt.typ}`,
typ: sql<'produkt'>`${produkt.typ}`,
but I believe there might be better solution
Want results from more Discord servers?
Add your server