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
def find_by_email(email) when is_binary(email) do
namespace = PaperTiger.Test.current_namespace()
:ets.match_object(@table, {{namespace, :_}, %{email: email}})
|> Enum.map(fn {_key, customer} -> customer end)
end
endThis generates all standard store functions:
get/1,list/1,count/0(reads - direct ETS)insert/1,update/1,delete/1,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.