# `Sublimate.ProjectionHelpers`

Helper functions for `Sublimate.ProjectionData`.

# `postgrex_options`

```elixir
@type postgrex_options() :: [{:timeout, integer() | :infinity}]
```

# `repo`

```elixir
@type repo() :: module()
```

# `table_columns`

```elixir
@type table_columns() :: [Sublimate.TableColumnData.t()]
```

# `identity_column_exists?`

```elixir
@spec identity_column_exists?(
  projection_data :: Sublimate.ProjectionData.t(),
  table_columns :: table_columns()
) ::
  :ok
  | {:error, :identity_column_not_found, String.t()}
  | {:error, :identity_column_invalid_type, String.t()}
```

Checks whether `projection_data.identity_column` is present in `table_columns` and is a valid identity column.

An identity column is either a serial column or an integer column that is a primary key.

Returns an error if:
- `projection_data.identity_column` is not found in `table_columns`
- the identity column has an invalid type

# `maybe_add_identity_column`

```elixir
@spec maybe_add_identity_column(
  projection_data :: Sublimate.ProjectionData.t(),
  table_columns :: table_columns(),
  repo :: repo(),
  postgrex_options :: postgrex_options()
) ::
  {:ok, table_columns()}
  | {:error, :identity_column_already_exists}
  | {:error, Exception.t()}
```

Adds an identity column to the source table if it isn't already present.

Returns an error if the identity column already exists.

# `needs_identity_column?`

```elixir
@spec needs_identity_column?(
  projection_data :: Sublimate.ProjectionData.t(),
  table_columns :: table_columns()
) :: :ok | {:error, :identity_column_already_exists}
```

Checks whether `projection_data.identity_column` is already present in `table_columns` and is a valid identity column.
This is the inverse of `identity_column_exists?/2`.

Returns an error if `projection_data.identity_column` is found in `table_columns` and has a valid type.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
