看看:
myEntity :: Entity Post
myEntity = ...
myValue :: Entity Post -> Post
myValue = <someFunction>
myKey :: Entity Post -> PostId
myKey = <someOtherFunction>
yesod中是否存在someFunction
和someOtherFunction
,还是需要创建它们?
答案 0 :(得分:5)
您有Entity key val
,然后是val
> :t entityVal
entityVal :: Entity record -> record
> :i entityVal
type role Entity nominal
data Entity record where
Entity :: PersistEntity record =>
(Key record) -> record -> Entity record
-- Defined in ‘persistent-2.2.1:Database.Persist.Class.PersistEntity’
或key
> :t entityKey
entityKey :: Entity record -> Key record
> :i entityKey
type role Entity nominal
data Entity record where
Entity :: PersistEntity record =>
(Key record) -> record -> Entity record
-- Defined in ‘persistent-2.2.1:Database.Persist.Class.PersistEntity’
或两者都可以使用模式匹配,例如
> let getR (Entity k v) = (k , v)
> :t getR
getR :: Entity t -> (Key t, t)