为什么以下不起作用?我知道有很多内容,User
类型可能没有真正的email
,createdAt
和updatedAt
字段。什么是不使用位置参数实例化对象的最佳方法,这很容易失控?
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
User
email String
createdAt UTCTime Maybe default=CURRENT_TIME
updatedAt UTCTime Maybe default=CURRENT_TIME
deriving Show
]]
main :: IO ()
main = runSqlite ":memory:" $ do
runMigration migrateAll
u <- insert $ User {email="saurabhnanda@gmail.com" createdAt=Nothing updatedAt=Nothing}
编译错误:
trysql.hs:38:23:
‘email’ is not a (visible) field of constructor ‘User’
trysql.hs:38:55:
‘createdAt’ is not a (visible) field of constructor ‘User’
trysql.hs:38:74:
‘updatedAt’ is not a (visible) field of constructor ‘User’
答案 0 :(得分:6)
函数名称如下:userEmail
,userCreatedAt
,userUpdatedAt
。
运行cabal REPL并浏览项目有助于识别Yesod为持久类型生成的函数。