How to use recording syntax with Yesod-Persistent

Why does the following not work? I know for sure that a lot is under the hood, and the type Userprobably has no margins email, createdAtand updatedAt. What is the best way to NOT create objects using positional parameters that can easily get 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="saurabhnanda@gmail.com" 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’
+4
source share
1 answer

Function names will be: userEmail, userCreatedAt, userUpdatedAt.

Running CRAL CRPL code and viewing a project helps identify functions created with Yesod for constant types.

+5
source

Source: https://habr.com/ru/post/1627466/


All Articles