Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Discussion | Move NullKey into the type signature #22

Open
charles-cooper opened this issue May 11, 2017 · 1 comment
Open

Discussion | Move NullKey into the type signature #22

charles-cooper opened this issue May 11, 2017 · 1 comment

Comments

@charles-cooper
Copy link
Contributor

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants