March Docs

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

fnallall(schema)#

Return all records for a schema as a list.

  let users = Depot.Repo.all(schema)
fncountcount(schema)#

Count the number of records for a schema.

  Depot.Repo.count(schema)
fndeletedelete(schema, id)#

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
  end
fndelete_alldelete_all(schema)#

Delete all records for a schema. Returns the count of deleted records.

  Depot.Repo.delete_all(schema)
fnexistsexists(schema)#

Returns true if any records exist for a schema.

  Depot.Repo.exists(schema)
fngetget(schema, id)#

Get a single record by primary key. Returns Some(record) or None.

  Depot.Repo.get(schema, "abc-123")
fnget_bangget_bang(schema, id)#

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) -> ...
  end
fnget_byget_by(schema, clauses)#

Get a single record matching the given field clauses. Returns Some(record) or None.

  Depot.Repo.get_by(schema, { email: "[email protected]" })
fninsertinsert(schema, gate)#

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)
  end
fnmatches_clausesmatches_clauses(record, clause_entries)#
fnoneone(schema)#

Returns 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) | None
fnupdateupdate(schema, gate)#

Update 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