Select list from list of IDs using persistent

706 Views Asked by At

In my application I need to be able to write a query that takes a list of IDs and returns a list of each of those records.

From what I can tell from the yesod persistent page I could do something like

selectList (UserId ==. 1 ||. UserId ==. 2 ||. UserId ==. 3) []

Which I believe would return a list containing user 1, 2 and 3 but I can't work out how I would write this query when I don't know the list or how long it will be at compile time.

How would I go about selecting a list of records using a list of IDs in Haskell persistent.

1

There are 1 best solutions below

3
On

Persistent has several combinators for creating queries the one you are looking for is (<-.) :: PersistField typ => EntityField v typ -> [typ] -> Filter v.

Then your query can be simplified to

selectList [UserId <-. [1..3]] []