Closed raryanpur closed 3 weeks ago
Thanks @raryanpur 👋
You are correct that this fully supported behavior! The cool thing about using where
is that the string returned from that query is actually the string that gets used in the FilterExpression
. This is intentional so folks can have even more control over how their filter expressions are written. You could even do something like this:
const { data } = await entity.query
.byIndex({ entityId: id })
.where((a, { value }) =>
someValue == null
? ""
: `somevalue = ${value(a.someValue, someValue)}`,
)
.go()
Great, thanks @tywalch !
Thanks again for building and supporting ElectroDB - it's awesome!
Is there a supported way to write conditional where operations? Currently, I just have the where operation return an empty string if the filter expression shouldn't be applied. e.g.
This works in practice (and is particularly helpful when using Electro to query in response to a
GET
request with optional query string parameters [e.g.my.rest.api/entity/<id>?someValue=x
]), and the source forwhere
looks like this is explicitly supported and not unhandled behavior, but wanted to confirm to be sure.