postgresql-orm icon indicating copy to clipboard operation
postgresql-orm copied to clipboard

Discussion | Move NullKey into the type signature

Open charles-cooper opened this issue 8 years ago • 1 comments

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?

charles-cooper avatar May 11 '17 16:05 charles-cooper

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

saurabhnanda avatar Nov 23 '17 11:11 saurabhnanda