Use "with" in select()

So my problem is something like this
// schema
const subcategories = pgTable(
'Subcategory',
{
name: text('name').notNull().unique(),
id: bigserial('id', { mode: 'number' }).primaryKey(),
category: integer('category').notNull(),
}
);

const products = pgTable(
'Product',
{
// Columns
subcategory: integer('subcategory').notNull()
}
)

const productsRelations = relations(products, ({ one, many }) => ({
subcategory: one(subcategories, {
fields: [products.subcategory],
references: [subcategories.id],
}),
}));


// I want to use the "with" that is available in the query API but with select()
const productList = await drizzle.select({
with: {subcategory: true},
})
.from(products)
// schema
const subcategories = pgTable(
'Subcategory',
{
name: text('name').notNull().unique(),
id: bigserial('id', { mode: 'number' }).primaryKey(),
category: integer('category').notNull(),
}
);

const products = pgTable(
'Product',
{
// Columns
subcategory: integer('subcategory').notNull()
}
)

const productsRelations = relations(products, ({ one, many }) => ({
subcategory: one(subcategories, {
fields: [products.subcategory],
references: [subcategories.id],
}),
}));


// I want to use the "with" that is available in the query API but with select()
const productList = await drizzle.select({
with: {subcategory: true},
})
.from(products)
I want to do something like this because I need to do subquerys and I don't find a way to do subquerys with the query API.
0 Replies
No replies yetBe the first to reply to this messageJoin