alevy / postgresql-orm

An Haskell ORM (Object Relational Mapping) and migrations DSL for PostgreSQL.
http://simple.cx
GNU General Public License v3.0
78 stars 12 forks source link

Discussion | Move NullKey into the type signature #22

Open charles-cooper opened 7 years ago

charles-cooper commented 7 years ago

Instead of having to do runtime checks to see if a Model has been saved, one could infer it from the type signature.

newtype NullKey = NullKey
newtype DBKey = DBKey Int64

data MyModel key = MyModel { pkey :: key, myData :: String }

insert :: Model model => Connection -> model NullKey -> IO (model DBKey)

update :: Model model => Connection -> model DBKey -> IO (model DBKey)

saveAndThenUpdate :: MyModel NullKey -> String -> MyModel DBKey
saveAndThenUpdate x string = do
  -- pseudocode
  ret <- insert conn myModel
  ret <- return $ ret { myData = string }
  ret <- update conn ret
  return ret 

What do you think?

saurabhnanda commented 6 years ago

My vote for this, because I've been conditioned by ORM to accept polymorphic records. But, as a newbie, I hated them.