-
Notifications
You must be signed in to change notification settings - Fork 107
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
Add selectOne
#265
Add selectOne
#265
Conversation
I'd prefer that the function be called selectFirst, unfortunately that would technically be a major API break since we're re-exporting persistent. Perhaps we could put this in the release that removes the old syntax? |
Thanks for the quick reply @belevy :) I was wondering about that, to avoid conflicts with existent persistent function, thus I thought as a workaround (for now) to get it called in a different way. And correct me if I'm wrong, but you are mentioning to put this as part of |
@parsonsmatt Correct me if I'm wrong but this would require a bump in the major version right i.e 4.0.0 |
|
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'd rather have this out now with selectOne
as the name than do a major version bump to give it the name selectFirst
.
This is great to have, thanks for the PR! 😄
src/Database/Esqueleto.hs
Outdated
@@ -129,7 +130,7 @@ module Database.Esqueleto {-# WARNING "This module will switch over to the Exper | |||
) where | |||
|
|||
import Database.Esqueleto.Legacy | |||
import Database.Esqueleto.Internal.PersistentImport | |||
import Database.Esqueleto.Internal.PersistentImport hiding (selectFirst) |
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.
Instead of hiding the import, we should just not re-export it from PersistentImpot
src/Database/Esqueleto/Legacy.hs
Outdated
@@ -130,7 +131,7 @@ module Database.Esqueleto.Legacy | |||
) where | |||
|
|||
import Database.Esqueleto.Internal.Internal | |||
import Database.Esqueleto.Internal.PersistentImport | |||
import Database.Esqueleto.Internal.PersistentImport hiding (selectFirst) |
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.
Same issue here (and elsewhere) - let's keep this an open import and hide the export at the source.
import Database.Esqueleto.Internal.PersistentImport hiding (selectFirst) | |
import Database.Esqueleto.Internal.PersistentImport |
-- @ | ||
|
||
selectFirst :: (SqlSelect a r, MonadIO m) => SqlQuery a -> SqlReadT m (Maybe r) | ||
selectFirst query = fmap Maybe.listToMaybe $ select $ limit 1 >> query |
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 also like the idea of naming this function selectFirst
, but the API break with persistent
does unfortunately require a major version bump (to 3.6.0.0).
It's such a useful function, I'd like to expose it now. We can do this with a minor version bump (3.5.1.0), as long as it does not conflict. selectOne
is another fine name for it, and I'd honestly be fine with having that 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.
Sounds great to me 🎉 will rename it accordingly and remove the unnecessary hiding
statements, thanks!
-- 'select' $ | ||
-- 'from' $ \person -> do | ||
-- 'limit' 1 | ||
-- return person |
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.
Let's use experimental syntax for the new examples.
-- 'select' $ | |
-- 'from' $ \person -> do | |
-- 'limit' 1 | |
-- return person | |
-- 'select' $ do | |
-- person <- 'from' $ table @Person | |
-- 'limit' 1 | |
-- return person |
-- 'selectFirst' $ | ||
-- 'from' $ \person -> | ||
-- return person |
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.
Same as below - let's use the Experimental
syntax instead, since all code will be switching to it.
Thanks for all the suggestions @belevy @parsonsmatt, I updated the branch accordingly and also updated the version number. Any more feedback is more than welcome 🎉 |
test/Common/Test.hs
Outdated
describe "selectOne" $ do | ||
let personQuery = | ||
selectOne $ | ||
from $ \person -> do |
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.
could you change this test query to use the Experimental syntax please. Were in the process of deprecating the old syntax so it will eventually need to change anyway.
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 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, thank you 😄
-- 'select' $ do | ||
-- person <- 'from' $ 'table' @Person | ||
-- 'limit' 1 | ||
-- return person |
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.
fantastic 😄
itDb "returns Nothing" $ do | ||
res <- personQuery | ||
asserting $ | ||
res `shouldBe` (Nothing :: Maybe (Value PersonId)) |
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.
awesome
released! thanks 😄 |
Closes #257
Before submitting your PR, check that you've:
@since
declarations to the Haddock.stylish-haskell
and otherwise adhered to the style guide.After submitting your PR: