PhoenixKit.RepoHelper (phoenix_kit v1.7.115)

Copy Markdown View Source

Helper for dynamically resolving the repository to use.

This module provides functions to get the appropriate repository based on configuration. It will use the configured repo from the parent application if available, otherwise fall back to the built-in PhoenixKit.Repo for development/testing.

Summary

Functions

Delegates to the configured repo's aggregate function.

Delegates to the configured repo's all function.

Delegates to the configured repo's delete function.

Delegates to the configured repo's delete_all function.

Delegates to the configured repo's exists? function.

Delegates to the configured repo's get function.

Delegates to the configured repo's get! function.

Delegates to the configured repo's get_by function.

Returns the primary key column name for a given table.

Delegates to the configured repo's insert function.

Delegates to the configured repo's insert! function.

Delegates to the configured repo's one function.

Delegates to the configured repo's preload function.

Delegates to the configured repo's query function.

Delegates to the configured repo's query! function.

Gets the repository module to use.

Delegates to the configured repo's rollback function.

Delegates to the configured repo's transaction function.

Delegates to the configured repo's update function.

Functions

aggregate(queryable, aggregate, field, opts \\ [])

Delegates to the configured repo's aggregate function.

all(queryable, opts \\ [])

Delegates to the configured repo's all function.

delete(struct_or_changeset, opts \\ [])

Delegates to the configured repo's delete function.

delete_all(queryable, opts \\ [])

Delegates to the configured repo's delete_all function.

exists?(queryable, opts \\ [])

Delegates to the configured repo's exists? function.

get(queryable, id, opts \\ [])

Delegates to the configured repo's get function.

get!(queryable, id, opts \\ [])

Delegates to the configured repo's get! function.

get_by(queryable, clauses, opts \\ [])

Delegates to the configured repo's get_by function.

get_pk_column(table_name)

Returns the primary key column name for a given table.

Looks up the table's primary key by querying pg_index. Uses Postgres' to_regclass/1 so the table name can be passed as a bind parameter (search-path aware, returns NULL when the table doesn't exist) — Postgrex can't bind a text parameter to a regclass cast directly.

Returns

  • column_name :: String.t() when the table has a single-column primary key.

Raises

  • ArgumentError when the table doesn't exist, has no primary key, or has a composite primary key (this helper only supports single-column PKs; callers building ON CONFLICT clauses must handle composite PKs explicitly).
  • Any error raised by the underlying repo query (e.g. Postgrex.Error).

Previously this function silently returned "id" on any failure, which masked the fact that every shipped PhoenixKit schema uses uuid as its primary key — see issue #517.

insert(struct_or_changeset, opts \\ [])

Delegates to the configured repo's insert function.

insert!(struct_or_changeset, opts \\ [])

Delegates to the configured repo's insert! function.

one(queryable, opts \\ [])

Delegates to the configured repo's one function.

preload(struct_or_structs, preloads, opts \\ [])

Delegates to the configured repo's preload function.

query(sql, params \\ [], opts \\ [])

Delegates to the configured repo's query function.

query!(sql, params \\ [], opts \\ [])

Delegates to the configured repo's query! function.

repo()

Gets the repository module to use.

Expects repo to be configured via PhoenixKit.Config.get(:repo). Raises an error if no repo is configured.

rollback(value)

Delegates to the configured repo's rollback function.

This function is used within transactions to rollback and return an error value.

transaction(fun_or_multi, opts \\ [])

Delegates to the configured repo's transaction function.

update(changeset, opts \\ [])

Delegates to the configured repo's update function.