Electric.Postgres.Inspector behaviour (electric v1.0.15)

View Source

Summary

Functions

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

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

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 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 information about a given table using a provided inspector.

Expects the table name provided by the user and validates that the table exists and returns the relation.

Types

column_info()

@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()

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

relation()

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

relation_id()

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

relation_info()

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

relation_kind()

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

type_kind()

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

Callbacks

clean(relation, opts)

@callback clean(relation(), opts :: term()) :: true

list_relations_with_stale_cache(opts)

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

load_column_info(relation, opts)

@callback load_column_info(relation(), opts :: term()) ::
  {:ok, [column_info()]} | :table_not_found

load_relation(arg1, opts)

@callback load_relation(String.t() | relation(), opts :: term()) ::
  {:ok, relation_info()} | {:error, String.t()}

Functions

clean(relation, arg)

@spec clean(relation() | relation_info(), inspector()) :: true

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

columns_to_expr(columns)

@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

get_pk_cols(columns)

@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(arg)

@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(relation, arg)

@spec load_column_info(relation(), inspector()) ::
  {:ok, [column_info()]} | :table_not_found

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

load_relation(table, inspector)

@spec load_relation(String.t() | relation(), inspector()) ::
  {:ok, relation_info()} | {:error, String.t()}

Expects the table name provided by the user and validates that the table exists and returns the relation.

The table name can be quoted or unquoted and can optionally be qualified, e.g. users would return {"public", "users"},

 `usErs` would return `{"public", "users"}`,
 `"Users"` would return `{"public", "Users"}`,
 `some_schema.users` would return `{"some_schema", "users"}`.