PaperTiger.Store (PaperTiger v1.5.1)

Copy Markdown View Source

Shared behavior for all ETS-backed resource stores.

Provides GenServer-wrapped ETS storage with:

  • Concurrent reads (direct ETS access)
  • Serialized writes (through GenServer)
  • Common CRUD operations
  • Pagination support
  • Test isolation via namespacing (see PaperTiger.Test)

Usage

defmodule PaperTiger.Store.Customers do
  use PaperTiger.Store,
    table: :paper_tiger_customers,
    resource: "customer"

  # Optionally add resource-specific queries on top of find_by/2
  def find_active_by_email(email) when is_binary(email) do
    Enum.filter(find_by(:email, email), & &1.active)
  end
end

This generates all standard store functions:

  • get/1, get_owned/3, list/1, count/0, find_by/2 (reads - direct ETS)
  • insert/1, update/1, delete/1, mutate_owned/3, clear/0 (writes - via GenServer)
  • clear_namespace/1 (for test cleanup)
  • GenServer callbacks

Namespacing

All data is stored with a composite key {namespace, id} where namespace is either :global (default) or the PID of the test process when using PaperTiger.Test.checkout_paper_tiger/1.

This allows concurrent tests to have isolated data without interference.