# `Electric.Postgres.Inspector`
[🔗](https://github.com/electric-sql/electric/tree/%40core/sync-service%401.6.2/packages/sync-service/lib/electric/postgres/inspector.ex#L1)

# `column_info`

```elixir
@type column_info() :: %{
  name: String.t(),
  type: String.t(),
  type_mod: integer() | nil,
  type_kind: type_kind(),
  formatted_type: String.t(),
  pk_position: non_neg_integer() | nil,
  type_id: {typid :: non_neg_integer(), typmod :: integer()},
  array_dimensions: non_neg_integer(),
  not_null: boolean(),
  array_type: String.t()
}
```

# `inspector`

```elixir
@type inspector() :: {module(), opts :: term()}
```

# `relation`

```elixir
@type relation() :: Electric.relation()
```

# `relation_id`

```elixir
@type relation_id() :: Electric.relation_id()
```

# `relation_info`

```elixir
@type relation_info() :: %{
  relation_id: relation_id(),
  relation: relation(),
  kind: relation_kind(),
  parent: nil | relation(),
  children: nil | [relation(), ...]
}
```

# `relation_kind`

```elixir
@type relation_kind() :: :ordinary_table | :partitioned_table
```

# `supported_features`

```elixir
@type supported_features() :: %{supports_generated_column_replication: boolean()}
```

# `type_kind`

```elixir
@type type_kind() ::
  :base | :composite | :domain | :enum | :pseudo | :range | :multirange
```

# `clean`

```elixir
@callback clean(relation_id(), opts :: term()) :: :ok
```

# `list_relations_with_stale_cache`

```elixir
@callback list_relations_with_stale_cache(opts :: term()) ::
  {:ok, [Electric.oid_relation()]} | :error
```

# `load_column_info`

```elixir
@callback load_column_info(relation_id(), opts :: term()) ::
  {:ok, [column_info()]}
  | :table_not_found
  | {:error, String.t() | :connection_not_available}
```

# `load_relation_info`

```elixir
@callback load_relation_info(relation_id(), opts :: term()) ::
  {:ok, relation_info()}
  | :table_not_found
  | {:error, String.t() | :connection_not_available}
```

# `load_relation_oid`

```elixir
@callback load_relation_oid(relation(), opts :: term()) ::
  {:ok, Electric.oid_relation()}
  | :table_not_found
  | {:error, String.t() | :connection_not_available}
```

# `load_supported_features`

```elixir
@callback load_supported_features(opts :: term()) ::
  {:ok, supported_features()} | {:error, String.t() | :connection_not_available}
```

# `clean`

```elixir
@spec clean(relation_id(), inspector()) :: :ok
```

Clean up all information about a given relation using a provided inspector.

# `columns_to_expr`

```elixir
@spec columns_to_expr([column_info(), ...]) ::
  Electric.Replication.Eval.Parser.refs_map()
```

Convert a column list into something that can be used by
`Electric.Replication.Eval.Parser.parse_and_validate_expression/2`

# `for_stack`

# `get_pk_cols`

```elixir
@spec get_pk_cols([column_info(), ...]) :: [String.t(), ...]
```

Get columns that should be considered a PK for table. If the table
has no PK, then we're considering all columns as identifying.

# `list_relations_with_stale_cache`

```elixir
@spec list_relations_with_stale_cache(inspector()) ::
  {:ok, [Electric.oid_relation()]} | :error
```

List relations that have stale cache. Doesn't clean the cache immediately,
that's left to the caller. Inspectors without cache will return an `:error`.

# `load_column_info`

```elixir
@spec load_column_info(relation_id(), inspector()) ::
  {:ok, [column_info()]}
  | :table_not_found
  | {:error, String.t() | :connection_not_available}
```

Load column information about a given table using a provided inspector.

# `load_relation_info`

```elixir
@spec load_relation_info(relation_id(), inspector()) ::
  {:ok, relation_info()}
  | :table_not_found
  | {:error, String.t() | :connection_not_available}
```

Load additional information about a given relation.

Additional information includes the relation kind, parent/child relationships,
and other metadata.

# `load_relation_oid`

```elixir
@spec load_relation_oid(relation(), inspector()) ::
  {:ok, Electric.oid_relation()}
  | :table_not_found
  | {:error, String.t() | :connection_not_available}
```

Expects the table name provided by the user and validates that the table exists,
returning the OID.

Table name is expected to have been normalized beforehand

# `load_supported_features`

```elixir
@spec load_supported_features(inspector()) ::
  {:ok, supported_features()} | {:error, String.t() | :connection_not_available}
```

Load the supported features on the target database using a provided inspector.

---

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