【发布时间】:2016-05-15 16:09:09
【问题描述】:
为什么以下操作不起作用?我有点知道引擎盖下有很多东西,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’
【问题讨论】: