Skip to content

brokkr-broker::dal::agent_annotations

Rust

Data Access Layer for Agent Annotation operations.

This module provides functionality to interact with agent annotations in the database, including creating, retrieving, updating, and deleting annotations.

pub

Handles database operations for Agent Annotations.

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

pub

fn create(
&self,
new_annotation: &NewAgentAnnotation,
) -> Result<AgentAnnotation, diesel::result::Error>

Creates a new agent annotation in the database.

Parameters:

Name Type Description
new_annotation &NewAgentAnnotation The new annotation details.

Returns:

The created AgentAnnotation or a database error.

Errors:

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

Source
pub fn create(
&self,
new_annotation: &NewAgentAnnotation,
) -> Result<AgentAnnotation, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::insert_into(agent_annotations::table)
.values(new_annotation)
.get_result(conn)
}

pub

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

Retrieves an agent annotation by its ID.

Parameters:

Name Type Description
annotation_id Uuid The UUID of the annotation to retrieve.

Returns:

An Option<AgentAnnotation> 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<AgentAnnotation>, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
agent_annotations::table
.filter(agent_annotations::id.eq(annotation_id))
.first(conn)
.optional()
}

pub

fn list_for_agent(
&self,
agent_id: Uuid,
) -> Result<Vec<AgentAnnotation>, diesel::result::Error>

Lists all annotations for a specific agent.

Parameters:

Name Type Description
agent_id Uuid The UUID of the agent whose annotations to retrieve.

Returns:

A Vec<AgentAnnotation> containing all annotations for the specified agent.

Errors:

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

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

pub

fn list(&self) -> Result<Vec<AgentAnnotation>, diesel::result::Error>

Lists all agent annotations in the database.

Returns:

A Vec<AgentAnnotation> containing all agent annotations.

Errors:

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

Source
pub fn list(&self) -> Result<Vec<AgentAnnotation>, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
agent_annotations::table.load::<AgentAnnotation>(conn)
}

pub

fn update(
&self,
annotation_id: Uuid,
updated_annotation: &AgentAnnotation,
) -> Result<AgentAnnotation, diesel::result::Error>

Updates an existing agent annotation in the database.

Parameters:

Name Type Description
annotation_id Uuid The UUID of the annotation to update.
updated_annotation &AgentAnnotation The updated annotation details.

Returns:

The updated AgentAnnotation.

Errors:

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

Source
pub fn update(
&self,
annotation_id: Uuid,
updated_annotation: &AgentAnnotation,
) -> Result<AgentAnnotation, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::update(agent_annotations::table.filter(agent_annotations::id.eq(annotation_id)))
.set(updated_annotation)
.get_result(conn)
}

pub

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

Deletes an agent 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(agent_annotations::table.filter(agent_annotations::id.eq(annotation_id)))
.execute(conn)
}

pub

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

Deletes all annotations for a specific agent.

Parameters:

Name Type Description
agent_id Uuid The UUID of the agent 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_agent(&self, agent_id: Uuid) -> Result<usize, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::delete(agent_annotations::table.filter(agent_annotations::agent_id.eq(agent_id)))
.execute(conn)
}

pub

fn delete_by_agent_and_key(
&self,
agent_id: Uuid,
key: &str,
) -> Result<usize, diesel::result::Error>

Deletes a specific annotation for an agent using a single indexed query.

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

Parameters:

Name Type Description
agent_id Uuid The UUID of the agent.
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_agent_and_key(
&self,
agent_id: Uuid,
key: &str,
) -> Result<usize, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::delete(
agent_annotations::table
.filter(agent_annotations::agent_id.eq(agent_id))
.filter(agent_annotations::key.eq(key)),
)
.execute(conn)
}