{-# LANGUAGE DeriveGeneric #-}
{-# LANGUAGE DuplicateRecordFields #-}
{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE RecordWildCards #-}
{-# LANGUAGE StrictData #-}
{-# LANGUAGE NoImplicitPrelude #-}
{-# 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.Types.Database
-- Copyright   : (c) 2013-2023 Brendan Hay
-- License     : Mozilla Public License, v. 2.0.
-- Maintainer  : Brendan Hay
-- Stability   : auto-generated
-- Portability : non-portable (GHC extensions)
module Amazonka.Glue.Types.Database 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.DatabaseIdentifier
import Amazonka.Glue.Types.PrincipalPermissions
import qualified Amazonka.Prelude as Prelude

-- | The @Database@ object represents a logical grouping of tables that might
-- reside in a Hive metastore or an RDBMS.
--
-- /See:/ 'newDatabase' smart constructor.
data Database = Database'
  { -- | The ID of the Data Catalog in which the database resides.
    Database -> Maybe Text
catalogId :: Prelude.Maybe Prelude.Text,
    -- | Creates a set of default permissions on the table for principals.
    Database -> Maybe [PrincipalPermissions]
createTableDefaultPermissions :: Prelude.Maybe [PrincipalPermissions],
    -- | The time at which the metadata database was created in the catalog.
    Database -> Maybe POSIX
createTime :: Prelude.Maybe Data.POSIX,
    -- | A description of the database.
    Database -> Maybe Text
description :: Prelude.Maybe Prelude.Text,
    -- | The location of the database (for example, an HDFS path).
    Database -> Maybe Text
locationUri :: Prelude.Maybe Prelude.Text,
    -- | These key-value pairs define parameters and properties of the database.
    Database -> Maybe (HashMap Text Text)
parameters :: Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text),
    -- | A @DatabaseIdentifier@ structure that describes a target database for
    -- resource linking.
    Database -> Maybe DatabaseIdentifier
targetDatabase :: Prelude.Maybe DatabaseIdentifier,
    -- | The name of the database. For Hive compatibility, this is folded to
    -- lowercase when it is stored.
    Database -> Text
name :: Prelude.Text
  }
  deriving (Database -> Database -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Database -> Database -> Bool
$c/= :: Database -> Database -> Bool
== :: Database -> Database -> Bool
$c== :: Database -> Database -> Bool
Prelude.Eq, ReadPrec [Database]
ReadPrec Database
Int -> ReadS Database
ReadS [Database]
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [Database]
$creadListPrec :: ReadPrec [Database]
readPrec :: ReadPrec Database
$creadPrec :: ReadPrec Database
readList :: ReadS [Database]
$creadList :: ReadS [Database]
readsPrec :: Int -> ReadS Database
$creadsPrec :: Int -> ReadS Database
Prelude.Read, Int -> Database -> ShowS
[Database] -> ShowS
Database -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Database] -> ShowS
$cshowList :: [Database] -> ShowS
show :: Database -> String
$cshow :: Database -> String
showsPrec :: Int -> Database -> ShowS
$cshowsPrec :: Int -> Database -> ShowS
Prelude.Show, forall x. Rep Database x -> Database
forall x. Database -> Rep Database x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep Database x -> Database
$cfrom :: forall x. Database -> Rep Database x
Prelude.Generic)

-- |
-- Create a value of 'Database' 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', 'database_catalogId' - The ID of the Data Catalog in which the database resides.
--
-- 'createTableDefaultPermissions', 'database_createTableDefaultPermissions' - Creates a set of default permissions on the table for principals.
--
-- 'createTime', 'database_createTime' - The time at which the metadata database was created in the catalog.
--
-- 'description', 'database_description' - A description of the database.
--
-- 'locationUri', 'database_locationUri' - The location of the database (for example, an HDFS path).
--
-- 'parameters', 'database_parameters' - These key-value pairs define parameters and properties of the database.
--
-- 'targetDatabase', 'database_targetDatabase' - A @DatabaseIdentifier@ structure that describes a target database for
-- resource linking.
--
-- 'name', 'database_name' - The name of the database. For Hive compatibility, this is folded to
-- lowercase when it is stored.
newDatabase ::
  -- | 'name'
  Prelude.Text ->
  Database
newDatabase :: Text -> Database
newDatabase Text
pName_ =
  Database'
    { $sel:catalogId:Database' :: Maybe Text
catalogId = forall a. Maybe a
Prelude.Nothing,
      $sel:createTableDefaultPermissions:Database' :: Maybe [PrincipalPermissions]
createTableDefaultPermissions = forall a. Maybe a
Prelude.Nothing,
      $sel:createTime:Database' :: Maybe POSIX
createTime = forall a. Maybe a
Prelude.Nothing,
      $sel:description:Database' :: Maybe Text
description = forall a. Maybe a
Prelude.Nothing,
      $sel:locationUri:Database' :: Maybe Text
locationUri = forall a. Maybe a
Prelude.Nothing,
      $sel:parameters:Database' :: Maybe (HashMap Text Text)
parameters = forall a. Maybe a
Prelude.Nothing,
      $sel:targetDatabase:Database' :: Maybe DatabaseIdentifier
targetDatabase = forall a. Maybe a
Prelude.Nothing,
      $sel:name:Database' :: Text
name = Text
pName_
    }

-- | The ID of the Data Catalog in which the database resides.
database_catalogId :: Lens.Lens' Database (Prelude.Maybe Prelude.Text)
database_catalogId :: Lens' Database (Maybe Text)
database_catalogId = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Maybe Text
catalogId :: Maybe Text
$sel:catalogId:Database' :: Database -> Maybe Text
catalogId} -> Maybe Text
catalogId) (\s :: Database
s@Database' {} Maybe Text
a -> Database
s {$sel:catalogId:Database' :: Maybe Text
catalogId = Maybe Text
a} :: Database)

-- | Creates a set of default permissions on the table for principals.
database_createTableDefaultPermissions :: Lens.Lens' Database (Prelude.Maybe [PrincipalPermissions])
database_createTableDefaultPermissions :: Lens' Database (Maybe [PrincipalPermissions])
database_createTableDefaultPermissions = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Maybe [PrincipalPermissions]
createTableDefaultPermissions :: Maybe [PrincipalPermissions]
$sel:createTableDefaultPermissions:Database' :: Database -> Maybe [PrincipalPermissions]
createTableDefaultPermissions} -> Maybe [PrincipalPermissions]
createTableDefaultPermissions) (\s :: Database
s@Database' {} Maybe [PrincipalPermissions]
a -> Database
s {$sel:createTableDefaultPermissions:Database' :: Maybe [PrincipalPermissions]
createTableDefaultPermissions = Maybe [PrincipalPermissions]
a} :: Database) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | The time at which the metadata database was created in the catalog.
database_createTime :: Lens.Lens' Database (Prelude.Maybe Prelude.UTCTime)
database_createTime :: Lens' Database (Maybe UTCTime)
database_createTime = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Maybe POSIX
createTime :: Maybe POSIX
$sel:createTime:Database' :: Database -> Maybe POSIX
createTime} -> Maybe POSIX
createTime) (\s :: Database
s@Database' {} Maybe POSIX
a -> Database
s {$sel:createTime:Database' :: Maybe POSIX
createTime = Maybe POSIX
a} :: Database) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall (a :: Format). Iso' (Time a) UTCTime
Data._Time

-- | A description of the database.
database_description :: Lens.Lens' Database (Prelude.Maybe Prelude.Text)
database_description :: Lens' Database (Maybe Text)
database_description = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Maybe Text
description :: Maybe Text
$sel:description:Database' :: Database -> Maybe Text
description} -> Maybe Text
description) (\s :: Database
s@Database' {} Maybe Text
a -> Database
s {$sel:description:Database' :: Maybe Text
description = Maybe Text
a} :: Database)

-- | The location of the database (for example, an HDFS path).
database_locationUri :: Lens.Lens' Database (Prelude.Maybe Prelude.Text)
database_locationUri :: Lens' Database (Maybe Text)
database_locationUri = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Maybe Text
locationUri :: Maybe Text
$sel:locationUri:Database' :: Database -> Maybe Text
locationUri} -> Maybe Text
locationUri) (\s :: Database
s@Database' {} Maybe Text
a -> Database
s {$sel:locationUri:Database' :: Maybe Text
locationUri = Maybe Text
a} :: Database)

-- | These key-value pairs define parameters and properties of the database.
database_parameters :: Lens.Lens' Database (Prelude.Maybe (Prelude.HashMap Prelude.Text Prelude.Text))
database_parameters :: Lens' Database (Maybe (HashMap Text Text))
database_parameters = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Maybe (HashMap Text Text)
parameters :: Maybe (HashMap Text Text)
$sel:parameters:Database' :: Database -> Maybe (HashMap Text Text)
parameters} -> Maybe (HashMap Text Text)
parameters) (\s :: Database
s@Database' {} Maybe (HashMap Text Text)
a -> Database
s {$sel:parameters:Database' :: Maybe (HashMap Text Text)
parameters = Maybe (HashMap Text Text)
a} :: Database) forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. 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 forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

-- | A @DatabaseIdentifier@ structure that describes a target database for
-- resource linking.
database_targetDatabase :: Lens.Lens' Database (Prelude.Maybe DatabaseIdentifier)
database_targetDatabase :: Lens' Database (Maybe DatabaseIdentifier)
database_targetDatabase = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Maybe DatabaseIdentifier
targetDatabase :: Maybe DatabaseIdentifier
$sel:targetDatabase:Database' :: Database -> Maybe DatabaseIdentifier
targetDatabase} -> Maybe DatabaseIdentifier
targetDatabase) (\s :: Database
s@Database' {} Maybe DatabaseIdentifier
a -> Database
s {$sel:targetDatabase:Database' :: Maybe DatabaseIdentifier
targetDatabase = Maybe DatabaseIdentifier
a} :: Database)

-- | The name of the database. For Hive compatibility, this is folded to
-- lowercase when it is stored.
database_name :: Lens.Lens' Database Prelude.Text
database_name :: Lens' Database Text
database_name = forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\Database' {Text
name :: Text
$sel:name:Database' :: Database -> Text
name} -> Text
name) (\s :: Database
s@Database' {} Text
a -> Database
s {$sel:name:Database' :: Text
name = Text
a} :: Database)

instance Data.FromJSON Database where
  parseJSON :: Value -> Parser Database
parseJSON =
    forall a. String -> (Object -> Parser a) -> Value -> Parser a
Data.withObject
      String
"Database"
      ( \Object
x ->
          Maybe Text
-> Maybe [PrincipalPermissions]
-> Maybe POSIX
-> Maybe Text
-> Maybe Text
-> Maybe (HashMap Text Text)
-> Maybe DatabaseIdentifier
-> Text
-> Database
Database'
            forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"CatalogId")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> ( Object
x
                            forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"CreateTableDefaultPermissions"
                            forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty
                        )
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"CreateTime")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Description")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"LocationUri")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"Parameters" forall a. Parser (Maybe a) -> a -> Parser a
Data..!= forall a. Monoid a => a
Prelude.mempty)
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser (Maybe a)
Data..:? Key
"TargetDatabase")
            forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x forall a. FromJSON a => Object -> Key -> Parser a
Data..: Key
"Name")
      )

instance Prelude.Hashable Database where
  hashWithSalt :: Int -> Database -> Int
hashWithSalt Int
_salt Database' {Maybe [PrincipalPermissions]
Maybe Text
Maybe (HashMap Text Text)
Maybe POSIX
Maybe DatabaseIdentifier
Text
name :: Text
targetDatabase :: Maybe DatabaseIdentifier
parameters :: Maybe (HashMap Text Text)
locationUri :: Maybe Text
description :: Maybe Text
createTime :: Maybe POSIX
createTableDefaultPermissions :: Maybe [PrincipalPermissions]
catalogId :: Maybe Text
$sel:name:Database' :: Database -> Text
$sel:targetDatabase:Database' :: Database -> Maybe DatabaseIdentifier
$sel:parameters:Database' :: Database -> Maybe (HashMap Text Text)
$sel:locationUri:Database' :: Database -> Maybe Text
$sel:description:Database' :: Database -> Maybe Text
$sel:createTime:Database' :: Database -> Maybe POSIX
$sel:createTableDefaultPermissions:Database' :: Database -> Maybe [PrincipalPermissions]
$sel:catalogId:Database' :: Database -> 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` Maybe [PrincipalPermissions]
createTableDefaultPermissions
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe POSIX
createTime
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
description
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe Text
locationUri
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe (HashMap Text Text)
parameters
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Maybe DatabaseIdentifier
targetDatabase
      forall a. Hashable a => Int -> a -> Int
`Prelude.hashWithSalt` Text
name

instance Prelude.NFData Database where
  rnf :: Database -> ()
rnf Database' {Maybe [PrincipalPermissions]
Maybe Text
Maybe (HashMap Text Text)
Maybe POSIX
Maybe DatabaseIdentifier
Text
name :: Text
targetDatabase :: Maybe DatabaseIdentifier
parameters :: Maybe (HashMap Text Text)
locationUri :: Maybe Text
description :: Maybe Text
createTime :: Maybe POSIX
createTableDefaultPermissions :: Maybe [PrincipalPermissions]
catalogId :: Maybe Text
$sel:name:Database' :: Database -> Text
$sel:targetDatabase:Database' :: Database -> Maybe DatabaseIdentifier
$sel:parameters:Database' :: Database -> Maybe (HashMap Text Text)
$sel:locationUri:Database' :: Database -> Maybe Text
$sel:description:Database' :: Database -> Maybe Text
$sel:createTime:Database' :: Database -> Maybe POSIX
$sel:createTableDefaultPermissions:Database' :: Database -> Maybe [PrincipalPermissions]
$sel:catalogId:Database' :: Database -> 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 Maybe [PrincipalPermissions]
createTableDefaultPermissions
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe POSIX
createTime
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
description
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe Text
locationUri
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe (HashMap Text Text)
parameters
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Maybe DatabaseIdentifier
targetDatabase
      seq :: forall a b. a -> b -> b
`Prelude.seq` forall a. NFData a => a -> ()
Prelude.rnf Text
name