Skip to content

brokkr-broker::dal::stack_labels

Rust

Data Access Layer for Stack Label operations.

This module provides functionality to interact with stack labels in the database, including creating, retrieving, listing, and deleting labels.

pub

Handles database operations for Stack Labels.

Name Type Description
dal &'a DAL Reference to the main DAL instance.

pub

fn create(
&self,
new_label: &NewStackLabel,
) -> Result<StackLabel, diesel::result::Error>

Creates a new stack label in the database.

Parameters:

Name Type Description
new_label &NewStackLabel The new label details to be inserted.

Returns:

The created StackLabel or a database error.

Errors:

Returns a diesel::result::Error if the database operation fails.

Source
pub fn create(&self, new_label: &NewStackLabel) -> Result<StackLabel, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::insert_into(stack_labels::table)
.values(new_label)
.get_result(conn)
}

pub

fn get(
&self,
label_id: Uuid,
) -> Result<Option<StackLabel>, diesel::result::Error>

Retrieves a stack label by its ID.

Parameters:

Name Type Description
label_id Uuid The UUID of the label to retrieve.

Returns:

An Option<StackLabel> if found, or None if not found.

Errors:

Returns a diesel::result::Error if the database operation fails.

Source
pub fn get(&self, label_id: Uuid) -> Result<Option<StackLabel>, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
stack_labels::table
.filter(stack_labels::id.eq(label_id))
.first(conn)
.optional()
}

pub

fn list_for_stack(
&self,
stack_id: Uuid,
) -> Result<Vec<StackLabel>, diesel::result::Error>

Lists all labels for a specific stack.

Parameters:

Name Type Description
stack_id Uuid The UUID of the stack whose labels to retrieve.

Returns:

A vector of StackLabels associated with the specified stack.

Errors:

Returns a diesel::result::Error if the database operation fails.

Source
pub fn list_for_stack(&self, stack_id: Uuid) -> Result<Vec<StackLabel>, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
stack_labels::table
.filter(stack_labels::stack_id.eq(stack_id))
.load::<StackLabel>(conn)
}

pub

fn delete(&self, label_id: Uuid) -> Result<usize, diesel::result::Error>

Deletes a stack label from the database.

Parameters:

Name Type Description
label_id Uuid The UUID of the label to delete.

Returns:

The number of affected rows (0 or 1).

Errors:

Returns a diesel::result::Error if the database operation fails.

Source
pub fn delete(&self, label_id: Uuid) -> Result<usize, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::delete(stack_labels::table.filter(stack_labels::id.eq(label_id))).execute(conn)
}

pub

fn delete_all_for_stack(
&self,
stack_id: Uuid,
) -> Result<usize, diesel::result::Error>

Deletes all labels for a specific stack.

Parameters:

Name Type Description
stack_id Uuid The UUID of the stack whose labels to delete.

Returns:

The number of affected rows.

Errors:

Returns a diesel::result::Error if the database operation fails.

Source
pub fn delete_all_for_stack(&self, stack_id: Uuid) -> Result<usize, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::delete(stack_labels::table.filter(stack_labels::stack_id.eq(stack_id)))
.execute(conn)
}

pub

fn delete_by_stack_and_label(
&self,
stack_id: Uuid,
label: &str,
) -> Result<usize, diesel::result::Error>

Deletes a specific label for a stack using a single indexed query.

This is more efficient than fetching all labels and filtering client-side.

Parameters:

Name Type Description
stack_id Uuid The UUID of the stack.
label &str The label string to delete.

Returns:

The number of affected rows (0 or 1).

Errors:

Returns a diesel::result::Error if the database operation fails.

Source
pub fn delete_by_stack_and_label(
&self,
stack_id: Uuid,
label: &str,
) -> Result<usize, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::delete(
stack_labels::table
.filter(stack_labels::stack_id.eq(stack_id))
.filter(stack_labels::label.eq(label)),
)
.execute(conn)
}