-
Notifications
You must be signed in to change notification settings - Fork 292
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
Derive Generic instances for non-generic newtype keys #990
Derive Generic instances for non-generic newtype keys #990
Conversation
6e05d72
to
8dad9e5
Compare
8dad9e5
to
d054f34
Compare
-- | ||
-- Default: [] | ||
-- | ||
-- @since 2.7.4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh hell yes
@@ -902,6 +912,8 @@ mkKeyTypeDec mps t = do | |||
useNewtype = pkNewtype mps t | |||
customKeyType = not (defaultIdType t) || not useNewtype || isJust (entityPrimary t) | |||
|
|||
supplement :: [Name] -> [Name] | |||
supplement names = names <> (filter (`notElem` names) $ mpsDeriveInstances mps) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i feel like these somewhat awkward elem
dances could be made easier by a gentle use of Set
|
||
import Database.Persist | ||
import Database.Persist.TH | ||
import TemplateTestImports | ||
|
||
|
||
share [mkPersist sqlSettings { mpsGeneric = False }, mkDeleteCascade sqlSettings { mpsGeneric = False }] [persistUpperCase| | ||
share [mkPersist sqlSettings { mpsGeneric = False, mpsDeriveInstances = [''Generic] }, mkDeleteCascade sqlSettings { mpsGeneric = False }] [persistUpperCase| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it, awesome.
else do | ||
let allInstances = [''Show, ''Read, ''Eq, ''Ord, ''PathPiece, ''ToHttpApiData, ''FromHttpApiData, ''PersistField, ''PersistFieldSql, ''ToJSON, ''FromJSON] | ||
let allInstances = supplement [''Show, ''Read, ''Eq, ''Ord, ''PathPiece, ''ToHttpApiData, ''FromHttpApiData, ''PersistField, ''PersistFieldSql, ''ToJSON, ''FromJSON] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Point for future upgrade: remove the unnecessary instances here like PathPiece, ToHttpApiData, etc that don't make sense for non-web-apps.
Released in |
Before submitting your PR, check that you've:
After submitting your PR: