Durable.Repo (Durable v0.1.0-rc)

View Source

Wrapper for Ecto repo calls with centralized options.

This module provides wrapper functions for common Ecto operations that automatically apply default options from the Durable configuration, such as the log option for controlling query logging.

Usage

Instead of calling the repo directly:

repo = config.repo
repo.all(query)

Use the wrapper with the config:

alias Durable.Repo
Repo.all(config, query)

This ensures consistent behavior across all Durable database operations.

Summary

Functions

Calculates the given aggregate over the given field.

Fetches all entries from the data store matching the given query.

Returns the default options to apply to all Ecto operations.

Deletes a struct using its primary key.

Deletes all entries matching the given query.

Fetches a single struct from the data store where the primary key matches the given id.

Fetches a single result from the query matching the given clauses.

Inserts a struct defined via Ecto.Schema or a changeset.

Inserts all entries into the repository.

Fetches a single result from the query.

Runs a custom SQL query on the given repo.

Runs an Ecto.Multi (or a function) inside a database transaction on the configured repo. Used to atomically couple state transitions (e.g. marking a PendingInput :timeout and resuming the workflow it belongs to) so a crash between the two updates can't orphan the workflow.

Updates a changeset using its primary key.

Updates all entries matching the given query with the given values.

Functions

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

Calculates the given aggregate over the given field.

all(config, queryable, opts \\ [])

Fetches all entries from the data store matching the given query.

default_options(config)

@spec default_options(Durable.Config.t()) :: keyword()

Returns the default options to apply to all Ecto operations.

delete(struct_or_changeset, config, opts \\ [])

Deletes a struct using its primary key.

Accepts struct as first arg to support piping.

delete_all(config, queryable, opts \\ [])

Deletes all entries matching the given query.

get(config, schema, id, opts \\ [])

Fetches a single struct from the data store where the primary key matches the given id.

get_by(config, schema, clauses, opts \\ [])

Fetches a single result from the query matching the given clauses.

insert(struct_or_changeset, config, opts \\ [])

Inserts a struct defined via Ecto.Schema or a changeset.

Accepts struct/changeset as first arg to support piping.

insert_all(config, schema_or_source, entries, opts \\ [])

Inserts all entries into the repository.

one(config, queryable, opts \\ [])

Fetches a single result from the query.

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

Runs a custom SQL query on the given repo.

transaction(config, fun_or_multi, opts \\ [])

Runs an Ecto.Multi (or a function) inside a database transaction on the configured repo. Used to atomically couple state transitions (e.g. marking a PendingInput :timeout and resuming the workflow it belongs to) so a crash between the two updates can't orphan the workflow.

update(changeset, config, opts \\ [])

Updates a changeset using its primary key.

Accepts changeset as first arg to support piping.

update_all(config, queryable, updates, opts \\ [])

Updates all entries matching the given query with the given values.