brokkr-broker::dal::template_annotations
Rust
Data Access Layer for Template Annotation operations.
This module provides functionality to interact with template annotations in the database, including creating, retrieving, listing, and deleting annotations.
Structs
Section titled “Structs”struct TemplateAnnotationsDAL<'a>
Section titled “struct TemplateAnnotationsDAL<'a>”pub
Handles database operations for Template 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: &NewTemplateAnnotation,) -> Result<TemplateAnnotation, diesel::result::Error>Creates a new template annotation in the database.
Parameters:
| Name | Type | Description |
|---|---|---|
new_annotation |
&NewTemplateAnnotation |
The new annotation details to be inserted. |
Returns:
The created TemplateAnnotation or a database error.
Errors:
Returns a diesel::result::Error if the database operation fails.
Source
pub fn create( &self, new_annotation: &NewTemplateAnnotation, ) -> Result<TemplateAnnotation, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::insert_into(template_annotations::table) .values(new_annotation) .get_result(conn) }pub
fn get( &self, annotation_id: Uuid,) -> Result<Option<TemplateAnnotation>, diesel::result::Error>Retrieves a template annotation by its ID.
Parameters:
| Name | Type | Description |
|---|---|---|
annotation_id |
Uuid |
The UUID of the annotation to retrieve. |
Returns:
An Option<TemplateAnnotation> 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<TemplateAnnotation>, diesel::result::Error> { let conn = &mut self.dal.conn()?; template_annotations::table .filter(template_annotations::id.eq(annotation_id)) .first(conn) .optional() }list_for_template
Section titled “list_for_template”pub
fn list_for_template( &self, template_id: Uuid,) -> Result<Vec<TemplateAnnotation>, diesel::result::Error>Lists all annotations for a specific template.
Parameters:
| Name | Type | Description |
|---|---|---|
template_id |
Uuid |
The UUID of the template whose annotations to retrieve. |
Returns:
A vector of TemplateAnnotations 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<TemplateAnnotation>, diesel::result::Error> { let conn = &mut self.dal.conn()?; template_annotations::table .filter(template_annotations::template_id.eq(template_id)) .load::<TemplateAnnotation>(conn) }delete
Section titled “delete”pub
fn delete( &self, annotation_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes a template 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( template_annotations::table.filter(template_annotations::id.eq(annotation_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 annotations for a specific template.
Parameters:
| Name | Type | Description |
|---|---|---|
template_id |
Uuid |
The UUID of the template 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_template( &self, template_id: Uuid, ) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete( template_annotations::table.filter(template_annotations::template_id.eq(template_id)), ) .execute(conn) }