Skip to content

How can I do an optional where clause in building the query? #1940

Answered by dfahlander
laukaichung asked this question in Q&A
Discussion options

You must be logged in to vote
const collection = value
  ? table.where('value').equals(value)
  : table.toCollection();

return collection
    .offset(getOffset(page, itemsPerPage))
    .limit(itemsPerPage)
    .reverse()
    .toArray();

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by laukaichung
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants