Why doesn't the following work? I kinda know that there's a lot going under the hood and the User
type probably doesn't really have the email
, createdAt
, and updatedAt
field. What's the best way to NOT instantiate objects using positional parameters, which can easily go out of hand?
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}
Compilation errors:
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’
The function names would be like: userEmail
, userCreatedAt
, userUpdatedAt
.
Running cabal REPL and browsing the project help identify Yesod generated functions for persistent types.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With