{-# 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.Glue.GetDatabase
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
--
-- Retrieves the definition of a specified database.
module Amazonka.Glue.GetDatabase
  ( -- * Creating a Request
    GetDatabase (..),
    newGetDatabase,

    -- * Request Lenses
    getDatabase_catalogId,
    getDatabase_name,

    -- * Destructuring the Response
    GetDatabaseResponse (..),
    newGetDatabaseResponse,

    -- * Response Lenses
    getDatabaseResponse_database,
    getDatabaseResponse_httpStatus,
  )
where

import qualified Amazonka.Core as Core
import qualified Amazonka.Core.Lens.Internal as Lens
import qualified Amazonka.Data as Data
import Amazonka.Glue.Types
import qualified Amazonka.Prelude as Prelude
import qualified Amazonka.Request as Request
import qualified Amazonka.Response as Response

-- | /See:/ 'newGetDatabase' smart constructor.
data GetDatabase = GetDatabase'
  { -- | The ID of the Data Catalog in which the database resides. If none is
    -- provided, the Amazon Web Services account ID is used by default.
    GetDatabase -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | The name of the database to retrieve. For Hive compatibility, this
    -- should be all lowercase.
    GetDatabase -> Text
name :: Prelude.Text
  }
  deriving (GetDatabase -> GetDatabase -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDatabase -> GetDatabase -> Bool
$c/= :: GetDatabase -> GetDatabase -> Bool
== :: GetDatabase -> GetDatabase -> Bool
$c== :: GetDatabase -> GetDatabase -> Bool
Prelude.Eq, ReadPrec [GetDatabase]
ReadPrec GetDatabase
Int -> ReadS GetDatabase
ReadS [GetDatabase]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDatabase]
$creadListPrec :: ReadPrec [GetDatabase]
readPrec :: ReadPrec GetDatabase
$creadPrec :: ReadPrec GetDatabase
readList :: ReadS [GetDatabase]
$creadList :: ReadS [GetDatabase]
readsPrec :: Int -> ReadS GetDatabase
$creadsPrec :: Int -> ReadS GetDatabase
Prelude.Read, Int -> GetDatabase -> ShowS
[GetDatabase] -> ShowS
GetDatabase -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDatabase] -> ShowS
$cshowList :: [GetDatabase] -> ShowS
show :: GetDatabase -> String
$cshow :: GetDatabase -> String
showsPrec :: Int -> GetDatabase -> ShowS
$cshowsPrec :: Int -> GetDatabase -> ShowS
Prelude.Show, forall x. Rep GetDatabase x -> GetDatabase
forall x. GetDatabase -> Rep GetDatabase x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDatabase x -> GetDatabase
$cfrom :: forall x. GetDatabase -> Rep GetDatabase x
Prelude.Generic)

-- |
-- Create a value of 'GetDatabase' 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:
--
-- 'catalogId', 'getDatabase_catalogId' - The ID of the Data Catalog in which the database resides. If none is
-- provided, the Amazon Web Services account ID is used by default.
--
-- 'name', 'getDatabase_name' - The name of the database to retrieve. For Hive compatibility, this
-- should be all lowercase.
newGetDatabase ::
  -- | 'name'
  Prelude.Text ->
  GetDatabase
newGetDatabase :: Text -> GetDatabase
newGetDatabase Text
pName_ =
  GetDatabase'
    { $sel:catalogId:GetDatabase' :: Maybe Text
catalogId = forall a. Maybe a
Prelude.Nothing,
      $sel:name:GetDatabase' :: Text
name = Text
pName_
    }

-- | The ID of the Data Catalog in which the database resides. If none is
-- provided, the Amazon Web Services account ID is used by default.
getDatabase_catalogId :: Lens.Lens' GetDatabase (Prelude.Maybe Prelude.Text)
getDatabase_catalogId :: Lens' GetDatabase (Maybe Text)
getDatabase_catalogId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDatabase' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:GetDatabase' :: GetDatabase -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: GetDatabase
s@GetDatabase' {} Maybe Text
a -> GetDatabase
s {$sel:catalogId:GetDatabase' :: Maybe Text
catalogId = Maybe Text
a} :: GetDatabase)

-- | The name of the database to retrieve. For Hive compatibility, this
-- should be all lowercase.
getDatabase_name :: Lens.Lens' GetDatabase Prelude.Text
getDatabase_name :: Lens' GetDatabase Text
getDatabase_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDatabase' {Text
name :: Text
$sel:name:GetDatabase' :: GetDatabase -> Text
name} -> Text
name) (\s :: GetDatabase
s@GetDatabase' {} Text
a -> GetDatabase
s {$sel:name:GetDatabase' :: Text
name = Text
a} :: GetDatabase)

instance Core.AWSRequest GetDatabase where
  type AWSResponse GetDatabase = GetDatabaseResponse
  request :: (Service -> Service) -> GetDatabase -> Request GetDatabase
request Service -> Service
overrides =
    forall a. (ToRequest a, ToJSON a) => Service -> a -> Request a
Request.postJSON (Service -> Service
overrides Service
defaultService)
  response :: forall (m :: * -> *).
MonadResource m =>
(ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy GetDatabase
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse GetDatabase)))
response =
    forall (m :: * -> *) a.
MonadResource m =>
(Int -> ResponseHeaders -> Object -> Either String (AWSResponse a))
-> (ByteStringLazy -> IO ByteStringLazy)
-> Service
-> Proxy a
-> ClientResponse ClientBody
-> m (Either Error (ClientResponse (AWSResponse a)))
Response.receiveJSON
      ( \Int
s ResponseHeaders
h Object
x ->
          Maybe Database -> Int -> GetDatabaseResponse
GetDatabaseResponse'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Either String (Maybe a)
Data..?> Key
"Database")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (forall (f :: * -> *) a. Applicative f => a -> f a
Prelude.pure (forall a. Enum a => a -> Int
Prelude.fromEnum Int
s))
      )

instance Prelude.Hashable GetDatabase where
  hashWithSalt :: Int -> GetDatabase -> Int
hashWithSalt Int
_salt GetDatabase' {Maybe Text
Text
name :: Text
catalogId :: Maybe Text
$sel:name:GetDatabase' :: GetDatabase -> Text
$sel:catalogId:GetDatabase' :: GetDatabase -> Maybe Text
..} =
    Int
_salt
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
catalogId
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData GetDatabase where
  rnf :: GetDatabase -> ()
rnf GetDatabase' {Maybe Text
Text
name :: Text
catalogId :: Maybe Text
$sel:name:GetDatabase' :: GetDatabase -> Text
$sel:catalogId:GetDatabase' :: GetDatabase -> Maybe Text
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
catalogId
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name

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

instance Data.ToJSON GetDatabase where
  toJSON :: GetDatabase -> Value
toJSON GetDatabase' {Maybe Text
Text
name :: Text
catalogId :: Maybe Text
$sel:name:GetDatabase' :: GetDatabase -> Text
$sel:catalogId:GetDatabase' :: GetDatabase -> Maybe Text
..} =
    [Pair] -> Value
Data.object
      ( forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Key
"CatalogId" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..=) forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> Maybe Text
catalogId,
            forall a. a -> Maybe a
Prelude.Just (Key
"Name" forall kv v. (KeyValue kv, ToJSON v) => Key -> v -> kv
Data..= Text
name)
          ]
      )

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

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

-- | /See:/ 'newGetDatabaseResponse' smart constructor.
data GetDatabaseResponse = GetDatabaseResponse'
  { -- | The definition of the specified database in the Data Catalog.
    GetDatabaseResponse -> Maybe Database
database :: Prelude.Maybe Database,
    -- | The response's http status code.
    GetDatabaseResponse -> Int
httpStatus :: Prelude.Int
  }
  deriving (GetDatabaseResponse -> GetDatabaseResponse -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: GetDatabaseResponse -> GetDatabaseResponse -> Bool
$c/= :: GetDatabaseResponse -> GetDatabaseResponse -> Bool
== :: GetDatabaseResponse -> GetDatabaseResponse -> Bool
$c== :: GetDatabaseResponse -> GetDatabaseResponse -> Bool
Prelude.Eq, ReadPrec [GetDatabaseResponse]
ReadPrec GetDatabaseResponse
Int -> ReadS GetDatabaseResponse
ReadS [GetDatabaseResponse]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [GetDatabaseResponse]
$creadListPrec :: ReadPrec [GetDatabaseResponse]
readPrec :: ReadPrec GetDatabaseResponse
$creadPrec :: ReadPrec GetDatabaseResponse
readList :: ReadS [GetDatabaseResponse]
$creadList :: ReadS [GetDatabaseResponse]
readsPrec :: Int -> ReadS GetDatabaseResponse
$creadsPrec :: Int -> ReadS GetDatabaseResponse
Prelude.Read, Int -> GetDatabaseResponse -> ShowS
[GetDatabaseResponse] -> ShowS
GetDatabaseResponse -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [GetDatabaseResponse] -> ShowS
$cshowList :: [GetDatabaseResponse] -> ShowS
show :: GetDatabaseResponse -> String
$cshow :: GetDatabaseResponse -> String
showsPrec :: Int -> GetDatabaseResponse -> ShowS
$cshowsPrec :: Int -> GetDatabaseResponse -> ShowS
Prelude.Show, forall x. Rep GetDatabaseResponse x -> GetDatabaseResponse
forall x. GetDatabaseResponse -> Rep GetDatabaseResponse x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep GetDatabaseResponse x -> GetDatabaseResponse
$cfrom :: forall x. GetDatabaseResponse -> Rep GetDatabaseResponse x
Prelude.Generic)

-- |
-- Create a value of 'GetDatabaseResponse' 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:
--
-- 'database', 'getDatabaseResponse_database' - The definition of the specified database in the Data Catalog.
--
-- 'httpStatus', 'getDatabaseResponse_httpStatus' - The response's http status code.
newGetDatabaseResponse ::
  -- | 'httpStatus'
  Prelude.Int ->
  GetDatabaseResponse
newGetDatabaseResponse :: Int -> GetDatabaseResponse
newGetDatabaseResponse Int
pHttpStatus_ =
  GetDatabaseResponse'
    { $sel:database:GetDatabaseResponse' :: Maybe Database
database = forall a. Maybe a
Prelude.Nothing,
      $sel:httpStatus:GetDatabaseResponse' :: Int
httpStatus = Int
pHttpStatus_
    }

-- | The definition of the specified database in the Data Catalog.
getDatabaseResponse_database :: Lens.Lens' GetDatabaseResponse (Prelude.Maybe Database)
getDatabaseResponse_database :: Lens' GetDatabaseResponse (Maybe Database)
getDatabaseResponse_database = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\GetDatabaseResponse' {Maybe Database
database :: Maybe Database
$sel:database:GetDatabaseResponse' :: GetDatabaseResponse -> Maybe Database
database} -> Maybe Database
database) (\s :: GetDatabaseResponse
s@GetDatabaseResponse' {} Maybe Database
a -> GetDatabaseResponse
s {$sel:database:GetDatabaseResponse' :: Maybe Database
database = Maybe Database
a} :: GetDatabaseResponse)

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

instance Prelude.NFData GetDatabaseResponse where
  rnf :: GetDatabaseResponse -> ()
rnf GetDatabaseResponse' {Int
Maybe Database
httpStatus :: Int
database :: Maybe Database
$sel:httpStatus:GetDatabaseResponse' :: GetDatabaseResponse -> Int
$sel:database:GetDatabaseResponse' :: GetDatabaseResponse -> Maybe Database
..} =
    forall a. NFData a => a -> ()
Prelude.rnf Maybe Database
database
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Int
httpStatus