Depot.Repo
Depot.Repo: in-memory repository backed by Vault tables.
Each schema table gets its own Vault table. Rows are stored as records keyed by primary key (auto-generated UUID on insert).
Usage:
let gate = Depot.Gate.cast_record(
Depot.Schema.blank(schema()),
params,
["name", "email"]
) |> Depot.Gate.validate_required(["name", "email"])
match Depot.Repo.insert(schema(), gate) do
Ok(record) -> record
Err(gate) -> Depot.Gate.errors(gate)
end
let users = Depot.Repo.all(schema())
let user = Depot.Repo.get(schema(), "some-uuid")Functions
Return all records for a schema as a list.
let users = Depot.Repo.all(schema)Count the number of records for a schema.
Depot.Repo.count(schema)Delete a record by its primary key value.
Returns Ok(id) if the record existed and was deleted, Err("not found") otherwise.
match Depot.Repo.delete(schema, "some-uuid") do
Ok(id) -> id
Err(e) -> e
endDelete all records for a schema. Returns the count of deleted records.
Depot.Repo.delete_all(schema)Returns true if any records exist for a schema.
Depot.Repo.exists(schema)Get a single record by primary key. Returns Some(record) or None.
Depot.Repo.get(schema, "abc-123")Get a single record by primary key. Returns Err if not found.
match Depot.Repo.get_bang(schema, "abc-123") do
Ok(user) -> ...
Err(msg) -> ...
endGet a single record matching the given field clauses. Returns Some(record) or None.
Depot.Repo.get_by(schema, { email: "[email protected]" })Insert a new record from a validated Gate.
Returns Ok(record) on success, Err(gate) if the gate is invalid. The primary key is auto-generated as a UUID.
match Depot.Repo.insert(schema, gate) do
Ok(user) -> user
Err(gate) -> Depot.Gate.errors(gate)
endReturns the single record in the table if exactly one row exists, otherwise None. Useful for tables expected to hold at most one row (e.g. site settings, feature flags).
Depot.Repo.one(schema) -- Some(record) | NoneUpdate an existing record from a validated Gate.
The gate's base must contain the primary key. Only changed fields are merged into the existing record.
Returns Ok(record) on success, Err(gate) if the gate is invalid.
match Depot.Repo.update(schema, gate) do
Ok(user) -> user
Err(gate) -> Depot.Gate.errors(gate)
end