4
爲什麼以下不工作?我知道有很多事情在引擎蓋下,User
類型可能並不具有email
,createdAt
和updatedAt
字段。不使用位置參數來實例化對象的最好方法是什麼,這很容易失控?如何在Yesod-Persistent中使用記錄語法
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="[email protected]" 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’