{-# LANGUAGE FlexibleContexts #-}

module Opaleye.Values(
  values,
  -- * Explicit versions
  valuesExplicit,
  -- * Adaptors
  V.Valuesspec,
  V.ValuesspecSafe,
  V.valuesspecField,
  -- * Deprecated versions
  valuesSafe,
  valuesSafeExplicit,
  valuesUnsafe,
  valuesUnsafeExplicit,
  ) where

import qualified Opaleye.Internal.QueryArr as Q
import           Opaleye.Internal.Values as V
import qualified Opaleye.Internal.Unpackspec as U
import qualified Opaleye.Select              as S

import           Data.Profunctor.Product.Default (Default, def)

-- | Do not use.  Will be deprecated in 0.8.
valuesUnsafe :: (Default V.ValuesspecUnsafe fields fields,
                 Default U.Unpackspec fields fields) =>
                [fields] -> S.Select fields
valuesUnsafe :: [fields] -> Select fields
valuesUnsafe = Unpackspec fields fields
-> ValuesspecUnsafe fields fields -> [fields] -> Select fields
forall fields fields'.
Unpackspec fields fields'
-> ValuesspecUnsafe fields fields' -> [fields] -> Select fields'
valuesUnsafeExplicit Unpackspec fields fields
forall (p :: * -> * -> *) a b. Default p a b => p a b
def ValuesspecUnsafe fields fields
forall (p :: * -> * -> *) a b. Default p a b => p a b
def

-- | Do not use.  Will be deprecated in 0.8.
valuesUnsafeExplicit :: U.Unpackspec fields fields'
                     -> V.ValuesspecUnsafe fields fields'
                     -> [fields] -> S.Select fields'
valuesUnsafeExplicit :: Unpackspec fields fields'
-> ValuesspecUnsafe fields fields' -> [fields] -> Select fields'
valuesUnsafeExplicit Unpackspec fields fields'
unpack ValuesspecUnsafe fields fields'
valuesspec [fields]
fields =
  (((), Tag) -> (fields', PrimQuery, Tag)) -> Select fields'
forall a b. ((a, Tag) -> (b, PrimQuery, Tag)) -> QueryArr a b
Q.productQueryArr (Unpackspec fields fields'
-> ValuesspecUnsafe fields fields'
-> [fields]
-> ((), Tag)
-> (fields', PrimQuery, Tag)
forall columns columns'.
Unpackspec columns columns'
-> ValuesspecUnsafe columns columns'
-> [columns]
-> ((), Tag)
-> (columns', PrimQuery, Tag)
V.valuesU Unpackspec fields fields'
unpack ValuesspecUnsafe fields fields'
valuesspec [fields]
fields)

-- | 'values' implements Postgres's @VALUES@ construct and allows you
-- to create a @SELECT@ that consists of the given rows.
--
-- Example type specialization:
--
-- @
-- values :: [(Field a, Field b)] -> Select (Field a, Field b)
-- @
--
-- Assuming the @makeAdaptorAndInstance@ splice has been run for the
-- product type @Foo@:
--
-- @
-- values :: [Foo (Field a) (Field b) (Field c)] -> S.Select (Foo (Field a) (Field b) (Field c))
-- @
values :: Default V.Valuesspec fields fields
       => [fields] -> S.Select fields
values :: [fields] -> Select fields
values = Valuesspec fields fields -> [fields] -> Select fields
forall fields fields'.
Valuesspec fields fields' -> [fields] -> Select fields'
valuesExplicit Valuesspec fields fields
forall (p :: * -> * -> *) a b. Default p a b => p a b
def

valuesExplicit :: V.Valuesspec fields fields'
               -> [fields] -> S.Select fields'
valuesExplicit :: Valuesspec fields fields' -> [fields] -> Select fields'
valuesExplicit Valuesspec fields fields'
valuesspec [fields]
fields =
  (((), Tag) -> (fields', PrimQuery, Tag)) -> Select fields'
forall a b. ((a, Tag) -> (b, PrimQuery, Tag)) -> QueryArr a b
Q.productQueryArr (Valuesspec fields fields'
-> [fields] -> ((), Tag) -> (fields', PrimQuery, Tag)
forall columns columns'.
Valuesspec columns columns'
-> [columns] -> ((), Tag) -> (columns', PrimQuery, Tag)
V.valuesUSafe Valuesspec fields fields'
valuesspec [fields]
fields)

-- | Use 'values' instead.  Will be deprecated in 0.8.
valuesSafe :: Default V.Valuesspec fields fields
           => [fields] -> S.Select fields
valuesSafe :: [fields] -> Select fields
valuesSafe = [fields] -> Select fields
forall fields.
Default Valuesspec fields fields =>
[fields] -> Select fields
values

-- | Use 'valuesExplicit' instead.  Will be deprecated in 0.8.
valuesSafeExplicit :: V.Valuesspec fields fields'
                   -> [fields] -> S.Select fields'
valuesSafeExplicit :: Valuesspec fields fields' -> [fields] -> Select fields'
valuesSafeExplicit = Valuesspec fields fields' -> [fields] -> Select fields'
forall fields fields'.
Valuesspec fields fields' -> [fields] -> Select fields'
valuesExplicit