{-# 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.QuickSight.Types.RelationalTable
-- 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)
module Amazonka.QuickSight.Types.RelationalTable where

import qualified Amazonka.Core as Core
import qualified Amazonka.Lens as Lens
import qualified Amazonka.Prelude as Prelude
import Amazonka.QuickSight.Types.InputColumn

-- | A physical table type for relational data sources.
--
-- /See:/ 'newRelationalTable' smart constructor.
data RelationalTable = RelationalTable'
  { -- | The catalog associated with a table.
    RelationalTable -> Maybe Text
catalog :: Prelude.Maybe Prelude.Text,
    -- | The schema name. This name applies to certain relational database
    -- engines.
    RelationalTable -> Maybe Text
schema :: Prelude.Maybe Prelude.Text,
    -- | The Amazon Resource Name (ARN) for the data source.
    RelationalTable -> Text
dataSourceArn :: Prelude.Text,
    -- | The name of the relational table.
    RelationalTable -> Text
name :: Prelude.Text,
    -- | The column schema of the table.
    RelationalTable -> NonEmpty InputColumn
inputColumns :: Prelude.NonEmpty InputColumn
  }
  deriving (RelationalTable -> RelationalTable -> Bool
(RelationalTable -> RelationalTable -> Bool)
-> (RelationalTable -> RelationalTable -> Bool)
-> Eq RelationalTable
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RelationalTable -> RelationalTable -> Bool
$c/= :: RelationalTable -> RelationalTable -> Bool
== :: RelationalTable -> RelationalTable -> Bool
$c== :: RelationalTable -> RelationalTable -> Bool
Prelude.Eq, ReadPrec [RelationalTable]
ReadPrec RelationalTable
Int -> ReadS RelationalTable
ReadS [RelationalTable]
(Int -> ReadS RelationalTable)
-> ReadS [RelationalTable]
-> ReadPrec RelationalTable
-> ReadPrec [RelationalTable]
-> Read RelationalTable
forall a.
(Int -> ReadS a)
-> ReadS [a] -> ReadPrec a -> ReadPrec [a] -> Read a
readListPrec :: ReadPrec [RelationalTable]
$creadListPrec :: ReadPrec [RelationalTable]
readPrec :: ReadPrec RelationalTable
$creadPrec :: ReadPrec RelationalTable
readList :: ReadS [RelationalTable]
$creadList :: ReadS [RelationalTable]
readsPrec :: Int -> ReadS RelationalTable
$creadsPrec :: Int -> ReadS RelationalTable
Prelude.Read, Int -> RelationalTable -> ShowS
[RelationalTable] -> ShowS
RelationalTable -> String
(Int -> RelationalTable -> ShowS)
-> (RelationalTable -> String)
-> ([RelationalTable] -> ShowS)
-> Show RelationalTable
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [RelationalTable] -> ShowS
$cshowList :: [RelationalTable] -> ShowS
show :: RelationalTable -> String
$cshow :: RelationalTable -> String
showsPrec :: Int -> RelationalTable -> ShowS
$cshowsPrec :: Int -> RelationalTable -> ShowS
Prelude.Show, (forall x. RelationalTable -> Rep RelationalTable x)
-> (forall x. Rep RelationalTable x -> RelationalTable)
-> Generic RelationalTable
forall x. Rep RelationalTable x -> RelationalTable
forall x. RelationalTable -> Rep RelationalTable x
forall a.
(forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
$cto :: forall x. Rep RelationalTable x -> RelationalTable
$cfrom :: forall x. RelationalTable -> Rep RelationalTable x
Prelude.Generic)

-- |
-- Create a value of 'RelationalTable' 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:
--
-- 'catalog', 'relationalTable_catalog' - The catalog associated with a table.
--
-- 'schema', 'relationalTable_schema' - The schema name. This name applies to certain relational database
-- engines.
--
-- 'dataSourceArn', 'relationalTable_dataSourceArn' - The Amazon Resource Name (ARN) for the data source.
--
-- 'name', 'relationalTable_name' - The name of the relational table.
--
-- 'inputColumns', 'relationalTable_inputColumns' - The column schema of the table.
newRelationalTable ::
  -- | 'dataSourceArn'
  Prelude.Text ->
  -- | 'name'
  Prelude.Text ->
  -- | 'inputColumns'
  Prelude.NonEmpty InputColumn ->
  RelationalTable
newRelationalTable :: Text -> Text -> NonEmpty InputColumn -> RelationalTable
newRelationalTable
  Text
pDataSourceArn_
  Text
pName_
  NonEmpty InputColumn
pInputColumns_ =
    RelationalTable' :: Maybe Text
-> Maybe Text
-> Text
-> Text
-> NonEmpty InputColumn
-> RelationalTable
RelationalTable'
      { $sel:catalog:RelationalTable' :: Maybe Text
catalog = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:schema:RelationalTable' :: Maybe Text
schema = Maybe Text
forall a. Maybe a
Prelude.Nothing,
        $sel:dataSourceArn:RelationalTable' :: Text
dataSourceArn = Text
pDataSourceArn_,
        $sel:name:RelationalTable' :: Text
name = Text
pName_,
        $sel:inputColumns:RelationalTable' :: NonEmpty InputColumn
inputColumns = Tagged (NonEmpty InputColumn) (Identity (NonEmpty InputColumn))
-> Tagged (NonEmpty InputColumn) (Identity (NonEmpty InputColumn))
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced (Tagged (NonEmpty InputColumn) (Identity (NonEmpty InputColumn))
 -> Tagged (NonEmpty InputColumn) (Identity (NonEmpty InputColumn)))
-> NonEmpty InputColumn -> NonEmpty InputColumn
forall t b. AReview t b -> b -> t
Lens.# NonEmpty InputColumn
pInputColumns_
      }

-- | The catalog associated with a table.
relationalTable_catalog :: Lens.Lens' RelationalTable (Prelude.Maybe Prelude.Text)
relationalTable_catalog :: (Maybe Text -> f (Maybe Text))
-> RelationalTable -> f RelationalTable
relationalTable_catalog = (RelationalTable -> Maybe Text)
-> (RelationalTable -> Maybe Text -> RelationalTable)
-> Lens RelationalTable RelationalTable (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelationalTable' {Maybe Text
catalog :: Maybe Text
$sel:catalog:RelationalTable' :: RelationalTable -> Maybe Text
catalog} -> Maybe Text
catalog) (\s :: RelationalTable
s@RelationalTable' {} Maybe Text
a -> RelationalTable
s {$sel:catalog:RelationalTable' :: Maybe Text
catalog = Maybe Text
a} :: RelationalTable)

-- | The schema name. This name applies to certain relational database
-- engines.
relationalTable_schema :: Lens.Lens' RelationalTable (Prelude.Maybe Prelude.Text)
relationalTable_schema :: (Maybe Text -> f (Maybe Text))
-> RelationalTable -> f RelationalTable
relationalTable_schema = (RelationalTable -> Maybe Text)
-> (RelationalTable -> Maybe Text -> RelationalTable)
-> Lens RelationalTable RelationalTable (Maybe Text) (Maybe Text)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelationalTable' {Maybe Text
schema :: Maybe Text
$sel:schema:RelationalTable' :: RelationalTable -> Maybe Text
schema} -> Maybe Text
schema) (\s :: RelationalTable
s@RelationalTable' {} Maybe Text
a -> RelationalTable
s {$sel:schema:RelationalTable' :: Maybe Text
schema = Maybe Text
a} :: RelationalTable)

-- | The Amazon Resource Name (ARN) for the data source.
relationalTable_dataSourceArn :: Lens.Lens' RelationalTable Prelude.Text
relationalTable_dataSourceArn :: (Text -> f Text) -> RelationalTable -> f RelationalTable
relationalTable_dataSourceArn = (RelationalTable -> Text)
-> (RelationalTable -> Text -> RelationalTable)
-> Lens RelationalTable RelationalTable Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelationalTable' {Text
dataSourceArn :: Text
$sel:dataSourceArn:RelationalTable' :: RelationalTable -> Text
dataSourceArn} -> Text
dataSourceArn) (\s :: RelationalTable
s@RelationalTable' {} Text
a -> RelationalTable
s {$sel:dataSourceArn:RelationalTable' :: Text
dataSourceArn = Text
a} :: RelationalTable)

-- | The name of the relational table.
relationalTable_name :: Lens.Lens' RelationalTable Prelude.Text
relationalTable_name :: (Text -> f Text) -> RelationalTable -> f RelationalTable
relationalTable_name = (RelationalTable -> Text)
-> (RelationalTable -> Text -> RelationalTable)
-> Lens RelationalTable RelationalTable Text Text
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelationalTable' {Text
name :: Text
$sel:name:RelationalTable' :: RelationalTable -> Text
name} -> Text
name) (\s :: RelationalTable
s@RelationalTable' {} Text
a -> RelationalTable
s {$sel:name:RelationalTable' :: Text
name = Text
a} :: RelationalTable)

-- | The column schema of the table.
relationalTable_inputColumns :: Lens.Lens' RelationalTable (Prelude.NonEmpty InputColumn)
relationalTable_inputColumns :: (NonEmpty InputColumn -> f (NonEmpty InputColumn))
-> RelationalTable -> f RelationalTable
relationalTable_inputColumns = (RelationalTable -> NonEmpty InputColumn)
-> (RelationalTable -> NonEmpty InputColumn -> RelationalTable)
-> Lens
     RelationalTable
     RelationalTable
     (NonEmpty InputColumn)
     (NonEmpty InputColumn)
forall s a b t. (s -> a) -> (s -> b -> t) -> Lens s t a b
Lens.lens (\RelationalTable' {NonEmpty InputColumn
inputColumns :: NonEmpty InputColumn
$sel:inputColumns:RelationalTable' :: RelationalTable -> NonEmpty InputColumn
inputColumns} -> NonEmpty InputColumn
inputColumns) (\s :: RelationalTable
s@RelationalTable' {} NonEmpty InputColumn
a -> RelationalTable
s {$sel:inputColumns:RelationalTable' :: NonEmpty InputColumn
inputColumns = NonEmpty InputColumn
a} :: RelationalTable) ((NonEmpty InputColumn -> f (NonEmpty InputColumn))
 -> RelationalTable -> f RelationalTable)
-> ((NonEmpty InputColumn -> f (NonEmpty InputColumn))
    -> NonEmpty InputColumn -> f (NonEmpty InputColumn))
-> (NonEmpty InputColumn -> f (NonEmpty InputColumn))
-> RelationalTable
-> f RelationalTable
forall b c a. (b -> c) -> (a -> b) -> a -> c
Prelude.. (NonEmpty InputColumn -> f (NonEmpty InputColumn))
-> NonEmpty InputColumn -> f (NonEmpty InputColumn)
forall s t a b. (Coercible s a, Coercible t b) => Iso s t a b
Lens.coerced

instance Core.FromJSON RelationalTable where
  parseJSON :: Value -> Parser RelationalTable
parseJSON =
    String
-> (Object -> Parser RelationalTable)
-> Value
-> Parser RelationalTable
forall a. String -> (Object -> Parser a) -> Value -> Parser a
Core.withObject
      String
"RelationalTable"
      ( \Object
x ->
          Maybe Text
-> Maybe Text
-> Text
-> Text
-> NonEmpty InputColumn
-> RelationalTable
RelationalTable'
            (Maybe Text
 -> Maybe Text
 -> Text
 -> Text
 -> NonEmpty InputColumn
 -> RelationalTable)
-> Parser (Maybe Text)
-> Parser
     (Maybe Text
      -> Text -> Text -> NonEmpty InputColumn -> RelationalTable)
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
Prelude.<$> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Catalog")
            Parser
  (Maybe Text
   -> Text -> Text -> NonEmpty InputColumn -> RelationalTable)
-> Parser (Maybe Text)
-> Parser (Text -> Text -> NonEmpty InputColumn -> RelationalTable)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (Maybe Text)
forall a. FromJSON a => Object -> Text -> Parser (Maybe a)
Core..:? Text
"Schema")
            Parser (Text -> Text -> NonEmpty InputColumn -> RelationalTable)
-> Parser Text
-> Parser (Text -> NonEmpty InputColumn -> RelationalTable)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"DataSourceArn")
            Parser (Text -> NonEmpty InputColumn -> RelationalTable)
-> Parser Text -> Parser (NonEmpty InputColumn -> RelationalTable)
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser Text
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"Name")
            Parser (NonEmpty InputColumn -> RelationalTable)
-> Parser (NonEmpty InputColumn) -> Parser RelationalTable
forall (f :: * -> *) a b. Applicative f => f (a -> b) -> f a -> f b
Prelude.<*> (Object
x Object -> Text -> Parser (NonEmpty InputColumn)
forall a. FromJSON a => Object -> Text -> Parser a
Core..: Text
"InputColumns")
      )

instance Prelude.Hashable RelationalTable

instance Prelude.NFData RelationalTable

instance Core.ToJSON RelationalTable where
  toJSON :: RelationalTable -> Value
toJSON RelationalTable' {Maybe Text
NonEmpty InputColumn
Text
inputColumns :: NonEmpty InputColumn
name :: Text
dataSourceArn :: Text
schema :: Maybe Text
catalog :: Maybe Text
$sel:inputColumns:RelationalTable' :: RelationalTable -> NonEmpty InputColumn
$sel:name:RelationalTable' :: RelationalTable -> Text
$sel:dataSourceArn:RelationalTable' :: RelationalTable -> Text
$sel:schema:RelationalTable' :: RelationalTable -> Maybe Text
$sel:catalog:RelationalTable' :: RelationalTable -> Maybe Text
..} =
    [Pair] -> Value
Core.object
      ( [Maybe Pair] -> [Pair]
forall a. [Maybe a] -> [a]
Prelude.catMaybes
          [ (Text
"Catalog" 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
catalog,
            (Text
"Schema" 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
schema,
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"DataSourceArn" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
dataSourceArn),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"Name" Text -> Text -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= Text
name),
            Pair -> Maybe Pair
forall a. a -> Maybe a
Prelude.Just (Text
"InputColumns" Text -> NonEmpty InputColumn -> Pair
forall kv v. (KeyValue kv, ToJSON v) => Text -> v -> kv
Core..= NonEmpty InputColumn
inputColumns)
          ]
      )