4

是否可以写

select min(next) from participant;

作为esqueleto查询?

更新

我发现了这个min_功能。然而,代码

nextMessageTime =
  from $ \p -> min_ (p ^. ParticipantNext)

显然有一些模棱两可的类型:

Could not deduce (Database.Esqueleto.Internal.Language.From
                    query expr backend (query (Entity (ParticipantGeneric backend0))))
  arising from the ambiguity check for ‘nextMessageTime’
from the context (Database.Esqueleto.Internal.Language.From
                    query expr backend (query (Entity (ParticipantGeneric backend2))),
                  Esqueleto query1 query backend1)
  bound by the inferred type for ‘nextMessageTime’:
             (Database.Esqueleto.Internal.Language.From
                query expr backend (query (Entity (ParticipantGeneric backend2))),
              Esqueleto query1 query backend1) =>
             query (Value (Maybe Int64))
  at Presta/DB/Queries.hs:(15,1)-(16,42)
The type variable ‘backend0’ is ambiguous
When checking that ‘nextMessageTime’
  has the inferred type ‘forall (query :: * -> *)
                                (expr :: * -> *)
                                backend
                                (query1 :: * -> *)
                                backend1
                                backend2.
                         (Database.Esqueleto.Internal.Language.From
                            query expr backend (query (Entity (ParticipantGeneric backend2))),
                          Esqueleto query1 query backend1) =>
                         query (Value (Maybe Int64))’
Probable cause: the inferred type is ambiguous
4

1 回答 1

2

我设法使用持久性使这项工作rawSql

nextMessageTime = do
  [Single t] <-
    rawSql
      "SELECT min(next) FROM participant"
      []
  return (t :: Int64)

(但如果您要复制此代码,请注意不详尽的模式。)

于 2014-06-24T18:48:31.997 回答