-
Notifications
You must be signed in to change notification settings - Fork 301
Support promoted types in Quasi Quoter #1258
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
Conversation
| let UserName = #name | ||
| OrganizationName = #name | ||
| DogName = #name | ||
| -} |
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.
There might be some more stuff to do here for this test maybe ... for now I have something that just asserts that it typechecks 👍
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.
Yeah - let's check the type of the field accessors and the EntityFields.
Still should jsut be a compilation check, but something like:
let mkTransfer :: CustomerId -> MoneyAmount 'CustomerOwned 'Debt -> CustomerTransfer
mkTransfer = CustomerTransfer
getAmount :: CustomerTransfer -> MoneyAmount 'CustomerOwned 'Debt
getAmount = customerTransferMoneyAmount
persistent/Database/Persist/TH.hs
Outdated
| mEmbedded ents (FTTypeCon Nothing (EntityNameHS -> name)) = | ||
| maybe (Left Nothing) Right $ M.lookup name ents | ||
| mEmbedded ents (FTTypePromoted (EntityNameHS -> name)) = | ||
| maybe (Left Nothing) Right $ M.lookup name ents |
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.
Not sure about this. I basically just mirrored what is done for FTTypeCon when there is no module (ie the case above).
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.
Hmm - I'd say let's go with a Left Nothing on all cases here. If we hit this, it means we're trying to determine whether we need an embedded entity reference, which we shouldn't - the only place this could possibly be is if we've got an FTApp or similar, and we want the SQL type construction to proceed unchanged.
| maybe (Left Nothing) Right $ M.lookup name ents | |
| Left Nothing |
Like, we'll have foo (Proxy 'User). That'll get turned into FTApp (FTypeCon Nothing "Proxy") (FTTypePromoted "User"). This code recurses and then finds that the corresponding EmbedEntityDef is for a User, even though that's totally wrong.
parsonsmatt
left a comment
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.
There are a few changes I'd like on this before accepting it, but it is fantastic work - thank you so much!
I'm afraid the changes I put into #1256 are going to be a massive conflict here. So let's get this merged in to master, we can release it as a patch bump since it's just a change to the QQ and purely additive. Then I'll work on getting it merged into persistent-2.13.
| in case T.breakOnEnd "." t of | ||
| (_, "") -> FTTypeCon Nothing t | ||
| ("", _) -> FTTypeCon Nothing t | ||
| (a, b) -> FTTypeCon (Just $ T.init a) b |
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.
Looks great 👍🏻
persistent/Database/Persist/TH.hs
Outdated
| mEmbedded ents (FTTypeCon Nothing (EntityNameHS -> name)) = | ||
| maybe (Left Nothing) Right $ M.lookup name ents | ||
| mEmbedded ents (FTTypePromoted (EntityNameHS -> name)) = | ||
| maybe (Left Nothing) Right $ M.lookup name ents |
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.
Hmm - I'd say let's go with a Left Nothing on all cases here. If we hit this, it means we're trying to determine whether we need an embedded entity reference, which we shouldn't - the only place this could possibly be is if we've got an FTApp or similar, and we want the SQL type construction to proceed unchanged.
| maybe (Left Nothing) Right $ M.lookup name ents | |
| Left Nothing |
Like, we'll have foo (Proxy 'User). That'll get turned into FTApp (FTypeCon Nothing "Proxy") (FTTypePromoted "User"). This code recurses and then finds that the corresponding EmbedEntityDef is for a User, even though that's totally wrong.
| FTApp x y -> | ||
| ftToType x `AppT` ftToType y | ||
| FTList x -> | ||
| ListT `AppT` ftToType x |
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.
👨🏻🍳
| -- {-# LANGUAGE TypeFamilies #-} | ||
| {-# LANGUAGE UndecidableInstances #-} | ||
|
|
||
| module Database.Persist.TH.KindEntitiesSpec where |
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.
beautiful tests <3
| let UserName = #name | ||
| OrganizationName = #name | ||
| DogName = #name | ||
| -} |
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.
Yeah - let's check the type of the field accessors and the EntityFields.
Still should jsut be a compilation check, but something like:
let mkTransfer :: CustomerId -> MoneyAmount 'CustomerOwned 'Debt -> CustomerTransfer
mkTransfer = CustomerTransfer
getAmount :: CustomerTransfer -> MoneyAmount 'CustomerOwned 'Debt
getAmount = customerTransferMoneyAmount| sqlType _ = SqlInt64 | ||
|
|
||
| instance PersistField (MoneyAmount a b) where | ||
| toPersistValue (MoneyAmount n) = PersistRational n |
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 don't think this PeristRational lines up with the SqlInt64 type you specified
- Correct instances for MoneyAmount - Add some additional compiler checks to spec - Removed commented out code - Remove redundant logic in mEmbedded
61b5361 to
2e11e0b
Compare
parsonsmatt
left a comment
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.
🎉
|
All good to merge? |
|
Yeah all good 👍 I'm happy to do the merge/conflict resolution into |
|
That would be really helpful, thank you 🙌🏻 |
Before submitting your PR, check that you've:
@sincedeclarations to the Haddockstylish-haskellon any changed files..editorconfigfile for details)After submitting your PR:
(unreleased)on the ChangelogCloses #1166
I've opened this as a draft PR with a view towards getting some feedback on it still. I think everything here should be fine for addressing that ticket, but there might be something I have overlooked here. I will annotate what I've got so far.
I have also opened this PR against
masteras it is not a super invasive change, and I would be happy to deal with porting it forward into thepersistent-2.13branch after it is merged in. Alternatively if it is preferred that this PR goes against that branch, and is backported tomaster, I'd be happy to do that as well.It may also make sense for this to just go into
2.13like my other recent change 👍