brokkr-broker::dal::agent_labels
Rust
Data Access Layer for AgentLabel operations.
This module provides functionality to interact with the agent_labels table in the database. It includes methods for creating, retrieving, listing, and deleting agent labels, as well as checking for label existence.
Structs
Section titled “Structs”struct AgentLabelsDAL<'a>
Section titled “struct AgentLabelsDAL<'a>”pub
Data Access Layer for AgentLabel operations.
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: &NewAgentLabel,) -> Result<AgentLabel, diesel::result::Error>Creates a new agent label in the database.
Parameters:
| Name | Type | Description |
|---|---|---|
new_label |
&NewAgentLabel |
A reference to the NewAgentLabel struct containing the label details. |
Returns:
Returns a Result containing the created AgentLabel on success, or a diesel::result::Error on failure.
Source
pub fn create(&self, new_label: &NewAgentLabel) -> Result<AgentLabel, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::insert_into(agent_labels::table) .values(new_label) .get_result(conn) }pub
fn get( &self, label_id: Uuid,) -> Result<Option<AgentLabel>, diesel::result::Error>Retrieves an agent label by its ID.
Parameters:
| Name | Type | Description |
|---|---|---|
label_id |
Uuid |
The UUID of the agent label to retrieve. |
Returns:
Returns a Result containing an Option
Source
pub fn get(&self, label_id: Uuid) -> Result<Option<AgentLabel>, diesel::result::Error> { let conn = &mut self.dal.conn()?; agent_labels::table .filter(agent_labels::id.eq(label_id)) .first(conn) .optional() }list_for_agent
Section titled “list_for_agent”pub
fn list_for_agent( &self, agent_id: Uuid,) -> Result<Vec<AgentLabel>, diesel::result::Error>Lists all labels for a specific agent.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
The UUID of the agent whose labels to retrieve. |
Returns:
Returns a Result containing a Vec of AgentLabels on success, or a diesel::result::Error on failure.
Source
pub fn list_for_agent(&self, agent_id: Uuid) -> Result<Vec<AgentLabel>, diesel::result::Error> { let conn = &mut self.dal.conn()?; agent_labels::table .filter(agent_labels::agent_id.eq(agent_id)) .load::<AgentLabel>(conn) }delete
Section titled “delete”pub
fn delete(&self, label_id: Uuid) -> Result<usize, diesel::result::Error>Deletes an agent label from the database.
Parameters:
| Name | Type | Description |
|---|---|---|
label_id |
Uuid |
The UUID of the agent label to delete. |
Returns:
Returns a Result containing the number of affected rows (0 or 1) on success, or a diesel::result::Error on failure.
Source
pub fn delete(&self, label_id: Uuid) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete(agent_labels::table.filter(agent_labels::id.eq(label_id))).execute(conn) }delete_all_for_agent
Section titled “delete_all_for_agent”pub
fn delete_all_for_agent( &self, agent_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes all labels for a specific agent.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
The UUID of the agent whose labels to delete. |
Returns:
Returns a Result containing the number of affected rows on success, or a diesel::result::Error on failure.
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_labels::table.filter(agent_labels::agent_id.eq(agent_id))) .execute(conn) }label_exists
Section titled “label_exists”pub
fn label_exists( &self, agent_id: Uuid, label: &str,) -> Result<bool, diesel::result::Error>Checks if a label exists for a specific agent.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
The UUID of the agent. |
label |
&str |
The label to check for. |
Returns:
Returns a Result containing a boolean (true if the label exists, false otherwise) on success, or a diesel::result::Error on failure.
Source
pub fn label_exists(&self, agent_id: Uuid, label: &str) -> Result<bool, diesel::result::Error> { let conn = &mut self.dal.conn()?; agent_labels::table .filter(agent_labels::agent_id.eq(agent_id)) .filter(agent_labels::label.eq(label)) .count() .get_result::<i64>(conn) .map(|count| count > 0) }delete_by_agent_and_label
Section titled “delete_by_agent_and_label”pub
fn delete_by_agent_and_label( &self, agent_id: Uuid, label: &str,) -> Result<usize, diesel::result::Error>Deletes a specific label for an agent using a single indexed query.
This is more efficient than fetching all labels and filtering client-side.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
The UUID of the agent. |
label |
&str |
The label string to delete. |
Returns:
Returns a Result containing the number of affected rows (0 or 1) on success, or a diesel::result::Error on failure.
Source
pub fn delete_by_agent_and_label( &self, agent_id: Uuid, label: &str, ) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete( agent_labels::table .filter(agent_labels::agent_id.eq(agent_id)) .filter(agent_labels::label.eq(label)), ) .execute(conn) }