yesodweb / persistent

Persistence interface for Haskell allowing multiple storage methods.
MIT License
467 stars 296 forks source link

Sharing types between frontend (ghcjs) and backend (ghc) #667

Closed mchaver closed 4 years ago

mchaver commented 7 years ago

persistent is a pretty big project and it would be nice if there was a way to define a types package, share it between GHC backend and GHCJS frontend without GHCJS depending on persistent. Also I found that some versions of persistent have trouble compiling with GHCJS. Ideally there could be a way to declare your models as types first and then apply a version of mkPersist to an existing type and produce all of the necessary persistent typeclasses and functions on the GHC side only and don't reproduce . Conceptually I don't think it is too challenging but there are a few things from persistent that need to be shared on both sides, namely Entity, Key and Id. Perhaps we could have a small base package that defines these, then the GHCJS package and the main persistent package can import them, but I am not sure how challenging it would be to pull those out.

(For reference, this was also an issue mentioned on groundhog https://github.com/lykahb/groundhog/issues/53)

gregwebs commented 7 years ago

This is certainly not the first time this approach has been proposed. Its tough to find a satisfactory solution here, particularly around adding meta-data annotations. But I think it would be great to have an alternate way to declare as you are suggesting.

parsonsmatt commented 4 years ago

Closing as a duplicate of #476

I think I may have misunderstood, so if I have, feel free to reopen and clarify :)