Open jakeleventhal opened 1 week ago
You can refer to the examples given in the official documentation。 Compose a WHERE statement and then use it in a query
async function getProductsBy({
name,
category,
maxPrice,
}: {
name?: string;
category?: string;
maxPrice?: string;
}) {
const filters: SQL[] = [];
if (name) filters.push(ilike(products.name, name));
if (category) filters.push(eq(products.category, category));
if (maxPrice) filters.push(lte(products.price, maxPrice));
return db
.select()
.from(products)
.where(and(...filters));
}
You can refer to the examples given in the official documentation。 Compose a WHERE statement and then use it in a query
async function getProductsBy({ name, category, maxPrice, }: { name?: string; category?: string; maxPrice?: string; }) { const filters: SQL[] = []; if (name) filters.push(ilike(products.name, name)); if (category) filters.push(eq(products.category, category)); if (maxPrice) filters.push(lte(products.price, maxPrice)); return db .select() .from(products) .where(and(...filters)); }
This completely disregards the original post. My issue in relation to the .if
API.
Report hasn't been filed before.
What version of
drizzle-orm
are you using?0.27.0
What version of
drizzle-kit
are you using?0.36.0
Other packages
No response
Describe the Bug
Suppose my route has an optional parameter
minDate
and I want to have a query like:This code does not work since minDate is sometimes undefined. This forces me to add
!
in thegte
function. This seems like a bad pattern.