{-# LANGUAGE TemplateHaskell #-}

-- | Internal representation of an insertion in a database table.
--
-- What makes this specific mutation tricky is that we support recursive
-- insertions, across local relationships. Because local joins come in two
-- different kinds (object relationships and array relations), and because for each
-- table we expose two root different root fields (insert_one and insert), we
-- distinguish between *single row inserts* and *multi rows inserts*.
--
-- TODO: the distinction between single-row inserts and multi-rows inserts does not
-- need to be enforced the way it currently is, with booleans and different
-- types. The distinction could be made in the translation layer, if need be.
module Hasura.RQL.IR.Insert
  ( AnnotatedInsertData (..),
    AnnotatedInsert (..),
    aiFieldName,
    aiIsSingle,
    aiData,
    aiOutput,
    aiNamingConvention,
    AnnotatedInsertField (..),
    AnnotatedInsertRow,
    ArrayRelationInsert,
    OnConflictClause (..),
    OnConflictClauseData (..),
    ConflictTarget (..),
    InsertQueryP1 (..),
    MultiObjectInsert,
    ObjectRelationInsert,
    RelationInsert (..),
    Single (..),
    SingleObjectInsert,
    getInsertArrayRelationships,
    getInsertColumns,
    getInsertObjectRelationships,
    _AIArrayRelationship,
    _AIColumn,
    _AIObjectRelationship,
  )
where

import Control.Lens ((^?))
import Control.Lens.TH (makeLenses, makePrisms)
import Data.Kind (Type)
import Hasura.Prelude
import Hasura.RQL.IR.BoolExp
import Hasura.RQL.IR.Conflict
import Hasura.RQL.IR.Returning
import Hasura.RQL.Types.Backend
import Hasura.RQL.Types.BackendType
import Hasura.RQL.Types.Column
import Hasura.RQL.Types.Common
import Hasura.RQL.Types.NamingCase (NamingCase)
import Hasura.RQL.Types.Permission
import Hasura.RQL.Types.Relationships.Local

-- | Overall representation of an insert mutation, corresponding to one root
-- field in our mutation, including the parsed selection set of the mutation's
-- output. For historical reasons, it will always contain a `MultiObjectInsert`,
-- whether the root mutation is a single row or not, and will distinguish
-- between them using a boolean field.
data AnnotatedInsert (b :: BackendType) (r :: Type) v = AnnotatedInsert
  { forall (b :: BackendType) r v. AnnotatedInsert b r v -> Text
_aiFieldName :: Text,
    forall (b :: BackendType) r v. AnnotatedInsert b r v -> Bool
_aiIsSingle :: Bool,
    forall (b :: BackendType) r v.
AnnotatedInsert b r v -> MultiObjectInsert b v
_aiData :: MultiObjectInsert b v,
    forall (b :: BackendType) r v.
AnnotatedInsert b r v -> MutationOutputG b r v
_aiOutput :: MutationOutputG b r v,
    forall (b :: BackendType) r v.
AnnotatedInsert b r v -> Maybe NamingCase
_aiNamingConvention :: Maybe NamingCase
  }
  deriving ((forall a b.
 (a -> b) -> AnnotatedInsert b r a -> AnnotatedInsert b r b)
-> (forall a b.
    a -> AnnotatedInsert b r b -> AnnotatedInsert b r a)
-> Functor (AnnotatedInsert b r)
forall a b. a -> AnnotatedInsert b r b -> AnnotatedInsert b r a
forall a b.
(a -> b) -> AnnotatedInsert b r a -> AnnotatedInsert b r b
forall (b :: BackendType) r a b.
Backend b =>
a -> AnnotatedInsert b r b -> AnnotatedInsert b r a
forall (b :: BackendType) r a b.
Backend b =>
(a -> b) -> AnnotatedInsert b r a -> AnnotatedInsert b r b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b) -> AnnotatedInsert b r a -> AnnotatedInsert b r b
fmap :: forall a b.
(a -> b) -> AnnotatedInsert b r a -> AnnotatedInsert b r b
$c<$ :: forall (b :: BackendType) r a b.
Backend b =>
a -> AnnotatedInsert b r b -> AnnotatedInsert b r a
<$ :: forall a b. a -> AnnotatedInsert b r b -> AnnotatedInsert b r a
Functor, (forall m. Monoid m => AnnotatedInsert b r m -> m)
-> (forall m a. Monoid m => (a -> m) -> AnnotatedInsert b r a -> m)
-> (forall m a. Monoid m => (a -> m) -> AnnotatedInsert b r a -> m)
-> (forall a b. (a -> b -> b) -> b -> AnnotatedInsert b r a -> b)
-> (forall a b. (a -> b -> b) -> b -> AnnotatedInsert b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> AnnotatedInsert b r a -> b)
-> (forall b a. (b -> a -> b) -> b -> AnnotatedInsert b r a -> b)
-> (forall a. (a -> a -> a) -> AnnotatedInsert b r a -> a)
-> (forall a. (a -> a -> a) -> AnnotatedInsert b r a -> a)
-> (forall a. AnnotatedInsert b r a -> [a])
-> (forall a. AnnotatedInsert b r a -> Bool)
-> (forall a. AnnotatedInsert b r a -> Int)
-> (forall a. Eq a => a -> AnnotatedInsert b r a -> Bool)
-> (forall a. Ord a => AnnotatedInsert b r a -> a)
-> (forall a. Ord a => AnnotatedInsert b r a -> a)
-> (forall a. Num a => AnnotatedInsert b r a -> a)
-> (forall a. Num a => AnnotatedInsert b r a -> a)
-> Foldable (AnnotatedInsert b r)
forall a. Eq a => a -> AnnotatedInsert b r a -> Bool
forall a. Num a => AnnotatedInsert b r a -> a
forall a. Ord a => AnnotatedInsert b r a -> a
forall m. Monoid m => AnnotatedInsert b r m -> m
forall a. AnnotatedInsert b r a -> Bool
forall a. AnnotatedInsert b r a -> Int
forall a. AnnotatedInsert b r a -> [a]
forall a. (a -> a -> a) -> AnnotatedInsert b r a -> a
forall m a. Monoid m => (a -> m) -> AnnotatedInsert b r a -> m
forall b a. (b -> a -> b) -> b -> AnnotatedInsert b r a -> b
forall a b. (a -> b -> b) -> b -> AnnotatedInsert b r a -> b
forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> AnnotatedInsert b r a -> Bool
forall (b :: BackendType) r a.
(Backend b, Num a) =>
AnnotatedInsert b r a -> a
forall (b :: BackendType) r a.
(Backend b, Ord a) =>
AnnotatedInsert b r a -> a
forall (b :: BackendType) r m.
(Backend b, Monoid m) =>
AnnotatedInsert b r m -> m
forall (b :: BackendType) r a.
Backend b =>
AnnotatedInsert b r a -> Bool
forall (b :: BackendType) r a.
Backend b =>
AnnotatedInsert b r a -> Int
forall (b :: BackendType) r a.
Backend b =>
AnnotatedInsert b r a -> [a]
forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> AnnotatedInsert b r a -> a
forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedInsert b r a -> m
forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedInsert b r a -> b
forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedInsert b r a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (b :: BackendType) r m.
(Backend b, Monoid m) =>
AnnotatedInsert b r m -> m
fold :: forall m. Monoid m => AnnotatedInsert b r m -> m
$cfoldMap :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedInsert b r a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> AnnotatedInsert b r a -> m
$cfoldMap' :: forall (b :: BackendType) r m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedInsert b r a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> AnnotatedInsert b r a -> m
$cfoldr :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedInsert b r a -> b
foldr :: forall a b. (a -> b -> b) -> b -> AnnotatedInsert b r a -> b
$cfoldr' :: forall (b :: BackendType) r a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedInsert b r a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> AnnotatedInsert b r a -> b
$cfoldl :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedInsert b r a -> b
foldl :: forall b a. (b -> a -> b) -> b -> AnnotatedInsert b r a -> b
$cfoldl' :: forall (b :: BackendType) r b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedInsert b r a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> AnnotatedInsert b r a -> b
$cfoldr1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> AnnotatedInsert b r a -> a
foldr1 :: forall a. (a -> a -> a) -> AnnotatedInsert b r a -> a
$cfoldl1 :: forall (b :: BackendType) r a.
Backend b =>
(a -> a -> a) -> AnnotatedInsert b r a -> a
foldl1 :: forall a. (a -> a -> a) -> AnnotatedInsert b r a -> a
$ctoList :: forall (b :: BackendType) r a.
Backend b =>
AnnotatedInsert b r a -> [a]
toList :: forall a. AnnotatedInsert b r a -> [a]
$cnull :: forall (b :: BackendType) r a.
Backend b =>
AnnotatedInsert b r a -> Bool
null :: forall a. AnnotatedInsert b r a -> Bool
$clength :: forall (b :: BackendType) r a.
Backend b =>
AnnotatedInsert b r a -> Int
length :: forall a. AnnotatedInsert b r a -> Int
$celem :: forall (b :: BackendType) r a.
(Backend b, Eq a) =>
a -> AnnotatedInsert b r a -> Bool
elem :: forall a. Eq a => a -> AnnotatedInsert b r a -> Bool
$cmaximum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
AnnotatedInsert b r a -> a
maximum :: forall a. Ord a => AnnotatedInsert b r a -> a
$cminimum :: forall (b :: BackendType) r a.
(Backend b, Ord a) =>
AnnotatedInsert b r a -> a
minimum :: forall a. Ord a => AnnotatedInsert b r a -> a
$csum :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
AnnotatedInsert b r a -> a
sum :: forall a. Num a => AnnotatedInsert b r a -> a
$cproduct :: forall (b :: BackendType) r a.
(Backend b, Num a) =>
AnnotatedInsert b r a -> a
product :: forall a. Num a => AnnotatedInsert b r a -> a
Foldable, Functor (AnnotatedInsert b r)
Foldable (AnnotatedInsert b r)
Functor (AnnotatedInsert b r)
-> Foldable (AnnotatedInsert b r)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> AnnotatedInsert b r a -> f (AnnotatedInsert b r b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    AnnotatedInsert b r (f a) -> f (AnnotatedInsert b r a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> AnnotatedInsert b r a -> m (AnnotatedInsert b r b))
-> (forall (m :: * -> *) a.
    Monad m =>
    AnnotatedInsert b r (m a) -> m (AnnotatedInsert b r a))
-> Traversable (AnnotatedInsert b r)
forall (b :: BackendType) r.
Backend b =>
Functor (AnnotatedInsert b r)
forall (b :: BackendType) r.
Backend b =>
Foldable (AnnotatedInsert b r)
forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
AnnotatedInsert b r (m a) -> m (AnnotatedInsert b r a)
forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
AnnotatedInsert b r (f a) -> f (AnnotatedInsert b r a)
forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> AnnotatedInsert b r a -> m (AnnotatedInsert b r b)
forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> AnnotatedInsert b r a -> f (AnnotatedInsert b r b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
AnnotatedInsert b r (m a) -> m (AnnotatedInsert b r a)
forall (f :: * -> *) a.
Applicative f =>
AnnotatedInsert b r (f a) -> f (AnnotatedInsert b r a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> AnnotatedInsert b r a -> m (AnnotatedInsert b r b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> AnnotatedInsert b r a -> f (AnnotatedInsert b r b)
$ctraverse :: forall (b :: BackendType) r (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b) -> AnnotatedInsert b r a -> f (AnnotatedInsert b r b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> AnnotatedInsert b r a -> f (AnnotatedInsert b r b)
$csequenceA :: forall (b :: BackendType) r (f :: * -> *) a.
(Backend b, Applicative f) =>
AnnotatedInsert b r (f a) -> f (AnnotatedInsert b r a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
AnnotatedInsert b r (f a) -> f (AnnotatedInsert b r a)
$cmapM :: forall (b :: BackendType) r (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b) -> AnnotatedInsert b r a -> m (AnnotatedInsert b r b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> AnnotatedInsert b r a -> m (AnnotatedInsert b r b)
$csequence :: forall (b :: BackendType) r (m :: * -> *) a.
(Backend b, Monad m) =>
AnnotatedInsert b r (m a) -> m (AnnotatedInsert b r a)
sequence :: forall (m :: * -> *) a.
Monad m =>
AnnotatedInsert b r (m a) -> m (AnnotatedInsert b r a)
Traversable)

-- | One individual insert, one node from the tree.
-- The @f@ parameter is used to construct the container for the values to be
-- inserted: 'Single' for a single-row insert, '[]' for a multi-row insert.
data AnnotatedInsertData (b :: BackendType) (f :: Type -> Type) (v :: Type) = AnnotatedInsertData
  { forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> f (AnnotatedInsertRow b v)
_aiInsertObject :: f (AnnotatedInsertRow b v),
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> TableName b
_aiTableName :: TableName b,
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v
-> (AnnBoolExp b v, Maybe (AnnBoolExp b v))
_aiCheckCondition :: (AnnBoolExp b v, Maybe (AnnBoolExp b v)),
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> [ColumnInfo b]
_aiTableColumns :: [ColumnInfo b],
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> Maybe (NESeq (Column b))
_aiPrimaryKey :: Maybe (NESeq (Column b)),
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> ExtraTableMetadata b
_aiExtraTableMetadata :: ExtraTableMetadata b,
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> PreSetColsG b v
_aiPresetValues :: PreSetColsG b v,
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> BackendInsert b v
_aiBackendInsert :: BackendInsert b v,
    forall (b :: BackendType) (f :: * -> *) v.
AnnotatedInsertData b f v -> Maybe (ValidateInput ResolvedWebhook)
_aiValidateInput :: Maybe (ValidateInput ResolvedWebhook)
  }
  deriving ((forall a b.
 (a -> b) -> AnnotatedInsertData b f a -> AnnotatedInsertData b f b)
-> (forall a b.
    a -> AnnotatedInsertData b f b -> AnnotatedInsertData b f a)
-> Functor (AnnotatedInsertData b f)
forall a b.
a -> AnnotatedInsertData b f b -> AnnotatedInsertData b f a
forall a b.
(a -> b) -> AnnotatedInsertData b f a -> AnnotatedInsertData b f b
forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Functor f) =>
a -> AnnotatedInsertData b f b -> AnnotatedInsertData b f a
forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Functor f) =>
(a -> b) -> AnnotatedInsertData b f a -> AnnotatedInsertData b f b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Functor f) =>
(a -> b) -> AnnotatedInsertData b f a -> AnnotatedInsertData b f b
fmap :: forall a b.
(a -> b) -> AnnotatedInsertData b f a -> AnnotatedInsertData b f b
$c<$ :: forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Functor f) =>
a -> AnnotatedInsertData b f b -> AnnotatedInsertData b f a
<$ :: forall a b.
a -> AnnotatedInsertData b f b -> AnnotatedInsertData b f a
Functor, (forall m. Monoid m => AnnotatedInsertData b f m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AnnotatedInsertData b f a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AnnotatedInsertData b f a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> AnnotatedInsertData b f a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> AnnotatedInsertData b f a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AnnotatedInsertData b f a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AnnotatedInsertData b f a -> b)
-> (forall a. (a -> a -> a) -> AnnotatedInsertData b f a -> a)
-> (forall a. (a -> a -> a) -> AnnotatedInsertData b f a -> a)
-> (forall a. AnnotatedInsertData b f a -> [a])
-> (forall a. AnnotatedInsertData b f a -> Bool)
-> (forall a. AnnotatedInsertData b f a -> Int)
-> (forall a. Eq a => a -> AnnotatedInsertData b f a -> Bool)
-> (forall a. Ord a => AnnotatedInsertData b f a -> a)
-> (forall a. Ord a => AnnotatedInsertData b f a -> a)
-> (forall a. Num a => AnnotatedInsertData b f a -> a)
-> (forall a. Num a => AnnotatedInsertData b f a -> a)
-> Foldable (AnnotatedInsertData b f)
forall a. Eq a => a -> AnnotatedInsertData b f a -> Bool
forall a. Num a => AnnotatedInsertData b f a -> a
forall a. Ord a => AnnotatedInsertData b f a -> a
forall m. Monoid m => AnnotatedInsertData b f m -> m
forall a. AnnotatedInsertData b f a -> Bool
forall a. AnnotatedInsertData b f a -> Int
forall a. AnnotatedInsertData b f a -> [a]
forall a. (a -> a -> a) -> AnnotatedInsertData b f a -> a
forall m a. Monoid m => (a -> m) -> AnnotatedInsertData b f a -> m
forall b a. (b -> a -> b) -> b -> AnnotatedInsertData b f a -> b
forall a b. (a -> b -> b) -> b -> AnnotatedInsertData b f a -> b
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Eq a) =>
a -> AnnotatedInsertData b f a -> Bool
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Num a) =>
AnnotatedInsertData b f a -> a
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Ord a) =>
AnnotatedInsertData b f a -> a
forall (b :: BackendType) (f :: * -> *) m.
(Backend b, Foldable f, Monoid m) =>
AnnotatedInsertData b f m -> m
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
AnnotatedInsertData b f a -> Bool
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
AnnotatedInsertData b f a -> Int
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
AnnotatedInsertData b f a -> [a]
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
(a -> a -> a) -> AnnotatedInsertData b f a -> a
forall (b :: BackendType) (f :: * -> *) m a.
(Backend b, Foldable f, Monoid m) =>
(a -> m) -> AnnotatedInsertData b f a -> m
forall (b :: BackendType) (f :: * -> *) b a.
(Backend b, Foldable f) =>
(b -> a -> b) -> b -> AnnotatedInsertData b f a -> b
forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Foldable f) =>
(a -> b -> b) -> b -> AnnotatedInsertData b f a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (b :: BackendType) (f :: * -> *) m.
(Backend b, Foldable f, Monoid m) =>
AnnotatedInsertData b f m -> m
fold :: forall m. Monoid m => AnnotatedInsertData b f m -> m
$cfoldMap :: forall (b :: BackendType) (f :: * -> *) m a.
(Backend b, Foldable f, Monoid m) =>
(a -> m) -> AnnotatedInsertData b f a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> AnnotatedInsertData b f a -> m
$cfoldMap' :: forall (b :: BackendType) (f :: * -> *) m a.
(Backend b, Foldable f, Monoid m) =>
(a -> m) -> AnnotatedInsertData b f a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> AnnotatedInsertData b f a -> m
$cfoldr :: forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Foldable f) =>
(a -> b -> b) -> b -> AnnotatedInsertData b f a -> b
foldr :: forall a b. (a -> b -> b) -> b -> AnnotatedInsertData b f a -> b
$cfoldr' :: forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Foldable f) =>
(a -> b -> b) -> b -> AnnotatedInsertData b f a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> AnnotatedInsertData b f a -> b
$cfoldl :: forall (b :: BackendType) (f :: * -> *) b a.
(Backend b, Foldable f) =>
(b -> a -> b) -> b -> AnnotatedInsertData b f a -> b
foldl :: forall b a. (b -> a -> b) -> b -> AnnotatedInsertData b f a -> b
$cfoldl' :: forall (b :: BackendType) (f :: * -> *) b a.
(Backend b, Foldable f) =>
(b -> a -> b) -> b -> AnnotatedInsertData b f a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> AnnotatedInsertData b f a -> b
$cfoldr1 :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
(a -> a -> a) -> AnnotatedInsertData b f a -> a
foldr1 :: forall a. (a -> a -> a) -> AnnotatedInsertData b f a -> a
$cfoldl1 :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
(a -> a -> a) -> AnnotatedInsertData b f a -> a
foldl1 :: forall a. (a -> a -> a) -> AnnotatedInsertData b f a -> a
$ctoList :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
AnnotatedInsertData b f a -> [a]
toList :: forall a. AnnotatedInsertData b f a -> [a]
$cnull :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
AnnotatedInsertData b f a -> Bool
null :: forall a. AnnotatedInsertData b f a -> Bool
$clength :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f) =>
AnnotatedInsertData b f a -> Int
length :: forall a. AnnotatedInsertData b f a -> Int
$celem :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Eq a) =>
a -> AnnotatedInsertData b f a -> Bool
elem :: forall a. Eq a => a -> AnnotatedInsertData b f a -> Bool
$cmaximum :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Ord a) =>
AnnotatedInsertData b f a -> a
maximum :: forall a. Ord a => AnnotatedInsertData b f a -> a
$cminimum :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Ord a) =>
AnnotatedInsertData b f a -> a
minimum :: forall a. Ord a => AnnotatedInsertData b f a -> a
$csum :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Num a) =>
AnnotatedInsertData b f a -> a
sum :: forall a. Num a => AnnotatedInsertData b f a -> a
$cproduct :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Foldable f, Num a) =>
AnnotatedInsertData b f a -> a
product :: forall a. Num a => AnnotatedInsertData b f a -> a
Foldable, Functor (AnnotatedInsertData b f)
Foldable (AnnotatedInsertData b f)
Functor (AnnotatedInsertData b f)
-> Foldable (AnnotatedInsertData b f)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> AnnotatedInsertData b f a -> f (AnnotatedInsertData b f b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    AnnotatedInsertData b f (f a) -> f (AnnotatedInsertData b f a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> AnnotatedInsertData b f a -> m (AnnotatedInsertData b f b))
-> (forall (m :: * -> *) a.
    Monad m =>
    AnnotatedInsertData b f (m a) -> m (AnnotatedInsertData b f a))
-> Traversable (AnnotatedInsertData b f)
forall {b :: BackendType} {f :: * -> *}.
(Backend b, Traversable f) =>
Functor (AnnotatedInsertData b f)
forall {b :: BackendType} {f :: * -> *}.
(Backend b, Traversable f) =>
Foldable (AnnotatedInsertData b f)
forall (b :: BackendType) (f :: * -> *) (m :: * -> *) a.
(Backend b, Traversable f, Monad m) =>
AnnotatedInsertData b f (m a) -> m (AnnotatedInsertData b f a)
forall (b :: BackendType) (f :: * -> *) (f :: * -> *) a.
(Backend b, Traversable f, Applicative f) =>
AnnotatedInsertData b f (f a) -> f (AnnotatedInsertData b f a)
forall (b :: BackendType) (f :: * -> *) (m :: * -> *) a b.
(Backend b, Traversable f, Monad m) =>
(a -> m b)
-> AnnotatedInsertData b f a -> m (AnnotatedInsertData b f b)
forall (b :: BackendType) (f :: * -> *) (f :: * -> *) a b.
(Backend b, Traversable f, Applicative f) =>
(a -> f b)
-> AnnotatedInsertData b f a -> f (AnnotatedInsertData b f b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
AnnotatedInsertData b f (m a) -> m (AnnotatedInsertData b f a)
forall (f :: * -> *) a.
Applicative f =>
AnnotatedInsertData b f (f a) -> f (AnnotatedInsertData b f a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AnnotatedInsertData b f a -> m (AnnotatedInsertData b f b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AnnotatedInsertData b f a -> f (AnnotatedInsertData b f b)
$ctraverse :: forall (b :: BackendType) (f :: * -> *) (f :: * -> *) a b.
(Backend b, Traversable f, Applicative f) =>
(a -> f b)
-> AnnotatedInsertData b f a -> f (AnnotatedInsertData b f b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AnnotatedInsertData b f a -> f (AnnotatedInsertData b f b)
$csequenceA :: forall (b :: BackendType) (f :: * -> *) (f :: * -> *) a.
(Backend b, Traversable f, Applicative f) =>
AnnotatedInsertData b f (f a) -> f (AnnotatedInsertData b f a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
AnnotatedInsertData b f (f a) -> f (AnnotatedInsertData b f a)
$cmapM :: forall (b :: BackendType) (f :: * -> *) (m :: * -> *) a b.
(Backend b, Traversable f, Monad m) =>
(a -> m b)
-> AnnotatedInsertData b f a -> m (AnnotatedInsertData b f b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AnnotatedInsertData b f a -> m (AnnotatedInsertData b f b)
$csequence :: forall (b :: BackendType) (f :: * -> *) (m :: * -> *) a.
(Backend b, Traversable f, Monad m) =>
AnnotatedInsertData b f (m a) -> m (AnnotatedInsertData b f a)
sequence :: forall (m :: * -> *) a.
Monad m =>
AnnotatedInsertData b f (m a) -> m (AnnotatedInsertData b f a)
Traversable)

-- | Ad-hoc helper.
-- We differientate between single row inserts ('SingleObjIns') and multiple row
-- inserts ('MultiObjIns'), but both use the same underlying representation:
-- 'AnnIns'. The only difference is which functor is used as a parameter. We use
-- '[]' for 'MultiObjIns', and we use this trivial 'Single' for 'SingleObjIns'.
newtype Single a = Single {forall a. Single a -> a
unSingle :: a}
  deriving ((forall a b. (a -> b) -> Single a -> Single b)
-> (forall a b. a -> Single b -> Single a) -> Functor Single
forall a b. a -> Single b -> Single a
forall a b. (a -> b) -> Single a -> Single b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall a b. (a -> b) -> Single a -> Single b
fmap :: forall a b. (a -> b) -> Single a -> Single b
$c<$ :: forall a b. a -> Single b -> Single a
<$ :: forall a b. a -> Single b -> Single a
Functor, (forall m. Monoid m => Single m -> m)
-> (forall m a. Monoid m => (a -> m) -> Single a -> m)
-> (forall m a. Monoid m => (a -> m) -> Single a -> m)
-> (forall a b. (a -> b -> b) -> b -> Single a -> b)
-> (forall a b. (a -> b -> b) -> b -> Single a -> b)
-> (forall b a. (b -> a -> b) -> b -> Single a -> b)
-> (forall b a. (b -> a -> b) -> b -> Single a -> b)
-> (forall a. (a -> a -> a) -> Single a -> a)
-> (forall a. (a -> a -> a) -> Single a -> a)
-> (forall a. Single a -> [a])
-> (forall a. Single a -> Bool)
-> (forall a. Single a -> Int)
-> (forall a. Eq a => a -> Single a -> Bool)
-> (forall a. Ord a => Single a -> a)
-> (forall a. Ord a => Single a -> a)
-> (forall a. Num a => Single a -> a)
-> (forall a. Num a => Single a -> a)
-> Foldable Single
forall a. Eq a => a -> Single a -> Bool
forall a. Num a => Single a -> a
forall a. Ord a => Single a -> a
forall m. Monoid m => Single m -> m
forall a. Single a -> Bool
forall a. Single a -> Int
forall a. Single a -> [a]
forall a. (a -> a -> a) -> Single a -> a
forall m a. Monoid m => (a -> m) -> Single a -> m
forall b a. (b -> a -> b) -> b -> Single a -> b
forall a b. (a -> b -> b) -> b -> Single a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall m. Monoid m => Single m -> m
fold :: forall m. Monoid m => Single m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> Single a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> Single a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> Single a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> Single a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> Single a -> b
foldr :: forall a b. (a -> b -> b) -> b -> Single a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> Single a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> Single a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> Single a -> b
foldl :: forall b a. (b -> a -> b) -> b -> Single a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> Single a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> Single a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> Single a -> a
foldr1 :: forall a. (a -> a -> a) -> Single a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> Single a -> a
foldl1 :: forall a. (a -> a -> a) -> Single a -> a
$ctoList :: forall a. Single a -> [a]
toList :: forall a. Single a -> [a]
$cnull :: forall a. Single a -> Bool
null :: forall a. Single a -> Bool
$clength :: forall a. Single a -> Int
length :: forall a. Single a -> Int
$celem :: forall a. Eq a => a -> Single a -> Bool
elem :: forall a. Eq a => a -> Single a -> Bool
$cmaximum :: forall a. Ord a => Single a -> a
maximum :: forall a. Ord a => Single a -> a
$cminimum :: forall a. Ord a => Single a -> a
minimum :: forall a. Ord a => Single a -> a
$csum :: forall a. Num a => Single a -> a
sum :: forall a. Num a => Single a -> a
$cproduct :: forall a. Num a => Single a -> a
product :: forall a. Num a => Single a -> a
Foldable, Functor Single
Foldable Single
Functor Single
-> Foldable Single
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> Single a -> f (Single b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    Single (f a) -> f (Single a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> Single a -> m (Single b))
-> (forall (m :: * -> *) a.
    Monad m =>
    Single (m a) -> m (Single a))
-> Traversable Single
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a. Monad m => Single (m a) -> m (Single a)
forall (f :: * -> *) a.
Applicative f =>
Single (f a) -> f (Single a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Single a -> m (Single b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Single a -> f (Single b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Single a -> f (Single b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> Single a -> f (Single b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
Single (f a) -> f (Single a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
Single (f a) -> f (Single a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Single a -> m (Single b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> Single a -> m (Single b)
$csequence :: forall (m :: * -> *) a. Monad m => Single (m a) -> m (Single a)
sequence :: forall (m :: * -> *) a. Monad m => Single (m a) -> m (Single a)
Traversable)

type SingleObjectInsert b v = AnnotatedInsertData b Single v

type MultiObjectInsert b v = AnnotatedInsertData b [] v

-- | An insert item.
-- The object and array relationships are not unavailable when 'XNestedInserts b = XDisable'
data AnnotatedInsertField (b :: BackendType) v
  = AIColumn (Column b, v)
  | AIObjectRelationship (XNestedInserts b) (ObjectRelationInsert b v)
  | AIArrayRelationship (XNestedInserts b) (ArrayRelationInsert b v)
  deriving ((forall a b.
 (a -> b) -> AnnotatedInsertField b a -> AnnotatedInsertField b b)
-> (forall a b.
    a -> AnnotatedInsertField b b -> AnnotatedInsertField b a)
-> Functor (AnnotatedInsertField b)
forall a b.
a -> AnnotatedInsertField b b -> AnnotatedInsertField b a
forall a b.
(a -> b) -> AnnotatedInsertField b a -> AnnotatedInsertField b b
forall (b :: BackendType) a b.
Backend b =>
a -> AnnotatedInsertField b b -> AnnotatedInsertField b a
forall (b :: BackendType) a b.
Backend b =>
(a -> b) -> AnnotatedInsertField b a -> AnnotatedInsertField b b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (b :: BackendType) a b.
Backend b =>
(a -> b) -> AnnotatedInsertField b a -> AnnotatedInsertField b b
fmap :: forall a b.
(a -> b) -> AnnotatedInsertField b a -> AnnotatedInsertField b b
$c<$ :: forall (b :: BackendType) a b.
Backend b =>
a -> AnnotatedInsertField b b -> AnnotatedInsertField b a
<$ :: forall a b.
a -> AnnotatedInsertField b b -> AnnotatedInsertField b a
Functor, (forall m. Monoid m => AnnotatedInsertField b m -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AnnotatedInsertField b a -> m)
-> (forall m a.
    Monoid m =>
    (a -> m) -> AnnotatedInsertField b a -> m)
-> (forall a b.
    (a -> b -> b) -> b -> AnnotatedInsertField b a -> b)
-> (forall a b.
    (a -> b -> b) -> b -> AnnotatedInsertField b a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AnnotatedInsertField b a -> b)
-> (forall b a.
    (b -> a -> b) -> b -> AnnotatedInsertField b a -> b)
-> (forall a. (a -> a -> a) -> AnnotatedInsertField b a -> a)
-> (forall a. (a -> a -> a) -> AnnotatedInsertField b a -> a)
-> (forall a. AnnotatedInsertField b a -> [a])
-> (forall a. AnnotatedInsertField b a -> Bool)
-> (forall a. AnnotatedInsertField b a -> Int)
-> (forall a. Eq a => a -> AnnotatedInsertField b a -> Bool)
-> (forall a. Ord a => AnnotatedInsertField b a -> a)
-> (forall a. Ord a => AnnotatedInsertField b a -> a)
-> (forall a. Num a => AnnotatedInsertField b a -> a)
-> (forall a. Num a => AnnotatedInsertField b a -> a)
-> Foldable (AnnotatedInsertField b)
forall a. Eq a => a -> AnnotatedInsertField b a -> Bool
forall a. Num a => AnnotatedInsertField b a -> a
forall a. Ord a => AnnotatedInsertField b a -> a
forall m. Monoid m => AnnotatedInsertField b m -> m
forall a. AnnotatedInsertField b a -> Bool
forall a. AnnotatedInsertField b a -> Int
forall a. AnnotatedInsertField b a -> [a]
forall a. (a -> a -> a) -> AnnotatedInsertField b a -> a
forall m a. Monoid m => (a -> m) -> AnnotatedInsertField b a -> m
forall b a. (b -> a -> b) -> b -> AnnotatedInsertField b a -> b
forall a b. (a -> b -> b) -> b -> AnnotatedInsertField b a -> b
forall (b :: BackendType) a.
(Backend b, Eq a) =>
a -> AnnotatedInsertField b a -> Bool
forall (b :: BackendType) a.
(Backend b, Num a) =>
AnnotatedInsertField b a -> a
forall (b :: BackendType) a.
(Backend b, Ord a) =>
AnnotatedInsertField b a -> a
forall (b :: BackendType) m.
(Backend b, Monoid m) =>
AnnotatedInsertField b m -> m
forall (b :: BackendType) a.
Backend b =>
AnnotatedInsertField b a -> Bool
forall (b :: BackendType) a.
Backend b =>
AnnotatedInsertField b a -> Int
forall (b :: BackendType) a.
Backend b =>
AnnotatedInsertField b a -> [a]
forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AnnotatedInsertField b a -> a
forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedInsertField b a -> m
forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedInsertField b a -> b
forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedInsertField b a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (b :: BackendType) m.
(Backend b, Monoid m) =>
AnnotatedInsertField b m -> m
fold :: forall m. Monoid m => AnnotatedInsertField b m -> m
$cfoldMap :: forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedInsertField b a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> AnnotatedInsertField b a -> m
$cfoldMap' :: forall (b :: BackendType) m a.
(Backend b, Monoid m) =>
(a -> m) -> AnnotatedInsertField b a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> AnnotatedInsertField b a -> m
$cfoldr :: forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedInsertField b a -> b
foldr :: forall a b. (a -> b -> b) -> b -> AnnotatedInsertField b a -> b
$cfoldr' :: forall (b :: BackendType) a b.
Backend b =>
(a -> b -> b) -> b -> AnnotatedInsertField b a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> AnnotatedInsertField b a -> b
$cfoldl :: forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedInsertField b a -> b
foldl :: forall b a. (b -> a -> b) -> b -> AnnotatedInsertField b a -> b
$cfoldl' :: forall (b :: BackendType) b a.
Backend b =>
(b -> a -> b) -> b -> AnnotatedInsertField b a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> AnnotatedInsertField b a -> b
$cfoldr1 :: forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AnnotatedInsertField b a -> a
foldr1 :: forall a. (a -> a -> a) -> AnnotatedInsertField b a -> a
$cfoldl1 :: forall (b :: BackendType) a.
Backend b =>
(a -> a -> a) -> AnnotatedInsertField b a -> a
foldl1 :: forall a. (a -> a -> a) -> AnnotatedInsertField b a -> a
$ctoList :: forall (b :: BackendType) a.
Backend b =>
AnnotatedInsertField b a -> [a]
toList :: forall a. AnnotatedInsertField b a -> [a]
$cnull :: forall (b :: BackendType) a.
Backend b =>
AnnotatedInsertField b a -> Bool
null :: forall a. AnnotatedInsertField b a -> Bool
$clength :: forall (b :: BackendType) a.
Backend b =>
AnnotatedInsertField b a -> Int
length :: forall a. AnnotatedInsertField b a -> Int
$celem :: forall (b :: BackendType) a.
(Backend b, Eq a) =>
a -> AnnotatedInsertField b a -> Bool
elem :: forall a. Eq a => a -> AnnotatedInsertField b a -> Bool
$cmaximum :: forall (b :: BackendType) a.
(Backend b, Ord a) =>
AnnotatedInsertField b a -> a
maximum :: forall a. Ord a => AnnotatedInsertField b a -> a
$cminimum :: forall (b :: BackendType) a.
(Backend b, Ord a) =>
AnnotatedInsertField b a -> a
minimum :: forall a. Ord a => AnnotatedInsertField b a -> a
$csum :: forall (b :: BackendType) a.
(Backend b, Num a) =>
AnnotatedInsertField b a -> a
sum :: forall a. Num a => AnnotatedInsertField b a -> a
$cproduct :: forall (b :: BackendType) a.
(Backend b, Num a) =>
AnnotatedInsertField b a -> a
product :: forall a. Num a => AnnotatedInsertField b a -> a
Foldable, Functor (AnnotatedInsertField b)
Foldable (AnnotatedInsertField b)
Functor (AnnotatedInsertField b)
-> Foldable (AnnotatedInsertField b)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b)
    -> AnnotatedInsertField b a -> f (AnnotatedInsertField b b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    AnnotatedInsertField b (f a) -> f (AnnotatedInsertField b a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b)
    -> AnnotatedInsertField b a -> m (AnnotatedInsertField b b))
-> (forall (m :: * -> *) a.
    Monad m =>
    AnnotatedInsertField b (m a) -> m (AnnotatedInsertField b a))
-> Traversable (AnnotatedInsertField b)
forall (b :: BackendType).
Backend b =>
Functor (AnnotatedInsertField b)
forall (b :: BackendType).
Backend b =>
Foldable (AnnotatedInsertField b)
forall (b :: BackendType) (m :: * -> *) a.
(Backend b, Monad m) =>
AnnotatedInsertField b (m a) -> m (AnnotatedInsertField b a)
forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Applicative f) =>
AnnotatedInsertField b (f a) -> f (AnnotatedInsertField b a)
forall (b :: BackendType) (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b)
-> AnnotatedInsertField b a -> m (AnnotatedInsertField b b)
forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b)
-> AnnotatedInsertField b a -> f (AnnotatedInsertField b b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
AnnotatedInsertField b (m a) -> m (AnnotatedInsertField b a)
forall (f :: * -> *) a.
Applicative f =>
AnnotatedInsertField b (f a) -> f (AnnotatedInsertField b a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AnnotatedInsertField b a -> m (AnnotatedInsertField b b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AnnotatedInsertField b a -> f (AnnotatedInsertField b b)
$ctraverse :: forall (b :: BackendType) (f :: * -> *) a b.
(Backend b, Applicative f) =>
(a -> f b)
-> AnnotatedInsertField b a -> f (AnnotatedInsertField b b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b)
-> AnnotatedInsertField b a -> f (AnnotatedInsertField b b)
$csequenceA :: forall (b :: BackendType) (f :: * -> *) a.
(Backend b, Applicative f) =>
AnnotatedInsertField b (f a) -> f (AnnotatedInsertField b a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
AnnotatedInsertField b (f a) -> f (AnnotatedInsertField b a)
$cmapM :: forall (b :: BackendType) (m :: * -> *) a b.
(Backend b, Monad m) =>
(a -> m b)
-> AnnotatedInsertField b a -> m (AnnotatedInsertField b b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b)
-> AnnotatedInsertField b a -> m (AnnotatedInsertField b b)
$csequence :: forall (b :: BackendType) (m :: * -> *) a.
(Backend b, Monad m) =>
AnnotatedInsertField b (m a) -> m (AnnotatedInsertField b a)
sequence :: forall (m :: * -> *) a.
Monad m =>
AnnotatedInsertField b (m a) -> m (AnnotatedInsertField b a)
Traversable)

-- | One individual row to be inserted.
-- Contains the columns' values and all the matching recursive relationship inserts.
type AnnotatedInsertRow b v = [AnnotatedInsertField b v]

-- | One individual relationship.
-- Unlike other types, this one is not parameterized by the type of the leaves
-- @v@, but by the kind of insert has to be performed: multi-row or single row.
-- See 'ObjectRelationInsert' and 'ArrayRelationInsert'.
data RelationInsert (b :: BackendType) a = RelationInsert
  { forall (b :: BackendType) a. RelationInsert b a -> a
_riInsertData :: a,
    forall (b :: BackendType) a. RelationInsert b a -> RelInfo b
_riRelationInfo :: RelInfo b
  }
  deriving (Int -> RelationInsert b a -> ShowS
[RelationInsert b a] -> ShowS
RelationInsert b a -> String
(Int -> RelationInsert b a -> ShowS)
-> (RelationInsert b a -> String)
-> ([RelationInsert b a] -> ShowS)
-> Show (RelationInsert b a)
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
forall (b :: BackendType) a.
(Backend b, Show a) =>
Int -> RelationInsert b a -> ShowS
forall (b :: BackendType) a.
(Backend b, Show a) =>
[RelationInsert b a] -> ShowS
forall (b :: BackendType) a.
(Backend b, Show a) =>
RelationInsert b a -> String
$cshowsPrec :: forall (b :: BackendType) a.
(Backend b, Show a) =>
Int -> RelationInsert b a -> ShowS
showsPrec :: Int -> RelationInsert b a -> ShowS
$cshow :: forall (b :: BackendType) a.
(Backend b, Show a) =>
RelationInsert b a -> String
show :: RelationInsert b a -> String
$cshowList :: forall (b :: BackendType) a.
(Backend b, Show a) =>
[RelationInsert b a] -> ShowS
showList :: [RelationInsert b a] -> ShowS
Show, RelationInsert b a -> RelationInsert b a -> Bool
(RelationInsert b a -> RelationInsert b a -> Bool)
-> (RelationInsert b a -> RelationInsert b a -> Bool)
-> Eq (RelationInsert b a)
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
forall (b :: BackendType) a.
(Backend b, Eq a) =>
RelationInsert b a -> RelationInsert b a -> Bool
$c== :: forall (b :: BackendType) a.
(Backend b, Eq a) =>
RelationInsert b a -> RelationInsert b a -> Bool
== :: RelationInsert b a -> RelationInsert b a -> Bool
$c/= :: forall (b :: BackendType) a.
(Backend b, Eq a) =>
RelationInsert b a -> RelationInsert b a -> Bool
/= :: RelationInsert b a -> RelationInsert b a -> Bool
Eq, (forall a b. (a -> b) -> RelationInsert b a -> RelationInsert b b)
-> (forall a b. a -> RelationInsert b b -> RelationInsert b a)
-> Functor (RelationInsert b)
forall a b. a -> RelationInsert b b -> RelationInsert b a
forall a b. (a -> b) -> RelationInsert b a -> RelationInsert b b
forall (b :: BackendType) a b.
a -> RelationInsert b b -> RelationInsert b a
forall (b :: BackendType) a b.
(a -> b) -> RelationInsert b a -> RelationInsert b b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
$cfmap :: forall (b :: BackendType) a b.
(a -> b) -> RelationInsert b a -> RelationInsert b b
fmap :: forall a b. (a -> b) -> RelationInsert b a -> RelationInsert b b
$c<$ :: forall (b :: BackendType) a b.
a -> RelationInsert b b -> RelationInsert b a
<$ :: forall a b. a -> RelationInsert b b -> RelationInsert b a
Functor, (forall m. Monoid m => RelationInsert b m -> m)
-> (forall m a. Monoid m => (a -> m) -> RelationInsert b a -> m)
-> (forall m a. Monoid m => (a -> m) -> RelationInsert b a -> m)
-> (forall a b. (a -> b -> b) -> b -> RelationInsert b a -> b)
-> (forall a b. (a -> b -> b) -> b -> RelationInsert b a -> b)
-> (forall b a. (b -> a -> b) -> b -> RelationInsert b a -> b)
-> (forall b a. (b -> a -> b) -> b -> RelationInsert b a -> b)
-> (forall a. (a -> a -> a) -> RelationInsert b a -> a)
-> (forall a. (a -> a -> a) -> RelationInsert b a -> a)
-> (forall a. RelationInsert b a -> [a])
-> (forall a. RelationInsert b a -> Bool)
-> (forall a. RelationInsert b a -> Int)
-> (forall a. Eq a => a -> RelationInsert b a -> Bool)
-> (forall a. Ord a => RelationInsert b a -> a)
-> (forall a. Ord a => RelationInsert b a -> a)
-> (forall a. Num a => RelationInsert b a -> a)
-> (forall a. Num a => RelationInsert b a -> a)
-> Foldable (RelationInsert b)
forall a. Eq a => a -> RelationInsert b a -> Bool
forall a. Num a => RelationInsert b a -> a
forall a. Ord a => RelationInsert b a -> a
forall m. Monoid m => RelationInsert b m -> m
forall a. RelationInsert b a -> Bool
forall a. RelationInsert b a -> Int
forall a. RelationInsert b a -> [a]
forall a. (a -> a -> a) -> RelationInsert b a -> a
forall m a. Monoid m => (a -> m) -> RelationInsert b a -> m
forall b a. (b -> a -> b) -> b -> RelationInsert b a -> b
forall a b. (a -> b -> b) -> b -> RelationInsert b a -> b
forall (b :: BackendType) a.
Eq a =>
a -> RelationInsert b a -> Bool
forall (b :: BackendType) a. Num a => RelationInsert b a -> a
forall (b :: BackendType) a. Ord a => RelationInsert b a -> a
forall (b :: BackendType) m. Monoid m => RelationInsert b m -> m
forall (b :: BackendType) a. RelationInsert b a -> Bool
forall (b :: BackendType) a. RelationInsert b a -> Int
forall (b :: BackendType) a. RelationInsert b a -> [a]
forall (b :: BackendType) a.
(a -> a -> a) -> RelationInsert b a -> a
forall (b :: BackendType) m a.
Monoid m =>
(a -> m) -> RelationInsert b a -> m
forall (b :: BackendType) b a.
(b -> a -> b) -> b -> RelationInsert b a -> b
forall (b :: BackendType) a b.
(a -> b -> b) -> b -> RelationInsert b a -> b
forall (t :: * -> *).
(forall m. Monoid m => t m -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall m a. Monoid m => (a -> m) -> t a -> m)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall a b. (a -> b -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall b a. (b -> a -> b) -> b -> t a -> b)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. (a -> a -> a) -> t a -> a)
-> (forall a. t a -> [a])
-> (forall a. t a -> Bool)
-> (forall a. t a -> Int)
-> (forall a. Eq a => a -> t a -> Bool)
-> (forall a. Ord a => t a -> a)
-> (forall a. Ord a => t a -> a)
-> (forall a. Num a => t a -> a)
-> (forall a. Num a => t a -> a)
-> Foldable t
$cfold :: forall (b :: BackendType) m. Monoid m => RelationInsert b m -> m
fold :: forall m. Monoid m => RelationInsert b m -> m
$cfoldMap :: forall (b :: BackendType) m a.
Monoid m =>
(a -> m) -> RelationInsert b a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> RelationInsert b a -> m
$cfoldMap' :: forall (b :: BackendType) m a.
Monoid m =>
(a -> m) -> RelationInsert b a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> RelationInsert b a -> m
$cfoldr :: forall (b :: BackendType) a b.
(a -> b -> b) -> b -> RelationInsert b a -> b
foldr :: forall a b. (a -> b -> b) -> b -> RelationInsert b a -> b
$cfoldr' :: forall (b :: BackendType) a b.
(a -> b -> b) -> b -> RelationInsert b a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> RelationInsert b a -> b
$cfoldl :: forall (b :: BackendType) b a.
(b -> a -> b) -> b -> RelationInsert b a -> b
foldl :: forall b a. (b -> a -> b) -> b -> RelationInsert b a -> b
$cfoldl' :: forall (b :: BackendType) b a.
(b -> a -> b) -> b -> RelationInsert b a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> RelationInsert b a -> b
$cfoldr1 :: forall (b :: BackendType) a.
(a -> a -> a) -> RelationInsert b a -> a
foldr1 :: forall a. (a -> a -> a) -> RelationInsert b a -> a
$cfoldl1 :: forall (b :: BackendType) a.
(a -> a -> a) -> RelationInsert b a -> a
foldl1 :: forall a. (a -> a -> a) -> RelationInsert b a -> a
$ctoList :: forall (b :: BackendType) a. RelationInsert b a -> [a]
toList :: forall a. RelationInsert b a -> [a]
$cnull :: forall (b :: BackendType) a. RelationInsert b a -> Bool
null :: forall a. RelationInsert b a -> Bool
$clength :: forall (b :: BackendType) a. RelationInsert b a -> Int
length :: forall a. RelationInsert b a -> Int
$celem :: forall (b :: BackendType) a.
Eq a =>
a -> RelationInsert b a -> Bool
elem :: forall a. Eq a => a -> RelationInsert b a -> Bool
$cmaximum :: forall (b :: BackendType) a. Ord a => RelationInsert b a -> a
maximum :: forall a. Ord a => RelationInsert b a -> a
$cminimum :: forall (b :: BackendType) a. Ord a => RelationInsert b a -> a
minimum :: forall a. Ord a => RelationInsert b a -> a
$csum :: forall (b :: BackendType) a. Num a => RelationInsert b a -> a
sum :: forall a. Num a => RelationInsert b a -> a
$cproduct :: forall (b :: BackendType) a. Num a => RelationInsert b a -> a
product :: forall a. Num a => RelationInsert b a -> a
Foldable, Functor (RelationInsert b)
Foldable (RelationInsert b)
Functor (RelationInsert b)
-> Foldable (RelationInsert b)
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> RelationInsert b a -> f (RelationInsert b b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    RelationInsert b (f a) -> f (RelationInsert b a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> RelationInsert b a -> m (RelationInsert b b))
-> (forall (m :: * -> *) a.
    Monad m =>
    RelationInsert b (m a) -> m (RelationInsert b a))
-> Traversable (RelationInsert b)
forall (b :: BackendType). Functor (RelationInsert b)
forall (b :: BackendType). Foldable (RelationInsert b)
forall (b :: BackendType) (m :: * -> *) a.
Monad m =>
RelationInsert b (m a) -> m (RelationInsert b a)
forall (b :: BackendType) (f :: * -> *) a.
Applicative f =>
RelationInsert b (f a) -> f (RelationInsert b a)
forall (b :: BackendType) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RelationInsert b a -> m (RelationInsert b b)
forall (b :: BackendType) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RelationInsert b a -> f (RelationInsert b b)
forall (t :: * -> *).
Functor t
-> Foldable t
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> t a -> f (t b))
-> (forall (f :: * -> *) a. Applicative f => t (f a) -> f (t a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> t a -> m (t b))
-> (forall (m :: * -> *) a. Monad m => t (m a) -> m (t a))
-> Traversable t
forall (m :: * -> *) a.
Monad m =>
RelationInsert b (m a) -> m (RelationInsert b a)
forall (f :: * -> *) a.
Applicative f =>
RelationInsert b (f a) -> f (RelationInsert b a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RelationInsert b a -> m (RelationInsert b b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RelationInsert b a -> f (RelationInsert b b)
$ctraverse :: forall (b :: BackendType) (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RelationInsert b a -> f (RelationInsert b b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> RelationInsert b a -> f (RelationInsert b b)
$csequenceA :: forall (b :: BackendType) (f :: * -> *) a.
Applicative f =>
RelationInsert b (f a) -> f (RelationInsert b a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
RelationInsert b (f a) -> f (RelationInsert b a)
$cmapM :: forall (b :: BackendType) (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RelationInsert b a -> m (RelationInsert b b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> RelationInsert b a -> m (RelationInsert b b)
$csequence :: forall (b :: BackendType) (m :: * -> *) a.
Monad m =>
RelationInsert b (m a) -> m (RelationInsert b a)
sequence :: forall (m :: * -> *) a.
Monad m =>
RelationInsert b (m a) -> m (RelationInsert b a)
Traversable)

-- | Insert across an object relationship.
-- Object relationships are 1:1 relationships across tables; an insert across
-- such a relationship can only insert one single row at a time; 'RelIns' is
-- therefore parameterized by a 'SingleObjectInsert'.
type ObjectRelationInsert b v = RelationInsert b (SingleObjectInsert b v)

-- | Insert across an array relationship.
-- Array relationships are 1:* relationships across tables; an insert across
-- such a relationship may therefore contain multiple rows; 'RelIns' is
-- therefore parameterized by a 'MultiObjectInsert'.
type ArrayRelationInsert b v = RelationInsert b (MultiObjectInsert b v)

-- | Old-style representation used for non-recursive insertions.
-- This is the representation used by RQL.DML, instead of the new fancy
-- recursive one present in this file. Postgres supports both representations,
-- and actually translates recursive queries that do not have any relationships
-- into this representation first.
data InsertQueryP1 (b :: BackendType) = InsertQueryP1
  { forall (b :: BackendType). InsertQueryP1 b -> TableName b
iqp1Table :: TableName b,
    forall (b :: BackendType). InsertQueryP1 b -> [Column b]
iqp1Cols :: [Column b],
    forall (b :: BackendType). InsertQueryP1 b -> [[SQLExpression b]]
iqp1Tuples :: [[SQLExpression b]],
    forall (b :: BackendType).
InsertQueryP1 b -> Maybe (OnConflictClause b (SQLExpression b))
iqp1Conflict :: Maybe (OnConflictClause b (SQLExpression b)),
    forall (b :: BackendType).
InsertQueryP1 b -> (AnnBoolExpSQL b, Maybe (AnnBoolExpSQL b))
iqp1CheckCond :: (AnnBoolExpSQL b, Maybe (AnnBoolExpSQL b)),
    forall (b :: BackendType). InsertQueryP1 b -> MutationOutput b
iqp1Output :: MutationOutput b,
    forall (b :: BackendType). InsertQueryP1 b -> [ColumnInfo b]
iqp1AllCols :: [ColumnInfo b]
  }

$(makeLenses ''AnnotatedInsert)
$(makePrisms ''AnnotatedInsertField)

getInsertColumns :: AnnotatedInsertRow b v -> [(Column b, v)]
getInsertColumns :: forall (b :: BackendType) v.
AnnotatedInsertRow b v -> [(Column b, v)]
getInsertColumns = (AnnotatedInsertField b v -> Maybe (Column b, v))
-> [AnnotatedInsertField b v] -> [(Column b, v)]
forall a b. (a -> Maybe b) -> [a] -> [b]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (AnnotatedInsertField b v
-> Getting
     (First (Column b, v)) (AnnotatedInsertField b v) (Column b, v)
-> Maybe (Column b, v)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting
  (First (Column b, v)) (AnnotatedInsertField b v) (Column b, v)
forall (b :: BackendType) v (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (Column b, v) (f (Column b, v))
-> p (AnnotatedInsertField b v) (f (AnnotatedInsertField b v))
_AIColumn)

getInsertObjectRelationships :: AnnotatedInsertRow b v -> [ObjectRelationInsert b v]
getInsertObjectRelationships :: forall (b :: BackendType) v.
AnnotatedInsertRow b v -> [ObjectRelationInsert b v]
getInsertObjectRelationships = (AnnotatedInsertField b v -> Maybe (ObjectRelationInsert b v))
-> [AnnotatedInsertField b v] -> [ObjectRelationInsert b v]
forall a b. (a -> Maybe b) -> [a] -> [b]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (((XNestedInserts b, ObjectRelationInsert b v)
 -> ObjectRelationInsert b v)
-> Maybe (XNestedInserts b, ObjectRelationInsert b v)
-> Maybe (ObjectRelationInsert b v)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (XNestedInserts b, ObjectRelationInsert b v)
-> ObjectRelationInsert b v
forall a b. (a, b) -> b
snd (Maybe (XNestedInserts b, ObjectRelationInsert b v)
 -> Maybe (ObjectRelationInsert b v))
-> (AnnotatedInsertField b v
    -> Maybe (XNestedInserts b, ObjectRelationInsert b v))
-> AnnotatedInsertField b v
-> Maybe (ObjectRelationInsert b v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AnnotatedInsertField b v
-> Getting
     (First (XNestedInserts b, ObjectRelationInsert b v))
     (AnnotatedInsertField b v)
     (XNestedInserts b, ObjectRelationInsert b v)
-> Maybe (XNestedInserts b, ObjectRelationInsert b v)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting
  (First (XNestedInserts b, ObjectRelationInsert b v))
  (AnnotatedInsertField b v)
  (XNestedInserts b, ObjectRelationInsert b v)
forall (b :: BackendType) v (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (XNestedInserts b, ObjectRelationInsert b v)
  (f (XNestedInserts b, ObjectRelationInsert b v))
-> p (AnnotatedInsertField b v) (f (AnnotatedInsertField b v))
_AIObjectRelationship))

getInsertArrayRelationships :: AnnotatedInsertRow b v -> [ArrayRelationInsert b v]
getInsertArrayRelationships :: forall (b :: BackendType) v.
AnnotatedInsertRow b v -> [ArrayRelationInsert b v]
getInsertArrayRelationships = (AnnotatedInsertField b v -> Maybe (ArrayRelationInsert b v))
-> [AnnotatedInsertField b v] -> [ArrayRelationInsert b v]
forall a b. (a -> Maybe b) -> [a] -> [b]
forall (f :: * -> *) a b.
Filterable f =>
(a -> Maybe b) -> f a -> f b
mapMaybe (((XNestedInserts b, ArrayRelationInsert b v)
 -> ArrayRelationInsert b v)
-> Maybe (XNestedInserts b, ArrayRelationInsert b v)
-> Maybe (ArrayRelationInsert b v)
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (XNestedInserts b, ArrayRelationInsert b v)
-> ArrayRelationInsert b v
forall a b. (a, b) -> b
snd (Maybe (XNestedInserts b, ArrayRelationInsert b v)
 -> Maybe (ArrayRelationInsert b v))
-> (AnnotatedInsertField b v
    -> Maybe (XNestedInserts b, ArrayRelationInsert b v))
-> AnnotatedInsertField b v
-> Maybe (ArrayRelationInsert b v)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (AnnotatedInsertField b v
-> Getting
     (First (XNestedInserts b, ArrayRelationInsert b v))
     (AnnotatedInsertField b v)
     (XNestedInserts b, ArrayRelationInsert b v)
-> Maybe (XNestedInserts b, ArrayRelationInsert b v)
forall s a. s -> Getting (First a) s a -> Maybe a
^? Getting
  (First (XNestedInserts b, ArrayRelationInsert b v))
  (AnnotatedInsertField b v)
  (XNestedInserts b, ArrayRelationInsert b v)
forall (b :: BackendType) v (p :: * -> * -> *) (f :: * -> *).
(Choice p, Applicative f) =>
p (XNestedInserts b, ArrayRelationInsert b v)
  (f (XNestedInserts b, ArrayRelationInsert b v))
-> p (AnnotatedInsertField b v) (f (AnnotatedInsertField b v))
_AIArrayRelationship))