Skip to content

.and() issue #1681

Answered by dfahlander
TheMenethil asked this question in Q&A
Mar 4, 2023 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

The doc page is indeed not very expressive.

The filter argument should be a callback that takes a database object (value) and returns true or false. Here's an example that might clarify the same intent as your snippet:

async function search() {
    var count = await db.items.where("isDone").equals("N").count();

    var rand = Math.floor(Math.random() * count);

    var result = await db.items
      .where("isDone").equals("N")
      .and(item => item.id === rand) // callback is plain function returning boolean
      .toArray(); // still need to do .toArray() at end

    return result;
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@TheMenethil
Comment options

@dfahlander
Comment options

Answer selected by dfahlander
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