Skip to content

Exists query#1070

Closed
limick wants to merge 7 commits intoyesodweb:masterfrom
zoominsoftware:exists-query
Closed

Exists query#1070
limick wants to merge 7 commits intoyesodweb:masterfrom
zoominsoftware:exists-query

Conversation

@limick
Copy link
Contributor

@limick limick commented Apr 2, 2020

This addresses #1069 by adding an exists function to the PersistQueryRead type class, which already provides the count function. The count function will be used for a fallback implementation for backends that don't provide a separate existence check.

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)

@limick limick marked this pull request as ready for review April 2, 2020 20:30

## 2.11.0

* Naive implementation of `exists`function from `PersistQueryRead` type class using `count`.
Copy link
Member

@MaxGabriel MaxGabriel Aug 8, 2020

Choose a reason for hiding this comment

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

Suggested change
* Naive implementation of `exists`function from `PersistQueryRead` type class using `count`.
* Naive implementation of `exists` function from `PersistQueryRead` type class using `count`. [#1070](https://github.com/yesodweb/persistent/pull/1070/files)


* [#1060](https://github.com/yesodweb/persistent/pull/1060)
* The QuasiQuoter now supports `OnDelete` and `OnUpdate` cascade options.
* [#1069](https://github.com/yesodweb/persistent/pull/1070)
Copy link
Member

Choose a reason for hiding this comment

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

Is this 1069/1070 mismatch intentional?

Copy link
Member

Choose a reason for hiding this comment

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

(This also applies to the other changelog files)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think I somehow came to the conclusion that the first is the issue number while the second is the PR, but I'll change it to the PR everywhere.

withRawQuery sql (getFiltsValues conn filts) $ do
mm <- CL.head
case mm of
Just [PersistBool b] -> return b
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Just [PersistBool b] -> return b
Just [PersistBool b] -> return b -- Postgres

mm <- CL.head
case mm of
Just [PersistBool b] -> return b
Just [PersistInt64 i] -> return $ i > 0
Copy link
Member

@MaxGabriel MaxGabriel Aug 9, 2020

Choose a reason for hiding this comment

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

Suggested change
Just [PersistInt64 i] -> return $ i > 0
Just [PersistInt64 i] -> return $ i > 0 -- MySQL, SQLite
-- The following haven't been tested, but this is based off the code used in count

Comment on lines +78 to +79
Just xs -> error $ "count:invalid sql return xs["++show xs++"] sql["++show sql++"]"
Nothing -> error $ "count:invalid sql returned nothing sql["++show sql++"]"
Copy link
Member

@MaxGabriel MaxGabriel Aug 9, 2020

Choose a reason for hiding this comment

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

Suggested change
Just xs -> error $ "count:invalid sql return xs["++show xs++"] sql["++show sql++"]"
Nothing -> error $ "count:invalid sql returned nothing sql["++show sql++"]"
Just xs -> error $ "PersistQuery.exists: Expected a boolean, int, double, or bytestring; got: " ++ show xs ++ " for query: " ++ show sql
Nothing -> error $ "PersistQuery.exists: Expected a boolean, int, double, or bytestring; got: Nothing for query: " ++ show sql

@MaxGabriel
Copy link
Member

This looks good to me, made a few suggested changes

@parsonsmatt parsonsmatt changed the base branch from master to matt/exists-query September 28, 2020 13:38
@parsonsmatt parsonsmatt changed the base branch from matt/exists-query to master September 28, 2020 13:39
@parsonsmatt
Copy link
Collaborator

@limick Would you mind applying the relevant suggestions? Should be doable from the web editor. THen we can get this merged in and released 😄

@limick limick mentioned this pull request Oct 2, 2020
5 tasks
@limick
Copy link
Contributor Author

limick commented Oct 2, 2020

Sure, thanks for your patience.
I no longer have access to the original repository, so I created a new PR #1131 to replace this one. I've applied the suggestions there (thanks!) and rebased onto the destination branch.

@limick limick closed this Oct 2, 2020
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.

3 participants