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 inMany #604

Merged
merged 3 commits into from
Aug 31, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/Opaleye/Operators.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
, sqlLength
-- * Containment operators
, in_
, inMany
, inSelect
-- * JSON operators
, SqlIsJson
Expand Down Expand Up @@ -132,7 +133,7 @@
import qualified Opaleye.Select as S
import qualified Opaleye.SqlTypes as T

import qualified Opaleye.Column as Column

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.10)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.2)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 8.8)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.0)

Module ‘Opaleye.Column’ is deprecated:

Check warning on line 136 in src/Opaleye/Operators.hs

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest, 9.4)

Module ‘Opaleye.Column’ is deprecated:

import qualified Opaleye.Internal.HaskellDB.PrimQuery as HPQ

Expand Down Expand Up @@ -289,14 +290,27 @@

-- | 'in_' is designed to be used in prefix form.
--
-- 'in_' @validProducts@ @product@ checks whether @product@ is a valid
-- product. 'in_' @validProducts@ is a function which checks whether
-- a product is a valid product.
in_ :: (Functor f, F.Foldable f) => f (Field a) -> Field a -> F.Field T.SqlBool
-- 'in_' @validUsers@ @user@ checks whether @user@ is a valid user.
-- 'in_' @validUsers@ is a function which checks whether a user is a
-- valid user.
in_ :: (F.Foldable f) => f (Field a) -> Field a -> F.Field T.SqlBool
in_ fcas (Column a) = case NEL.nonEmpty (F.toList fcas) of
Nothing -> T.sqlBool False
Just xs -> Column $ HPQ.BinExpr HPQ.OpIn a (HPQ.ListExpr (fmap C.unColumn xs))

-- | @inMany@ is a generalization of 'in_' to values with multiple
-- fields. It is designed to be used in prefix form.
--
-- @inMany validUsers user@ checks whether @user@ is a valid user.
-- @inMany validUsers@ is a function which checks whether a user is a
-- valid user.
inMany ::
(F.Foldable f, D.Default O.EqPP fields fields) =>
f fields ->
fields ->
F.Field T.SqlBool
inMany xs x = ors (fmap (.=== x) (F.toList xs))

-- | True if the first argument occurs amongst the rows of the second,
-- false otherwise.
--
Expand Down
Loading