brokkr-broker::dal::stack_annotations
Rust
Data Access Layer for Stack Annotation operations.
This module provides functionality to interact with stack annotations in the database, including creating, retrieving, updating, and deleting annotations.
Structs
Section titled “Structs”struct StackAnnotationsDAL<'a>
Section titled “struct StackAnnotationsDAL<'a>”pub
Handles database operations for Stack Annotations.
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_annotation: &NewStackAnnotation,) -> Result<StackAnnotation, diesel::result::Error>Creates a new stack annotation in the database.
Parameters:
| Name | Type | Description |
|---|---|---|
new_annotation |
&NewStackAnnotation |
The new annotation details to be inserted. |
Returns:
The created StackAnnotation or a database error.
Errors:
Returns a diesel::result::Error if the database operation fails.
Source
pub fn create( &self, new_annotation: &NewStackAnnotation, ) -> Result<StackAnnotation, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::insert_into(stack_annotations::table) .values(new_annotation) .get_result(conn) }pub
fn get( &self, annotation_id: Uuid,) -> Result<Option<StackAnnotation>, diesel::result::Error>Retrieves a stack annotation by its ID.
Parameters:
| Name | Type | Description |
|---|---|---|
annotation_id |
Uuid |
The UUID of the annotation to retrieve. |
Returns:
An Option<StackAnnotation> if found, or None if not found.
Errors:
Returns a diesel::result::Error if the database operation fails.
Source
pub fn get( &self, annotation_id: Uuid, ) -> Result<Option<StackAnnotation>, diesel::result::Error> { let conn = &mut self.dal.conn()?; stack_annotations::table .filter(stack_annotations::id.eq(annotation_id)) .first(conn) .optional() }list_for_stack
Section titled “list_for_stack”pub
fn list_for_stack( &self, stack_id: Uuid,) -> Result<Vec<StackAnnotation>, diesel::result::Error>Lists all annotations for a specific stack.
Parameters:
| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
The UUID of the stack whose annotations to retrieve. |
Returns:
A vector of StackAnnotations 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<StackAnnotation>, diesel::result::Error> { let conn = &mut self.dal.conn()?; stack_annotations::table .filter(stack_annotations::stack_id.eq(stack_id)) .load::<StackAnnotation>(conn) }update
Section titled “update”pub
fn update( &self, annotation_id: Uuid, updated_annotation: &StackAnnotation,) -> Result<StackAnnotation, diesel::result::Error>Updates an existing stack annotation in the database.
Parameters:
| Name | Type | Description |
|---|---|---|
annotation_id |
Uuid |
The UUID of the annotation to update. |
updated_annotation |
&StackAnnotation |
The updated annotation details. |
Returns:
The updated StackAnnotation.
Errors:
Returns a diesel::result::Error if the database operation fails.
Source
pub fn update( &self, annotation_id: Uuid, updated_annotation: &StackAnnotation, ) -> Result<StackAnnotation, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::update(stack_annotations::table.filter(stack_annotations::id.eq(annotation_id))) .set(updated_annotation) .get_result(conn) }delete
Section titled “delete”pub
fn delete( &self, annotation_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes a stack annotation from the database.
Parameters:
| Name | Type | Description |
|---|---|---|
annotation_id |
Uuid |
The UUID of the annotation 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, annotation_id: Uuid) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete(stack_annotations::table.filter(stack_annotations::id.eq(annotation_id))) .execute(conn) }delete_all_for_stack
Section titled “delete_all_for_stack”pub
fn delete_all_for_stack( &self, stack_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes all annotations for a specific stack.
Parameters:
| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
The UUID of the stack whose annotations 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_annotations::table.filter(stack_annotations::stack_id.eq(stack_id))) .execute(conn) }delete_by_stack_and_key
Section titled “delete_by_stack_and_key”pub
fn delete_by_stack_and_key( &self, stack_id: Uuid, key: &str,) -> Result<usize, diesel::result::Error>Deletes a specific annotation for a stack using a single indexed query.
This is more efficient than fetching all annotations and filtering client-side.
Parameters:
| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
The UUID of the stack. |
key |
&str |
The annotation key 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_key( &self, stack_id: Uuid, key: &str, ) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete( stack_annotations::table .filter(stack_annotations::stack_id.eq(stack_id)) .filter(stack_annotations::key.eq(key)), ) .execute(conn) }