-- | MSSQL Types Update
--
-- This module defines the Update-related IR types specific to MSSQL.
module Hasura.Backends.MSSQL.Types.Update
  ( UpdateOperator (..),
    Update (..),
    UpdateSet,
    UpdateOutput,
  )
where

import Hasura.Backends.MSSQL.Types.Instances ()
import Hasura.Backends.MSSQL.Types.Internal
import Hasura.Prelude

-- | The various @update operators@ supported by MSSQL,
-- i.e. the @_set@, @_inc@ operators that appear in the schema.
--
-- TODO: Docs for MSSQL!
-- See <https://hasura.io/docs/latest/graphql/core/databases/postgres/mutations/update.html#postgres-update-mutation Update Mutations User docs>
data UpdateOperator v
  = UpdateSet v
  | UpdateInc v
  deriving ((forall a b. (a -> b) -> UpdateOperator a -> UpdateOperator b)
-> (forall a b. a -> UpdateOperator b -> UpdateOperator a)
-> Functor UpdateOperator
forall a b. a -> UpdateOperator b -> UpdateOperator a
forall a b. (a -> b) -> UpdateOperator a -> UpdateOperator 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) -> UpdateOperator a -> UpdateOperator b
fmap :: forall a b. (a -> b) -> UpdateOperator a -> UpdateOperator b
$c<$ :: forall a b. a -> UpdateOperator b -> UpdateOperator a
<$ :: forall a b. a -> UpdateOperator b -> UpdateOperator a
Functor, (forall m. Monoid m => UpdateOperator m -> m)
-> (forall m a. Monoid m => (a -> m) -> UpdateOperator a -> m)
-> (forall m a. Monoid m => (a -> m) -> UpdateOperator a -> m)
-> (forall a b. (a -> b -> b) -> b -> UpdateOperator a -> b)
-> (forall a b. (a -> b -> b) -> b -> UpdateOperator a -> b)
-> (forall b a. (b -> a -> b) -> b -> UpdateOperator a -> b)
-> (forall b a. (b -> a -> b) -> b -> UpdateOperator a -> b)
-> (forall a. (a -> a -> a) -> UpdateOperator a -> a)
-> (forall a. (a -> a -> a) -> UpdateOperator a -> a)
-> (forall a. UpdateOperator a -> [a])
-> (forall a. UpdateOperator a -> Bool)
-> (forall a. UpdateOperator a -> Int)
-> (forall a. Eq a => a -> UpdateOperator a -> Bool)
-> (forall a. Ord a => UpdateOperator a -> a)
-> (forall a. Ord a => UpdateOperator a -> a)
-> (forall a. Num a => UpdateOperator a -> a)
-> (forall a. Num a => UpdateOperator a -> a)
-> Foldable UpdateOperator
forall a. Eq a => a -> UpdateOperator a -> Bool
forall a. Num a => UpdateOperator a -> a
forall a. Ord a => UpdateOperator a -> a
forall m. Monoid m => UpdateOperator m -> m
forall a. UpdateOperator a -> Bool
forall a. UpdateOperator a -> Int
forall a. UpdateOperator a -> [a]
forall a. (a -> a -> a) -> UpdateOperator a -> a
forall m a. Monoid m => (a -> m) -> UpdateOperator a -> m
forall b a. (b -> a -> b) -> b -> UpdateOperator a -> b
forall a b. (a -> b -> b) -> b -> UpdateOperator 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 => UpdateOperator m -> m
fold :: forall m. Monoid m => UpdateOperator m -> m
$cfoldMap :: forall m a. Monoid m => (a -> m) -> UpdateOperator a -> m
foldMap :: forall m a. Monoid m => (a -> m) -> UpdateOperator a -> m
$cfoldMap' :: forall m a. Monoid m => (a -> m) -> UpdateOperator a -> m
foldMap' :: forall m a. Monoid m => (a -> m) -> UpdateOperator a -> m
$cfoldr :: forall a b. (a -> b -> b) -> b -> UpdateOperator a -> b
foldr :: forall a b. (a -> b -> b) -> b -> UpdateOperator a -> b
$cfoldr' :: forall a b. (a -> b -> b) -> b -> UpdateOperator a -> b
foldr' :: forall a b. (a -> b -> b) -> b -> UpdateOperator a -> b
$cfoldl :: forall b a. (b -> a -> b) -> b -> UpdateOperator a -> b
foldl :: forall b a. (b -> a -> b) -> b -> UpdateOperator a -> b
$cfoldl' :: forall b a. (b -> a -> b) -> b -> UpdateOperator a -> b
foldl' :: forall b a. (b -> a -> b) -> b -> UpdateOperator a -> b
$cfoldr1 :: forall a. (a -> a -> a) -> UpdateOperator a -> a
foldr1 :: forall a. (a -> a -> a) -> UpdateOperator a -> a
$cfoldl1 :: forall a. (a -> a -> a) -> UpdateOperator a -> a
foldl1 :: forall a. (a -> a -> a) -> UpdateOperator a -> a
$ctoList :: forall a. UpdateOperator a -> [a]
toList :: forall a. UpdateOperator a -> [a]
$cnull :: forall a. UpdateOperator a -> Bool
null :: forall a. UpdateOperator a -> Bool
$clength :: forall a. UpdateOperator a -> Int
length :: forall a. UpdateOperator a -> Int
$celem :: forall a. Eq a => a -> UpdateOperator a -> Bool
elem :: forall a. Eq a => a -> UpdateOperator a -> Bool
$cmaximum :: forall a. Ord a => UpdateOperator a -> a
maximum :: forall a. Ord a => UpdateOperator a -> a
$cminimum :: forall a. Ord a => UpdateOperator a -> a
minimum :: forall a. Ord a => UpdateOperator a -> a
$csum :: forall a. Num a => UpdateOperator a -> a
sum :: forall a. Num a => UpdateOperator a -> a
$cproduct :: forall a. Num a => UpdateOperator a -> a
product :: forall a. Num a => UpdateOperator a -> a
Foldable, Functor UpdateOperator
Foldable UpdateOperator
Functor UpdateOperator
-> Foldable UpdateOperator
-> (forall (f :: * -> *) a b.
    Applicative f =>
    (a -> f b) -> UpdateOperator a -> f (UpdateOperator b))
-> (forall (f :: * -> *) a.
    Applicative f =>
    UpdateOperator (f a) -> f (UpdateOperator a))
-> (forall (m :: * -> *) a b.
    Monad m =>
    (a -> m b) -> UpdateOperator a -> m (UpdateOperator b))
-> (forall (m :: * -> *) a.
    Monad m =>
    UpdateOperator (m a) -> m (UpdateOperator a))
-> Traversable UpdateOperator
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 =>
UpdateOperator (m a) -> m (UpdateOperator a)
forall (f :: * -> *) a.
Applicative f =>
UpdateOperator (f a) -> f (UpdateOperator a)
forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UpdateOperator a -> m (UpdateOperator b)
forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UpdateOperator a -> f (UpdateOperator b)
$ctraverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UpdateOperator a -> f (UpdateOperator b)
traverse :: forall (f :: * -> *) a b.
Applicative f =>
(a -> f b) -> UpdateOperator a -> f (UpdateOperator b)
$csequenceA :: forall (f :: * -> *) a.
Applicative f =>
UpdateOperator (f a) -> f (UpdateOperator a)
sequenceA :: forall (f :: * -> *) a.
Applicative f =>
UpdateOperator (f a) -> f (UpdateOperator a)
$cmapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UpdateOperator a -> m (UpdateOperator b)
mapM :: forall (m :: * -> *) a b.
Monad m =>
(a -> m b) -> UpdateOperator a -> m (UpdateOperator b)
$csequence :: forall (m :: * -> *) a.
Monad m =>
UpdateOperator (m a) -> m (UpdateOperator a)
sequence :: forall (m :: * -> *) a.
Monad m =>
UpdateOperator (m a) -> m (UpdateOperator a)
Traversable, (forall x. UpdateOperator v -> Rep (UpdateOperator v) x)
-> (forall x. Rep (UpdateOperator v) x -> UpdateOperator v)
-> Generic (UpdateOperator v)
forall x. Rep (UpdateOperator v) x -> UpdateOperator v
forall x. UpdateOperator v -> Rep (UpdateOperator v) x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
forall v x. Rep (UpdateOperator v) x -> UpdateOperator v
forall v x. UpdateOperator v -> Rep (UpdateOperator v) x
$cfrom :: forall v x. UpdateOperator v -> Rep (UpdateOperator v) x
from :: forall x. UpdateOperator v -> Rep (UpdateOperator v) x
$cto :: forall v x. Rep (UpdateOperator v) x -> UpdateOperator v
to :: forall x. Rep (UpdateOperator v) x -> UpdateOperator v
Generic, Typeable (UpdateOperator v)
Typeable (UpdateOperator v)
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g)
    -> UpdateOperator v
    -> c (UpdateOperator v))
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c (UpdateOperator v))
-> (UpdateOperator v -> Constr)
-> (UpdateOperator v -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c (UpdateOperator v)))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e))
    -> Maybe (c (UpdateOperator v)))
-> ((forall b. Data b => b -> b)
    -> UpdateOperator v -> UpdateOperator v)
-> (forall r r'.
    (r -> r' -> r)
    -> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r)
-> (forall r r'.
    (r' -> r -> r)
    -> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r)
-> (forall u.
    (forall d. Data d => d -> u) -> UpdateOperator v -> [u])
-> (forall u.
    Int -> (forall d. Data d => d -> u) -> UpdateOperator v -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d)
    -> UpdateOperator v -> m (UpdateOperator v))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> UpdateOperator v -> m (UpdateOperator v))
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d)
    -> UpdateOperator v -> m (UpdateOperator v))
-> Data (UpdateOperator v)
UpdateOperator v -> Constr
UpdateOperator v -> DataType
(forall b. Data b => b -> b)
-> UpdateOperator v -> UpdateOperator v
forall {v}. Data v => Typeable (UpdateOperator v)
forall v. Data v => UpdateOperator v -> Constr
forall v. Data v => UpdateOperator v -> DataType
forall v.
Data v =>
(forall b. Data b => b -> b)
-> UpdateOperator v -> UpdateOperator v
forall v u.
Data v =>
Int -> (forall d. Data d => d -> u) -> UpdateOperator v -> u
forall v u.
Data v =>
(forall d. Data d => d -> u) -> UpdateOperator v -> [u]
forall v r r'.
Data v =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
forall v r r'.
Data v =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
forall v (m :: * -> *).
(Data v, Monad m) =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
forall v (m :: * -> *).
(Data v, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
forall v (c :: * -> *).
Data v =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpdateOperator v)
forall v (c :: * -> *).
Data v =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpdateOperator v -> c (UpdateOperator v)
forall v (t :: * -> *) (c :: * -> *).
(Data v, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (UpdateOperator v))
forall v (t :: * -> * -> *) (c :: * -> *).
(Data v, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpdateOperator v))
forall a.
Typeable a
-> (forall (c :: * -> *).
    (forall d b. Data d => c (d -> b) -> d -> c b)
    -> (forall g. g -> c g) -> a -> c a)
-> (forall (c :: * -> *).
    (forall b r. Data b => c (b -> r) -> c r)
    -> (forall r. r -> c r) -> Constr -> c a)
-> (a -> Constr)
-> (a -> DataType)
-> (forall (t :: * -> *) (c :: * -> *).
    Typeable t =>
    (forall d. Data d => c (t d)) -> Maybe (c a))
-> (forall (t :: * -> * -> *) (c :: * -> *).
    Typeable t =>
    (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c a))
-> ((forall b. Data b => b -> b) -> a -> a)
-> (forall r r'.
    (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall r r'.
    (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> a -> r)
-> (forall u. (forall d. Data d => d -> u) -> a -> [u])
-> (forall u. Int -> (forall d. Data d => d -> u) -> a -> u)
-> (forall (m :: * -> *).
    Monad m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> (forall (m :: * -> *).
    MonadPlus m =>
    (forall d. Data d => d -> m d) -> a -> m a)
-> Data a
forall u.
Int -> (forall d. Data d => d -> u) -> UpdateOperator v -> u
forall u. (forall d. Data d => d -> u) -> UpdateOperator v -> [u]
forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpdateOperator v)
forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpdateOperator v -> c (UpdateOperator v)
forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (UpdateOperator v))
forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpdateOperator v))
$cgfoldl :: forall v (c :: * -> *).
Data v =>
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpdateOperator v -> c (UpdateOperator v)
gfoldl :: forall (c :: * -> *).
(forall d b. Data d => c (d -> b) -> d -> c b)
-> (forall g. g -> c g) -> UpdateOperator v -> c (UpdateOperator v)
$cgunfold :: forall v (c :: * -> *).
Data v =>
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpdateOperator v)
gunfold :: forall (c :: * -> *).
(forall b r. Data b => c (b -> r) -> c r)
-> (forall r. r -> c r) -> Constr -> c (UpdateOperator v)
$ctoConstr :: forall v. Data v => UpdateOperator v -> Constr
toConstr :: UpdateOperator v -> Constr
$cdataTypeOf :: forall v. Data v => UpdateOperator v -> DataType
dataTypeOf :: UpdateOperator v -> DataType
$cdataCast1 :: forall v (t :: * -> *) (c :: * -> *).
(Data v, Typeable t) =>
(forall d. Data d => c (t d)) -> Maybe (c (UpdateOperator v))
dataCast1 :: forall (t :: * -> *) (c :: * -> *).
Typeable t =>
(forall d. Data d => c (t d)) -> Maybe (c (UpdateOperator v))
$cdataCast2 :: forall v (t :: * -> * -> *) (c :: * -> *).
(Data v, Typeable t) =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpdateOperator v))
dataCast2 :: forall (t :: * -> * -> *) (c :: * -> *).
Typeable t =>
(forall d e. (Data d, Data e) => c (t d e))
-> Maybe (c (UpdateOperator v))
$cgmapT :: forall v.
Data v =>
(forall b. Data b => b -> b)
-> UpdateOperator v -> UpdateOperator v
gmapT :: (forall b. Data b => b -> b)
-> UpdateOperator v -> UpdateOperator v
$cgmapQl :: forall v r r'.
Data v =>
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
gmapQl :: forall r r'.
(r -> r' -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
$cgmapQr :: forall v r r'.
Data v =>
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
gmapQr :: forall r r'.
(r' -> r -> r)
-> r -> (forall d. Data d => d -> r') -> UpdateOperator v -> r
$cgmapQ :: forall v u.
Data v =>
(forall d. Data d => d -> u) -> UpdateOperator v -> [u]
gmapQ :: forall u. (forall d. Data d => d -> u) -> UpdateOperator v -> [u]
$cgmapQi :: forall v u.
Data v =>
Int -> (forall d. Data d => d -> u) -> UpdateOperator v -> u
gmapQi :: forall u.
Int -> (forall d. Data d => d -> u) -> UpdateOperator v -> u
$cgmapM :: forall v (m :: * -> *).
(Data v, Monad m) =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
gmapM :: forall (m :: * -> *).
Monad m =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
$cgmapMp :: forall v (m :: * -> *).
(Data v, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
gmapMp :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
$cgmapMo :: forall v (m :: * -> *).
(Data v, MonadPlus m) =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
gmapMo :: forall (m :: * -> *).
MonadPlus m =>
(forall d. Data d => d -> m d)
-> UpdateOperator v -> m (UpdateOperator v)
Data)

type UpdateSet = HashMap ColumnName (UpdateOperator Expression)

type UpdateOutput = Output Inserted

-- | UPDATE [table_alias] SET [table_alias].column = 'value' OUTPUT INSERTED.column INTO #updated
-- FROM [table_name] AS [table_alias] WHERE <filter-expression>
data Update = Update
  { Update -> Aliased TableName
updateTable :: Aliased TableName,
    Update -> UpdateSet
updateSet :: UpdateSet,
    Update -> UpdateOutput
updateOutput :: UpdateOutput,
    Update -> TempTable
updateTempTable :: TempTable,
    Update -> Where
updateWhere :: Where
  }