haskell - How to omit fields that will be filled in by the database -


i've started off persistent yesod , have hit first roadblock.

share [mkpersist sqlsettings, mkmigrate "migrateall"] [persistlowercase| user   email string   createdat utctime maybe default=current_time   updatedat utctime maybe default=current_time   deriving show |]  u <- insert $ user "saurabhnanda@gmail.com" nothing nothing 

i'm coming rails background , schema design conventions advocated them. in particular case, having every table have created_at , updated_at timestamp. however, there way not specify createdat , updatedat fields every object created?

i don't know persistent, usual technique kind of thing define parameterized types. example, might write

data dated = dated     { created :: utctime     , updated :: utctime     , value ::     } 

then bare values need not worry metadata, , metadata can handled uniformly across different types. e.g. might expose api this:

new :: -> io (dated a) new =     <- getutctime     return (dated a)  update :: dated -> -> io (dated a) update old new =     <- getutctime     return (old { updated = now, value = new }) 

then suggest exporting dated type constructor , fields, new , update, not exporting dated data constructor. ensure created , updated fields maintained correctly.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -