Select 条日期范围内的记录使用 Yesod.Persist
Select records in date range using Yesod.Persist
我需要 select table 中的所有记录,其中列日期介于 2 个日期之间、日期之前或日期之后。
我可以看到 selectList
function takes a parameter Filter
这似乎是我需要按日期范围 select 记录的内容,但我无法弄清楚我需要在过滤器参数中放入什么select 按范围或在日期之前和之后。
所以我发现您可以通过添加过滤器来获取日期前后的记录
[TableDateColumn <=. UTCTime]
要获取日期早于现在的记录,您可以使用
getBeforeDate = do
now <- liftIO getCurrentTime
selectList [TableDateColumn <=. Just now] []
我还没有验证这一点,但由于 selectList
需要一个过滤器列表,因此在一个范围内进行选择是有意义的
selectList [TableDateColumn >=. timeStart, TableDateColumn <=. timeEnd] []
我需要 select table 中的所有记录,其中列日期介于 2 个日期之间、日期之前或日期之后。
我可以看到 selectList
function takes a parameter Filter
这似乎是我需要按日期范围 select 记录的内容,但我无法弄清楚我需要在过滤器参数中放入什么select 按范围或在日期之前和之后。
所以我发现您可以通过添加过滤器来获取日期前后的记录
[TableDateColumn <=. UTCTime]
要获取日期早于现在的记录,您可以使用
getBeforeDate = do
now <- liftIO getCurrentTime
selectList [TableDateColumn <=. Just now] []
我还没有验证这一点,但由于 selectList
需要一个过滤器列表,因此在一个范围内进行选择是有意义的
selectList [TableDateColumn >=. timeStart, TableDateColumn <=. timeEnd] []