DT
Join ServerDrizzle Team
help
Option filter parameters
Hi! Love using drizzle so far! Had a quick question (not a bug):
If I have a query like this, and
which is fine, just wondering if this is a good approach. thanks!
const res = await ctx.database
.select()
.from(worker)
.where(
and(
eq(worker.locationUid, input.location),
isNull(worker.deletedAt),
ilike(worker.name, "%{input.name}%")
)
)
If I have a query like this, and
input.name
might be null
(in which case I want to skip filtering by this), is there a short-hand for enabling that behavior? Right now I'm putting filters into an array like: [..., input.name && ilike(worker.name, "%{input.name}%) : null].filter(v => v)
which is fine, just wondering if this is a good approach. thanks!
Hi!
here you go
just small example I did for another thread
but should work well for you
we will also add this case to docs
will work on examples section for different cases like this one
all you need from this examples is that filter statements can be grouped in array
and then used like this
.where(and(...filters))
great thanks, looks good