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

Add selectOne #265

Merged
merged 9 commits into from
Jun 17, 2021
Merged

Add selectOne #265

merged 9 commits into from
Jun 17, 2021

Conversation

ibarrae
Copy link
Contributor

@ibarrae ibarrae commented Jun 2, 2021

Closes #257

Before submitting your PR, check that you've:

After submitting your PR:

  • Update the Changelog.md file with a link to your PR.
  • Check that CI passes (or if it fails, for reasons unrelated to your change, like CI timeouts).

@belevy
Copy link
Collaborator

belevy commented Jun 2, 2021

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?

@ibarrae
Copy link
Contributor Author

ibarrae commented Jun 2, 2021

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 4.0.0.0 3.6 right?

@belevy
Copy link
Collaborator

belevy commented Jun 2, 2021

@parsonsmatt Correct me if I'm wrong but this would require a bump in the major version right i.e 4.0.0

@parsonsmatt
Copy link
Collaborator

esqueleto uses PVP versioning so we could put this out with selectFirst as an esqueleto function with 3.6.0.0

Copy link
Collaborator

@parsonsmatt parsonsmatt left a 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! 😄

@@ -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)
Copy link
Collaborator

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

@@ -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)
Copy link
Collaborator

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.

Suggested change
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
Copy link
Collaborator

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.

Copy link
Contributor Author

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!

Comment on lines 2561 to 2564
-- 'select' $
-- 'from' $ \person -> do
-- 'limit' 1
-- return person
Copy link
Collaborator

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.

Suggested change
-- 'select' $
-- 'from' $ \person -> do
-- 'limit' 1
-- return person
-- 'select' $ do
-- person <- 'from' $ table @Person
-- 'limit' 1
-- return person

Comment on lines 2550 to 2552
-- 'selectFirst' $
-- 'from' $ \person ->
-- return person
Copy link
Collaborator

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.

@ibarrae ibarrae marked this pull request as ready for review June 2, 2021 16:34
@ibarrae ibarrae requested a review from parsonsmatt June 2, 2021 16:35
@ibarrae
Copy link
Contributor Author

ibarrae commented Jun 2, 2021

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 🎉

@ibarrae ibarrae changed the title Add selectSingle Add selectOne Jun 2, 2021
describe "selectOne" $ do
let personQuery =
selectOne $
from $ \person -> do
Copy link
Collaborator

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For sure @belevy, I still need to get used to the upcoming syntax 😄. You can take a look at those changes in this commit

@ibarrae ibarrae requested a review from belevy June 16, 2021 20:45
Copy link
Collaborator

@parsonsmatt parsonsmatt left a 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
Copy link
Collaborator

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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

awesome

@parsonsmatt parsonsmatt merged commit 3312804 into bitemyapp:master Jun 17, 2021
@parsonsmatt
Copy link
Collaborator

released! thanks 😄

@ibarrae ibarrae deleted the add-select-first branch July 12, 2021 19:44
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

Successfully merging this pull request may close these issues.

Add selectFirst Esqueleto variant
3 participants