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

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

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

fndeletedelete(schema, id)#

Delete a record by its primary key value.

Depot.Repo.delete(schema, "some-uuid")

fnallall(schema)#

Return all records for a schema as a list.

let users = Depot.Repo.all(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. Panics if not found.

let user = Depot.Repo.get_bang(schema, "abc-123")

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 = "alice@test.com" })

fnoneone(schema)#

Return exactly one record matching all rows (useful after filtering). Returns Some(record) if exactly one match, None otherwise.

Depot.Repo.one(schema)

fncountcount(schema)#

Count the number of records for a schema.

Depot.Repo.count(schema)

fnexistsexists(schema)#

Returns true if any records exist for a schema.

Depot.Repo.exists(schema)

fndelete_alldelete_all(schema)#

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

Depot.Repo.delete_all(schema)