brokkr-broker::dal::template_labels
Rust
Data Access Layer for Template Label operations.
This module provides functionality to interact with template labels in the database, including creating, retrieving, listing, and deleting labels.
Structs
Section titled “Structs”struct TemplateLabelsDAL<'a>
Section titled “struct TemplateLabelsDAL<'a>”pub
Handles database operations for Template Labels.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
dal |
&'a DAL |
Reference to the main DAL instance. |
Methods
Section titled “Methods”create
Section titled “create”pub
fn create( &self, new_label: &NewTemplateLabel,) -> Result<TemplateLabel, diesel::result::Error>Creates a new template label in the database.
Parameters:
| Name | Type | Description |
|---|---|---|
new_label |
&NewTemplateLabel |
The new label details to be inserted. |
Returns:
The created TemplateLabel or a database error.
Errors:
Returns a diesel::result::Error if the database operation fails.
Source
pub fn create( &self, new_label: &NewTemplateLabel, ) -> Result<TemplateLabel, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::insert_into(template_labels::table) .values(new_label) .get_result(conn) }pub
fn get( &self, label_id: Uuid,) -> Result<Option<TemplateLabel>, diesel::result::Error>Retrieves a template label by its ID.
Parameters:
| Name | Type | Description |
|---|---|---|
label_id |
Uuid |
The UUID of the label to retrieve. |
Returns:
An Option<TemplateLabel> 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<TemplateLabel>, diesel::result::Error> { let conn = &mut self.dal.conn()?; template_labels::table .filter(template_labels::id.eq(label_id)) .first(conn) .optional() }list_for_template
Section titled “list_for_template”pub
fn list_for_template( &self, template_id: Uuid,) -> Result<Vec<TemplateLabel>, diesel::result::Error>Lists all labels for a specific template.
Parameters:
| Name | Type | Description |
|---|---|---|
template_id |
Uuid |
The UUID of the template whose labels to retrieve. |
Returns:
A vector of TemplateLabels associated with the specified template.
Errors:
Returns a diesel::result::Error if the database operation fails.
Source
pub fn list_for_template( &self, template_id: Uuid, ) -> Result<Vec<TemplateLabel>, diesel::result::Error> { let conn = &mut self.dal.conn()?; template_labels::table .filter(template_labels::template_id.eq(template_id)) .load::<TemplateLabel>(conn) }delete
Section titled “delete”pub
fn delete(&self, label_id: Uuid) -> Result<usize, diesel::result::Error>Deletes a template 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(template_labels::table.filter(template_labels::id.eq(label_id))) .execute(conn) }delete_all_for_template
Section titled “delete_all_for_template”pub
fn delete_all_for_template( &self, template_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes all labels for a specific template.
Parameters:
| Name | Type | Description |
|---|---|---|
template_id |
Uuid |
The UUID of the template 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_template( &self, template_id: Uuid, ) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete(template_labels::table.filter(template_labels::template_id.eq(template_id))) .execute(conn) }