{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# OPTIONS_GHC -fno-warn-unused-binds #-}
{-# OPTIONS_GHC -fno-warn-unused-imports #-}
{-# OPTIONS_GHC -fno-warn-unused-matches #-}

-- Derived from AWS service descriptions, licensed under Apache 2.0.

-- |
-- Module      : Amazonka.RedshiftData.ExecuteStatement
-- Copyright   : (c) 2013-2021 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay <brendan.g.hay+amazonka@gmail.com>
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Runs an SQL statement, which can be data manipulation language (DML) or
-- data definition language (DDL). This statement must be a single SQL
-- statement. Depending on the authorization method, use one of the
-- following combinations of request parameters:
--
-- -   Secrets Manager - specify the Amazon Resource Name (ARN) of the
--     secret, the database name, and the cluster identifier that matches
--     the cluster in the secret.
--
-- -   Temporary credentials - specify the cluster identifier, the database
--     name, and the database user name. Permission to call the
--     @redshift:GetClusterCredentials@ operation is required to use this
--     method.
module Amazonka.RedshiftData.ExecuteStatement
  ( -- * Creating a Request
    ExecuteStatement (..),
    newExecuteStatement,

    -- * Request Lenses
    executeStatement_dbUser,
    executeStatement_statementName,
    executeStatement_parameters,
    executeStatement_secretArn,
    executeStatement_withEvent,
    executeStatement_clusterIdentifier,
    executeStatement_database,
    executeStatement_sql,

    -- * Destructuring the Response
    ExecuteStatementResponse (..),
    newExecuteStatementResponse,

    -- * Response Lenses
    executeStatementResponse_dbUser,
    executeStatementResponse_database,
    executeStatementResponse_createdAt,
    executeStatementResponse_clusterIdentifier,
    executeStatementResponse_id,
    executeStatementResponse_secretArn,
    executeStatementResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.RedshiftData.Types
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newExecuteStatement' smart constructor.
data ExecuteStatement = ExecuteStatement'
  { -- | The database user name. This parameter is required when authenticating
    -- using temporary credentials.
    ExecuteStatement -> Maybe Text
dbUser :: Prelude.Maybe Prelude.Text,
    -- | The name of the SQL statement. You can name the SQL statement when you
    -- create it to identify the query.
    ExecuteStatement -> Maybe Text
statementName :: Prelude.Maybe Prelude.Text,
    -- | The parameters for the SQL statement.
    ExecuteStatement -> Maybe (NonEmpty SqlParameter)
parameters :: Prelude.Maybe (Prelude.NonEmpty SqlParameter),
    -- | The name or ARN of the secret that enables access to the database. This
    -- parameter is required when authenticating using Secrets Manager.
    ExecuteStatement -> Maybe Text
secretArn :: Prelude.Maybe Prelude.Text,
    -- | A value that indicates whether to send an event to the Amazon
    -- EventBridge event bus after the SQL statement runs.
    ExecuteStatement -> Maybe Bool
withEvent :: Prelude.Maybe Prelude.Bool,
    -- | The cluster identifier. This parameter is required when authenticating
    -- using either Secrets Manager or temporary credentials.
    ExecuteStatement -> Text
clusterIdentifier :: Prelude.Text,
    -- | The name of the database. This parameter is required when authenticating
    -- using either Secrets Manager or temporary credentials.
    ExecuteStatement -> Text
database :: Prelude.Text,
    -- | The SQL statement text to run.
    ExecuteStatement -> Text
sql :: Prelude.Text
  }
  deriving (ExecuteStatement -> ExecuteStatement -> Bool
(ExecuteStatement -> ExecuteStatement -> Bool)
-> (ExecuteStatement -> ExecuteStatement -> Bool)
-> Eq ExecuteStatement
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExecuteStatement -> ExecuteStatement -> Bool
$c/= :: ExecuteStatement -> ExecuteStatement -> Bool
== :: ExecuteStatement -> ExecuteStatement -> Bool
$c== :: ExecuteStatement -> ExecuteStatement -> Bool
Prelude.Eq, ReadPrec [ExecuteStatement]
ReadPrec ExecuteStatement
Int -> ReadS ExecuteStatement
ReadS [ExecuteStatement]
(Int -> ReadS ExecuteStatement)
-> ReadS [ExecuteStatement]
-> ReadPrec ExecuteStatement
-> ReadPrec [ExecuteStatement]
-> Read ExecuteStatement
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExecuteStatement]
$creadListPrec :: ReadPrec [ExecuteStatement]
readPrec :: ReadPrec ExecuteStatement
$creadPrec :: ReadPrec ExecuteStatement
readList :: ReadS [ExecuteStatement]
$creadList :: ReadS [ExecuteStatement]
readsPrec :: Int -> ReadS ExecuteStatement
$creadsPrec :: Int -> ReadS ExecuteStatement
Prelude.Read, Int -> ExecuteStatement -> ShowS
[ExecuteStatement] -> ShowS
ExecuteStatement -> String
(Int -> ExecuteStatement -> ShowS)
-> (ExecuteStatement -> String)
-> ([ExecuteStatement] -> ShowS)
-> Show ExecuteStatement
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExecuteStatement] -> ShowS
$cshowList :: [ExecuteStatement] -> ShowS
show :: ExecuteStatement -> String
$cshow :: ExecuteStatement -> String
showsPrec :: Int -> ExecuteStatement -> ShowS
$cshowsPrec :: Int -> ExecuteStatement -> ShowS
Prelude.Show, (forall x. ExecuteStatement -> Rep ExecuteStatement x)
-> (forall x. Rep ExecuteStatement x -> ExecuteStatement)
-> Generic ExecuteStatement
forall x. Rep ExecuteStatement x -> ExecuteStatement
forall x. ExecuteStatement -> Rep ExecuteStatement x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep ExecuteStatement x -> ExecuteStatement
$cfrom :: forall x. ExecuteStatement -> Rep ExecuteStatement x
Prelude.Generic)

-- |
-- Create a value of 'ExecuteStatement' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'dbUser', 'executeStatement_dbUser' - The database user name. This parameter is required when authenticating
-- using temporary credentials.
--
-- 'statementName', 'executeStatement_statementName' - The name of the SQL statement. You can name the SQL statement when you
-- create it to identify the query.
--
-- 'parameters', 'executeStatement_parameters' - The parameters for the SQL statement.
--
-- 'secretArn', 'executeStatement_secretArn' - The name or ARN of the secret that enables access to the database. This
-- parameter is required when authenticating using Secrets Manager.
--
-- 'withEvent', 'executeStatement_withEvent' - A value that indicates whether to send an event to the Amazon
-- EventBridge event bus after the SQL statement runs.
--
-- 'clusterIdentifier', 'executeStatement_clusterIdentifier' - The cluster identifier. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
--
-- 'database', 'executeStatement_database' - The name of the database. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
--
-- 'sql', 'executeStatement_sql' - The SQL statement text to run.
newExecuteStatement ::
  -- | 'clusterIdentifier'
  Prelude.Text ->
  -- | 'database'
  Prelude.Text ->
  -- | 'sql'
  Prelude.Text ->
  ExecuteStatement
newExecuteStatement :: Text -> Text -> Text -> ExecuteStatement
newExecuteStatement
  Text
pClusterIdentifier_
  Text
pDatabase_
  Text
pSql_ =
    ExecuteStatement' :: Maybe Text
-> Maybe Text
-> Maybe (NonEmpty SqlParameter)
-> Maybe Text
-> Maybe Bool
-> Text
-> Text
-> Text
-> ExecuteStatement
ExecuteStatement'
      { $sel:dbUser:ExecuteStatement' :: Maybe Text
dbUser = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:statementName:ExecuteStatement' :: Maybe Text
statementName = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:parameters:ExecuteStatement' :: Maybe (NonEmpty SqlParameter)
parameters = Maybe (NonEmpty SqlParameter)
forall a. Maybe a
Prelude.Nothing,
        $sel:secretArn:ExecuteStatement' :: Maybe Text
secretArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:withEvent:ExecuteStatement' :: Maybe Bool
withEvent = Maybe Bool
forall a. Maybe a
Prelude.Nothing,
        $sel:clusterIdentifier:ExecuteStatement' :: Text
clusterIdentifier = Text
pClusterIdentifier_,
        $sel:database:ExecuteStatement' :: Text
database = Text
pDatabase_,
        $sel:sql:ExecuteStatement' :: Text
sql = Text
pSql_
      }

-- | The database user name. This parameter is required when authenticating
-- using temporary credentials.
executeStatement_dbUser :: Lens.Lens' ExecuteStatement (Prelude.Maybe Prelude.Text)
executeStatement_dbUser :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatement -> f ExecuteStatement
executeStatement_dbUser = (ExecuteStatement -> Maybe Text)
-> (ExecuteStatement -> Maybe Text -> ExecuteStatement)
-> Lens ExecuteStatement ExecuteStatement (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Maybe Text
dbUser :: Maybe Text
$sel:dbUser:ExecuteStatement' :: ExecuteStatement -> Maybe Text
dbUser} -> Maybe Text
dbUser) (\s :: ExecuteStatement
s@ExecuteStatement' {} Maybe Text
a -> ExecuteStatement
s {$sel:dbUser:ExecuteStatement' :: Maybe Text
dbUser = Maybe Text
a} :: ExecuteStatement)

-- | The name of the SQL statement. You can name the SQL statement when you
-- create it to identify the query.
executeStatement_statementName :: Lens.Lens' ExecuteStatement (Prelude.Maybe Prelude.Text)
executeStatement_statementName :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatement -> f ExecuteStatement
executeStatement_statementName = (ExecuteStatement -> Maybe Text)
-> (ExecuteStatement -> Maybe Text -> ExecuteStatement)
-> Lens ExecuteStatement ExecuteStatement (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Maybe Text
statementName :: Maybe Text
$sel:statementName:ExecuteStatement' :: ExecuteStatement -> Maybe Text
statementName} -> Maybe Text
statementName) (\s :: ExecuteStatement
s@ExecuteStatement' {} Maybe Text
a -> ExecuteStatement
s {$sel:statementName:ExecuteStatement' :: Maybe Text
statementName = Maybe Text
a} :: ExecuteStatement)

-- | The parameters for the SQL statement.
executeStatement_parameters :: Lens.Lens' ExecuteStatement (Prelude.Maybe (Prelude.NonEmpty SqlParameter))
executeStatement_parameters :: (Maybe (NonEmpty SqlParameter)
 -> f (Maybe (NonEmpty SqlParameter)))
-> ExecuteStatement -> f ExecuteStatement
executeStatement_parameters = (ExecuteStatement -> Maybe (NonEmpty SqlParameter))
-> (ExecuteStatement
    -> Maybe (NonEmpty SqlParameter) -> ExecuteStatement)
-> Lens
     ExecuteStatement
     ExecuteStatement
     (Maybe (NonEmpty SqlParameter))
     (Maybe (NonEmpty SqlParameter))
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Maybe (NonEmpty SqlParameter)
parameters :: Maybe (NonEmpty SqlParameter)
$sel:parameters:ExecuteStatement' :: ExecuteStatement -> Maybe (NonEmpty SqlParameter)
parameters} -> Maybe (NonEmpty SqlParameter)
parameters) (\s :: ExecuteStatement
s@ExecuteStatement' {} Maybe (NonEmpty SqlParameter)
a -> ExecuteStatement
s {$sel:parameters:ExecuteStatement' :: Maybe (NonEmpty SqlParameter)
parameters = Maybe (NonEmpty SqlParameter)
a} :: ExecuteStatement) ((Maybe (NonEmpty SqlParameter)
  -> f (Maybe (NonEmpty SqlParameter)))
 -> ExecuteStatement -> f ExecuteStatement)
-> ((Maybe (NonEmpty SqlParameter)
     -> f (Maybe (NonEmpty SqlParameter)))
    -> Maybe (NonEmpty SqlParameter)
    -> f (Maybe (NonEmpty SqlParameter)))
-> (Maybe (NonEmpty SqlParameter)
    -> f (Maybe (NonEmpty SqlParameter)))
-> ExecuteStatement
-> f ExecuteStatement
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso
  (NonEmpty SqlParameter)
  (NonEmpty SqlParameter)
  (NonEmpty SqlParameter)
  (NonEmpty SqlParameter)
-> Iso
     (Maybe (NonEmpty SqlParameter))
     (Maybe (NonEmpty SqlParameter))
     (Maybe (NonEmpty SqlParameter))
     (Maybe (NonEmpty SqlParameter))
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso
  (NonEmpty SqlParameter)
  (NonEmpty SqlParameter)
  (NonEmpty SqlParameter)
  (NonEmpty SqlParameter)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The name or ARN of the secret that enables access to the database. This
-- parameter is required when authenticating using Secrets Manager.
executeStatement_secretArn :: Lens.Lens' ExecuteStatement (Prelude.Maybe Prelude.Text)
executeStatement_secretArn :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatement -> f ExecuteStatement
executeStatement_secretArn = (ExecuteStatement -> Maybe Text)
-> (ExecuteStatement -> Maybe Text -> ExecuteStatement)
-> Lens ExecuteStatement ExecuteStatement (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Maybe Text
secretArn :: Maybe Text
$sel:secretArn:ExecuteStatement' :: ExecuteStatement -> Maybe Text
secretArn} -> Maybe Text
secretArn) (\s :: ExecuteStatement
s@ExecuteStatement' {} Maybe Text
a -> ExecuteStatement
s {$sel:secretArn:ExecuteStatement' :: Maybe Text
secretArn = Maybe Text
a} :: ExecuteStatement)

-- | A value that indicates whether to send an event to the Amazon
-- EventBridge event bus after the SQL statement runs.
executeStatement_withEvent :: Lens.Lens' ExecuteStatement (Prelude.Maybe Prelude.Bool)
executeStatement_withEvent :: (Maybe Bool -> f (Maybe Bool))
-> ExecuteStatement -> f ExecuteStatement
executeStatement_withEvent = (ExecuteStatement -> Maybe Bool)
-> (ExecuteStatement -> Maybe Bool -> ExecuteStatement)
-> Lens ExecuteStatement ExecuteStatement (Maybe Bool) (Maybe Bool)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Maybe Bool
withEvent :: Maybe Bool
$sel:withEvent:ExecuteStatement' :: ExecuteStatement -> Maybe Bool
withEvent} -> Maybe Bool
withEvent) (\s :: ExecuteStatement
s@ExecuteStatement' {} Maybe Bool
a -> ExecuteStatement
s {$sel:withEvent:ExecuteStatement' :: Maybe Bool
withEvent = Maybe Bool
a} :: ExecuteStatement)

-- | The cluster identifier. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
executeStatement_clusterIdentifier :: Lens.Lens' ExecuteStatement Prelude.Text
executeStatement_clusterIdentifier :: (Text -> f Text) -> ExecuteStatement -> f ExecuteStatement
executeStatement_clusterIdentifier = (ExecuteStatement -> Text)
-> (ExecuteStatement -> Text -> ExecuteStatement)
-> Lens ExecuteStatement ExecuteStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Text
clusterIdentifier :: Text
$sel:clusterIdentifier:ExecuteStatement' :: ExecuteStatement -> Text
clusterIdentifier} -> Text
clusterIdentifier) (\s :: ExecuteStatement
s@ExecuteStatement' {} Text
a -> ExecuteStatement
s {$sel:clusterIdentifier:ExecuteStatement' :: Text
clusterIdentifier = Text
a} :: ExecuteStatement)

-- | The name of the database. This parameter is required when authenticating
-- using either Secrets Manager or temporary credentials.
executeStatement_database :: Lens.Lens' ExecuteStatement Prelude.Text
executeStatement_database :: (Text -> f Text) -> ExecuteStatement -> f ExecuteStatement
executeStatement_database = (ExecuteStatement -> Text)
-> (ExecuteStatement -> Text -> ExecuteStatement)
-> Lens ExecuteStatement ExecuteStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Text
database :: Text
$sel:database:ExecuteStatement' :: ExecuteStatement -> Text
database} -> Text
database) (\s :: ExecuteStatement
s@ExecuteStatement' {} Text
a -> ExecuteStatement
s {$sel:database:ExecuteStatement' :: Text
database = Text
a} :: ExecuteStatement)

-- | The SQL statement text to run.
executeStatement_sql :: Lens.Lens' ExecuteStatement Prelude.Text
executeStatement_sql :: (Text -> f Text) -> ExecuteStatement -> f ExecuteStatement
executeStatement_sql = (ExecuteStatement -> Text)
-> (ExecuteStatement -> Text -> ExecuteStatement)
-> Lens ExecuteStatement ExecuteStatement Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatement' {Text
sql :: Text
$sel:sql:ExecuteStatement' :: ExecuteStatement -> Text
sql} -> Text
sql) (\s :: ExecuteStatement
s@ExecuteStatement' {} Text
a -> ExecuteStatement
s {$sel:sql:ExecuteStatement' :: Text
sql = Text
a} :: ExecuteStatement)

instance Core.AWSRequest ExecuteStatement where
  type
    AWSResponse ExecuteStatement =
      ExecuteStatementResponse
  request :: ExecuteStatement -> Request ExecuteStatement
request = Service -> ExecuteStatement -> Request ExecuteStatement
forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON Service
defaultService
  response :: Logger
-> Service
-> Proxy ExecuteStatement
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ExecuteStatement)))
response =
    (Int
 -> ResponseHeaders
 -> Object
 -> Either String (AWSResponse ExecuteStatement))
-> Logger
-> Service
-> Proxy ExecuteStatement
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse ExecuteStatement)))
forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> Logger
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Text
-> Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Int
-> ExecuteStatementResponse
ExecuteStatementResponse'
            (Maybe Text
 -> Maybe Text
 -> Maybe POSIX
 -> Maybe Text
 -> Maybe Text
 -> Maybe Text
 -> Int
 -> ExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text
      -> Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Int
      -> ExecuteStatementResponse)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"DbUser")
            Either
  String
  (Maybe Text
   -> Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Int
   -> ExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe POSIX
      -> Maybe Text
      -> Maybe Text
      -> Maybe Text
      -> Int
      -> ExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Database")
            Either
  String
  (Maybe POSIX
   -> Maybe Text
   -> Maybe Text
   -> Maybe Text
   -> Int
   -> ExecuteStatementResponse)
-> Either String (Maybe POSIX)
-> Either
     String
     (Maybe Text
      -> Maybe Text -> Maybe Text -> Int -> ExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe POSIX)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"CreatedAt")
            Either
  String
  (Maybe Text
   -> Maybe Text -> Maybe Text -> Int -> ExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either
     String
     (Maybe Text -> Maybe Text -> Int -> ExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"ClusterIdentifier")
            Either
  String
  (Maybe Text -> Maybe Text -> Int -> ExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either String (Maybe Text -> Int -> ExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"Id")
            Either String (Maybe Text -> Int -> ExecuteStatementResponse)
-> Either String (Maybe Text)
-> Either String (Int -> ExecuteStatementResponse)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Either String (Maybe Text)
forall a. FromJSON a => Object -> Text -> Either String (Maybe a)
Core..?> Text
"SecretArn")
            Either String (Int -> ExecuteStatementResponse)
-> Either String Int -> Either String ExecuteStatementResponse
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Int -> Either String Int
forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (Int -> Int
forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable ExecuteStatement

instance Prelude.NFData ExecuteStatement

instance Core.ToHeaders ExecuteStatement where
  toHeaders :: ExecuteStatement -> ResponseHeaders
toHeaders =
    ResponseHeaders -> ExecuteStatement -> ResponseHeaders
forall a b. a -> b -> a
Prelude.const
      ( [ResponseHeaders] -> ResponseHeaders
forall a. Monoid a => [a] -> a
Prelude.mconcat
          [ HeaderName
"X-Amz-Target"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"RedshiftData.ExecuteStatement" ::
                          Prelude.ByteString
                      ),
            HeaderName
"Content-Type"
              HeaderName -> ByteString -> ResponseHeaders
forall a. ToHeader a => HeaderName -> a -> ResponseHeaders
Core.=# ( ByteString
"application/x-amz-json-1.1" ::
                          Prelude.ByteString
                      )
          ]
      )

instance Core.ToJSON ExecuteStatement where
  toJSON :: ExecuteStatement -> Value
toJSON ExecuteStatement' {Maybe Bool
Maybe (NonEmpty SqlParameter)
Maybe Text
Text
sql :: Text
database :: Text
clusterIdentifier :: Text
withEvent :: Maybe Bool
secretArn :: Maybe Text
parameters :: Maybe (NonEmpty SqlParameter)
statementName :: Maybe Text
dbUser :: Maybe Text
$sel:sql:ExecuteStatement' :: ExecuteStatement -> Text
$sel:database:ExecuteStatement' :: ExecuteStatement -> Text
$sel:clusterIdentifier:ExecuteStatement' :: ExecuteStatement -> Text
$sel:withEvent:ExecuteStatement' :: ExecuteStatement -> Maybe Bool
$sel:secretArn:ExecuteStatement' :: ExecuteStatement -> Maybe Text
$sel:parameters:ExecuteStatement' :: ExecuteStatement -> Maybe (NonEmpty SqlParameter)
$sel:statementName:ExecuteStatement' :: ExecuteStatement -> Maybe Text
$sel:dbUser:ExecuteStatement' :: ExecuteStatement -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"DbUser" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
dbUser,
            (Text
"StatementName" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
statementName,
            (Text
"Parameters" Text -> NonEmpty SqlParameter -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (NonEmpty SqlParameter -> Pair)
-> Maybe (NonEmpty SqlParameter) -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe (NonEmpty SqlParameter)
parameters,
            (Text
"SecretArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Text -> Pair) -> Maybe Text -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
secretArn,
            (Text
"WithEvent" Text -> Bool -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..=) (Bool -> Pair) -> Maybe Bool -> Maybe Pair
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Bool
withEvent,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just
              (Text
"ClusterIdentifier" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
clusterIdentifier),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Database" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
database),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Sql" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
sql)
          ]
      )

instance Core.ToPath ExecuteStatement where
  toPath :: ExecuteStatement -> ByteString
toPath = ByteString -> ExecuteStatement -> ByteString
forall a b. a -> b -> a
Prelude.const ByteString
"/"

instance Core.ToQuery ExecuteStatement where
  toQuery :: ExecuteStatement -> QueryString
toQuery = QueryString -> ExecuteStatement -> QueryString
forall a b. a -> b -> a
Prelude.const QueryString
forall a. Monoid a => a
Prelude.mempty

-- | /See:/ 'newExecuteStatementResponse' smart constructor.
data ExecuteStatementResponse = ExecuteStatementResponse'
  { -- | The database user name.
    ExecuteStatementResponse -> Maybe Text
dbUser :: Prelude.Maybe Prelude.Text,
    -- | The name of the database.
    ExecuteStatementResponse -> Maybe Text
database :: Prelude.Maybe Prelude.Text,
    -- | The date and time (UTC) the statement was created.
    ExecuteStatementResponse -> Maybe POSIX
createdAt :: Prelude.Maybe Core.POSIX,
    -- | The cluster identifier.
    ExecuteStatementResponse -> Maybe Text
clusterIdentifier :: Prelude.Maybe Prelude.Text,
    -- | The identifier of the SQL statement whose results are to be fetched.
    -- This value is a universally unique identifier (UUID) generated by Amazon
    -- Redshift Data API.
    ExecuteStatementResponse -> Maybe Text
id :: Prelude.Maybe Prelude.Text,
    -- | The name or ARN of the secret that enables access to the database.
    ExecuteStatementResponse -> Maybe Text
secretArn :: Prelude.Maybe Prelude.Text,
    -- | The response's http status code.
    ExecuteStatementResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (ExecuteStatementResponse -> ExecuteStatementResponse -> Bool
(ExecuteStatementResponse -> ExecuteStatementResponse -> Bool)
-> (ExecuteStatementResponse -> ExecuteStatementResponse -> Bool)
-> Eq ExecuteStatementResponse
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ExecuteStatementResponse -> ExecuteStatementResponse -> Bool
$c/= :: ExecuteStatementResponse -> ExecuteStatementResponse -> Bool
== :: ExecuteStatementResponse -> ExecuteStatementResponse -> Bool
$c== :: ExecuteStatementResponse -> ExecuteStatementResponse -> Bool
Prelude.Eq, ReadPrec [ExecuteStatementResponse]
ReadPrec ExecuteStatementResponse
Int -> ReadS ExecuteStatementResponse
ReadS [ExecuteStatementResponse]
(Int -> ReadS ExecuteStatementResponse)
-> ReadS [ExecuteStatementResponse]
-> ReadPrec ExecuteStatementResponse
-> ReadPrec [ExecuteStatementResponse]
-> Read ExecuteStatementResponse
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [ExecuteStatementResponse]
$creadListPrec :: ReadPrec [ExecuteStatementResponse]
readPrec :: ReadPrec ExecuteStatementResponse
$creadPrec :: ReadPrec ExecuteStatementResponse
readList :: ReadS [ExecuteStatementResponse]
$creadList :: ReadS [ExecuteStatementResponse]
readsPrec :: Int -> ReadS ExecuteStatementResponse
$creadsPrec :: Int -> ReadS ExecuteStatementResponse
Prelude.Read, Int -> ExecuteStatementResponse -> ShowS
[ExecuteStatementResponse] -> ShowS
ExecuteStatementResponse -> String
(Int -> ExecuteStatementResponse -> ShowS)
-> (ExecuteStatementResponse -> String)
-> ([ExecuteStatementResponse] -> ShowS)
-> Show ExecuteStatementResponse
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ExecuteStatementResponse] -> ShowS
$cshowList :: [ExecuteStatementResponse] -> ShowS
show :: ExecuteStatementResponse -> String
$cshow :: ExecuteStatementResponse -> String
showsPrec :: Int -> ExecuteStatementResponse -> ShowS
$cshowsPrec :: Int -> ExecuteStatementResponse -> ShowS
Prelude.Show, (forall x.
 ExecuteStatementResponse -> Rep ExecuteStatementResponse x)
-> (forall x.
    Rep ExecuteStatementResponse x -> ExecuteStatementResponse)
-> Generic ExecuteStatementResponse
forall x.
Rep ExecuteStatementResponse x -> ExecuteStatementResponse
forall x.
ExecuteStatementResponse -> Rep ExecuteStatementResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x.
Rep ExecuteStatementResponse x -> ExecuteStatementResponse
$cfrom :: forall x.
ExecuteStatementResponse -> Rep ExecuteStatementResponse x
Prelude.Generic)

-- |
-- Create a value of 'ExecuteStatementResponse' with all optional fields omitted.
--
-- Use <https://hackage.haskell.org/package/generic-lens generic-lens> or <https://hackage.haskell.org/package/optics optics> to modify other optional fields.
--
-- The following record fields are available, with the corresponding lenses provided
-- for backwards compatibility:
--
-- 'dbUser', 'executeStatementResponse_dbUser' - The database user name.
--
-- 'database', 'executeStatementResponse_database' - The name of the database.
--
-- 'createdAt', 'executeStatementResponse_createdAt' - The date and time (UTC) the statement was created.
--
-- 'clusterIdentifier', 'executeStatementResponse_clusterIdentifier' - The cluster identifier.
--
-- 'id', 'executeStatementResponse_id' - The identifier of the SQL statement whose results are to be fetched.
-- This value is a universally unique identifier (UUID) generated by Amazon
-- Redshift Data API.
--
-- 'secretArn', 'executeStatementResponse_secretArn' - The name or ARN of the secret that enables access to the database.
--
-- 'httpStatus', 'executeStatementResponse_httpStatus' - The response's http status code.
newExecuteStatementResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  ExecuteStatementResponse
newExecuteStatementResponse :: Int -> ExecuteStatementResponse
newExecuteStatementResponse Int
pHttpStatus_ =
  ExecuteStatementResponse' :: Maybe Text
-> Maybe Text
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe Text
-> Int
-> ExecuteStatementResponse
ExecuteStatementResponse'
    { $sel:dbUser:ExecuteStatementResponse' :: Maybe Text
dbUser = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:database:ExecuteStatementResponse' :: Maybe Text
database = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:createdAt:ExecuteStatementResponse' :: Maybe POSIX
createdAt = Maybe POSIX
forall a. Maybe a
Prelude.Nothing,
      $sel:clusterIdentifier:ExecuteStatementResponse' :: Maybe Text
clusterIdentifier = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:id:ExecuteStatementResponse' :: Maybe Text
id = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:secretArn:ExecuteStatementResponse' :: Maybe Text
secretArn = Maybe Text
forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:ExecuteStatementResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The database user name.
executeStatementResponse_dbUser :: Lens.Lens' ExecuteStatementResponse (Prelude.Maybe Prelude.Text)
executeStatementResponse_dbUser :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatementResponse -> f ExecuteStatementResponse
executeStatementResponse_dbUser = (ExecuteStatementResponse -> Maybe Text)
-> (ExecuteStatementResponse
    -> Maybe Text -> ExecuteStatementResponse)
-> Lens
     ExecuteStatementResponse
     ExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatementResponse' {Maybe Text
dbUser :: Maybe Text
$sel:dbUser:ExecuteStatementResponse' :: ExecuteStatementResponse -> Maybe Text
dbUser} -> Maybe Text
dbUser) (\s :: ExecuteStatementResponse
s@ExecuteStatementResponse' {} Maybe Text
a -> ExecuteStatementResponse
s {$sel:dbUser:ExecuteStatementResponse' :: Maybe Text
dbUser = Maybe Text
a} :: ExecuteStatementResponse)

-- | The name of the database.
executeStatementResponse_database :: Lens.Lens' ExecuteStatementResponse (Prelude.Maybe Prelude.Text)
executeStatementResponse_database :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatementResponse -> f ExecuteStatementResponse
executeStatementResponse_database = (ExecuteStatementResponse -> Maybe Text)
-> (ExecuteStatementResponse
    -> Maybe Text -> ExecuteStatementResponse)
-> Lens
     ExecuteStatementResponse
     ExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatementResponse' {Maybe Text
database :: Maybe Text
$sel:database:ExecuteStatementResponse' :: ExecuteStatementResponse -> Maybe Text
database} -> Maybe Text
database) (\s :: ExecuteStatementResponse
s@ExecuteStatementResponse' {} Maybe Text
a -> ExecuteStatementResponse
s {$sel:database:ExecuteStatementResponse' :: Maybe Text
database = Maybe Text
a} :: ExecuteStatementResponse)

-- | The date and time (UTC) the statement was created.
executeStatementResponse_createdAt :: Lens.Lens' ExecuteStatementResponse (Prelude.Maybe Prelude.UTCTime)
executeStatementResponse_createdAt :: (Maybe UTCTime -> f (Maybe UTCTime))
-> ExecuteStatementResponse -> f ExecuteStatementResponse
executeStatementResponse_createdAt = (ExecuteStatementResponse -> Maybe POSIX)
-> (ExecuteStatementResponse
    -> Maybe POSIX -> ExecuteStatementResponse)
-> Lens
     ExecuteStatementResponse
     ExecuteStatementResponse
     (Maybe POSIX)
     (Maybe POSIX)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatementResponse' {Maybe POSIX
createdAt :: Maybe POSIX
$sel:createdAt:ExecuteStatementResponse' :: ExecuteStatementResponse -> Maybe POSIX
createdAt} -> Maybe POSIX
createdAt) (\s :: ExecuteStatementResponse
s@ExecuteStatementResponse' {} Maybe POSIX
a -> ExecuteStatementResponse
s {$sel:createdAt:ExecuteStatementResponse' :: Maybe POSIX
createdAt = Maybe POSIX
a} :: ExecuteStatementResponse) ((Maybe POSIX -> f (Maybe POSIX))
 -> ExecuteStatementResponse -> f ExecuteStatementResponse)
-> ((Maybe UTCTime -> f (Maybe UTCTime))
    -> Maybe POSIX -> f (Maybe POSIX))
-> (Maybe UTCTime -> f (Maybe UTCTime))
-> ExecuteStatementResponse
-> f ExecuteStatementResponse
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. AnIso POSIX POSIX UTCTime UTCTime
-> Iso (Maybe POSIX) (Maybe POSIX) (Maybe UTCTime) (Maybe UTCTime)
forall (f :: * -> *) (g :: * -> *) s t a b.
(Functor f, Functor g) =>
AnIso s t a b -> Iso (f s) (g t) (f a) (g b)
Lens.mapping AnIso POSIX POSIX UTCTime UTCTime
forall (a :: Format). Iso' (Time a) UTCTime
Core._Time

-- | The cluster identifier.
executeStatementResponse_clusterIdentifier :: Lens.Lens' ExecuteStatementResponse (Prelude.Maybe Prelude.Text)
executeStatementResponse_clusterIdentifier :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatementResponse -> f ExecuteStatementResponse
executeStatementResponse_clusterIdentifier = (ExecuteStatementResponse -> Maybe Text)
-> (ExecuteStatementResponse
    -> Maybe Text -> ExecuteStatementResponse)
-> Lens
     ExecuteStatementResponse
     ExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatementResponse' {Maybe Text
clusterIdentifier :: Maybe Text
$sel:clusterIdentifier:ExecuteStatementResponse' :: ExecuteStatementResponse -> Maybe Text
clusterIdentifier} -> Maybe Text
clusterIdentifier) (\s :: ExecuteStatementResponse
s@ExecuteStatementResponse' {} Maybe Text
a -> ExecuteStatementResponse
s {$sel:clusterIdentifier:ExecuteStatementResponse' :: Maybe Text
clusterIdentifier = Maybe Text
a} :: ExecuteStatementResponse)

-- | The identifier of the SQL statement whose results are to be fetched.
-- This value is a universally unique identifier (UUID) generated by Amazon
-- Redshift Data API.
executeStatementResponse_id :: Lens.Lens' ExecuteStatementResponse (Prelude.Maybe Prelude.Text)
executeStatementResponse_id :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatementResponse -> f ExecuteStatementResponse
executeStatementResponse_id = (ExecuteStatementResponse -> Maybe Text)
-> (ExecuteStatementResponse
    -> Maybe Text -> ExecuteStatementResponse)
-> Lens
     ExecuteStatementResponse
     ExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatementResponse' {Maybe Text
id :: Maybe Text
$sel:id:ExecuteStatementResponse' :: ExecuteStatementResponse -> Maybe Text
id} -> Maybe Text
id) (\s :: ExecuteStatementResponse
s@ExecuteStatementResponse' {} Maybe Text
a -> ExecuteStatementResponse
s {$sel:id:ExecuteStatementResponse' :: Maybe Text
id = Maybe Text
a} :: ExecuteStatementResponse)

-- | The name or ARN of the secret that enables access to the database.
executeStatementResponse_secretArn :: Lens.Lens' ExecuteStatementResponse (Prelude.Maybe Prelude.Text)
executeStatementResponse_secretArn :: (Maybe Text -> f (Maybe Text))
-> ExecuteStatementResponse -> f ExecuteStatementResponse
executeStatementResponse_secretArn = (ExecuteStatementResponse -> Maybe Text)
-> (ExecuteStatementResponse
    -> Maybe Text -> ExecuteStatementResponse)
-> Lens
     ExecuteStatementResponse
     ExecuteStatementResponse
     (Maybe Text)
     (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatementResponse' {Maybe Text
secretArn :: Maybe Text
$sel:secretArn:ExecuteStatementResponse' :: ExecuteStatementResponse -> Maybe Text
secretArn} -> Maybe Text
secretArn) (\s :: ExecuteStatementResponse
s@ExecuteStatementResponse' {} Maybe Text
a -> ExecuteStatementResponse
s {$sel:secretArn:ExecuteStatementResponse' :: Maybe Text
secretArn = Maybe Text
a} :: ExecuteStatementResponse)

-- | The response's http status code.
executeStatementResponse_httpStatus :: Lens.Lens' ExecuteStatementResponse Prelude.Int
executeStatementResponse_httpStatus :: (Int -> f Int)
-> ExecuteStatementResponse -> f ExecuteStatementResponse
executeStatementResponse_httpStatus = (ExecuteStatementResponse -> Int)
-> (ExecuteStatementResponse -> Int -> ExecuteStatementResponse)
-> Lens ExecuteStatementResponse ExecuteStatementResponse Int Int
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\ExecuteStatementResponse' {Int
httpStatus :: Int
$sel:httpStatus:ExecuteStatementResponse' :: ExecuteStatementResponse -> Int
httpStatus} -> Int
httpStatus) (\s :: ExecuteStatementResponse
s@ExecuteStatementResponse' {} Int
a -> ExecuteStatementResponse
s {$sel:httpStatus:ExecuteStatementResponse' :: Int
httpStatus = Int
a} :: ExecuteStatementResponse)

instance Prelude.NFData ExecuteStatementResponse