artifact

Reads and writes the artifacts table: listing, creation, updates, archiving and id prefix lengths.

const SELECT_COLUMNS

source

pub(in crate::store::repo) const SELECT_COLUMNS: &str = "\
  id, project_id, title, body, metadata, \
  archived_at, created_at, updated_at";

The columns of artifacts, in the order that the artifact model’s TryFrom<Row> reads them.

fn all

source

pub async fn all(conn: &Connection, project_id: &Id, filter: &Filter) -> Result<Vec<Model>, Error>

Return artifacts for a project, applying the given filter.

Archived artifacts are left out unless the filter asks for all or only archived ones. The newest come first.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose artifacts to list
filter &Filter which archive states to include, and an optional tag label to match
returns Result<Vec<Model>, Error> The artifacts, or an error when the query or a row’s decoding fails.

fn archive

source

pub async fn archive(conn: &Connection, id: &Id) -> Result<Model, Error>

Archive an artifact by setting its archived_at timestamp.

It also sets updated_at to the same time.

Parameter Type Description
conn &Connection the database connection
id &Id the artifact to archive
returns Result<Model, Error> The archived artifact, or Error::NotFound when no artifact has that id.

fn create

source

pub async fn create(conn: &Connection, project_id: &Id, new: &New) -> Result<Model, Error>

Create a new artifact in the given project.

The artifact gets a fresh id, timestamps set to now, and {} as metadata when none is given.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project that owns the artifact
new &New the title, body and optional metadata of the artifact
returns Result<Model, Error> The artifact as stored, or an error when the insert fails or the row cannot be read back.

fn find_by_id

source

pub async fn find_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Option<Model>, Error>

Find an artifact by its Id.

Parameter Type Description
conn &Connection the database connection
id impl Into<Id> the full id of the artifact
returns Result<Option<Model>, Error> The artifact, None when no row has that id, or an error when the query fails.

fn find_required_by_id

source

pub async fn find_required_by_id(conn: &Connection, id: impl Into<Id>) -> Result<Model, Error>

Find an artifact by its Id, returning Error::NotFound when no row matches.

Parameter Type Description
conn &Connection the database connection
id impl Into<Id> the full id of the artifact
returns Result<Model, Error> The artifact, or a database error.

fn prefix_length_for_id

source

pub async fn prefix_length_for_id(
    conn: &Connection,
    project_id: &Id,
    id: &str,
) -> Result<usize, Error>

Return the minimum unique prefix length for a single artifact in the project.

Narrows the disambiguation pool to artifacts whose ID shares at least the first character with id — an ID that differs at character 0 can never force the prefix longer than 1, so omitting it preserves the same result as prefix_lengths while avoiding a full-table scan.

Uses two-tier resolution: if the target is active (not archived) it is resolved against the active pool only; otherwise it is resolved against the full pool.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose artifacts form the pool
id &str the full encoded id of the artifact
returns Result<usize, Error> The length; 1 when id is empty.

fn prefix_lengths

source

pub async fn prefix_lengths(
    conn: &Connection,
    project_id: &Id,
    ids: &[&str],
) -> Result<Vec<usize>, Error>

Return per-ID prefix lengths for a set of artifacts using a two-tier pool: active (non-archived) IDs are resolved against the active pool only, while archived IDs are resolved against the full pool.

Parameter Type Description
conn &Connection the database connection
project_id &Id the project whose artifacts form the pools
ids &[&str] the full encoded ids to measure
returns Result<Vec<usize>, Error> The returned Vec<usize> is aligned to ids. An id that is not in the project gets 1.

fn collect_ids

source

async fn collect_ids(conn: &Connection, sql: &str, project_id: &Id) -> Result<Vec<String>, Error>

Run a query that selects one id column, bound to a project id, and collect the ids.

Parameter Type Description
conn &Connection the database connection
sql &str a query whose first column is an id and whose ?1 is the project id
project_id &Id the value bound to ?1
returns Result<Vec<String>, Error> The ids, in the order the query returns them, or an error when the query fails.

fn update

source

pub async fn update(conn: &Connection, id: &Id, patch: &Patch) -> Result<Model, Error>

Update an existing artifact with the given patch.

Only the fields that the patch sets change; updated_at is always set to now.

Parameter Type Description
conn &Connection the database connection
id &Id the artifact to update
patch &Patch the new title, body or metadata, each optional
returns Result<Model, Error> The updated artifact, or Error::NotFound when no artifact has that id.