Lazarus.Repo (lazarus v1.0.0)

Copy Markdown View Source

Lower-level Repo integration behind use Lazarus.

Most applications should use Lazarus rather than referencing this module directly. This module primarily exists to implement and document the repo-specific hooks that power use Lazarus.

The functions documented below are injected into your Repo module when you call use Lazarus. In other words, this module is the reference for the Repo.update* behavior that skips soft-deleted rows plus the Repo.soft_delete* and Repo.hard_delete* APIs, even though those functions ultimately live on your own Repo module.

What use Lazarus adds to a Repo

  • Repo.update*, loaded Repo.insert_or_update*, and Repo.update_all/3 behavior that skips soft-deleted rows unless with_deleted: true is passed
  • Repo.soft_delete/2 and Repo.soft_delete!/2 for single-row soft deletes
  • Repo.soft_delete_all/2 for bulk soft deletes
  • Repo.hard_delete/2, Repo.hard_delete!/2, and Repo.hard_delete_all/2 as explicit hard-delete escape hatches
  • protection against accidental Repo.delete* and Repo.delete_all* calls
  • a prepare_query/3 callback that filters soft-deleted rows from reads and bulk updates unless with_deleted: true is passed
  • protection against raw SQL unless allow_raw_sql: true is passed
  • protection against schema-less sources unless allow_schema_less_sources: true is passed
  • composition with any Repo-defined prepare_query/3, with Lazarus running after the Repo callback and respecting options such as with_deleted: true

use options

  • :bypass_schemas - schemas that should keep ordinary update*, delete*, update_all, and delete_all* behavior, and skip read and update filtering
  • :bypass_tables - schema-less table names that should keep ordinary update_all and delete_all* behavior and skip read and update raw-source filtering

Example

defmodule MyApp.Repo do
  use Ecto.Repo, otp_app: :my_app, adapter: Ecto.Adapters.Postgres
  use Lazarus
end

Most users will want the README plus the "Repo Module Setup", "Fetch, Update, and Delete APIs", "Query Support", "Cascade Soft-Deletes", and "Assoc Replace" guides for end-to-end usage. This module is better read as API reference for repo-level behavior.