brokkr-broker::dal::agent_targets
Rust
Data Access Layer for AgentTarget operations.
This module provides functionality to interact with the agent_targets table in the database, allowing CRUD operations on AgentTarget entities.
Structs
Section titled “Structs”struct AgentTargetsDAL<'a>
Section titled “struct AgentTargetsDAL<'a>”pub
Handles database operations for AgentTarget entities.
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_target: &NewAgentTarget,) -> Result<AgentTarget, diesel::result::Error>Creates a new agent target in the database.
Parameters:
| Name | Type | Description |
|---|---|---|
new_target |
&NewAgentTarget |
The new agent target details to be inserted. |
Returns:
The created AgentTarget on success, or a diesel::result::Error on failure.
Source
pub fn create( &self, new_target: &NewAgentTarget, ) -> Result<AgentTarget, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::insert_into(agent_targets::table) .values(new_target) .get_result(conn) }pub
fn get( &self, target_id: Uuid,) -> Result<Option<AgentTarget>, diesel::result::Error>Retrieves an agent target by its ID.
Parameters:
| Name | Type | Description |
|---|---|---|
target_id |
Uuid |
The UUID of the agent target to retrieve. |
Returns:
An Option<AgentTarget> if found, or a diesel::result::Error on failure.
Source
pub fn get(&self, target_id: Uuid) -> Result<Option<AgentTarget>, diesel::result::Error> { let conn = &mut self.dal.conn()?; agent_targets::table .filter(agent_targets::id.eq(target_id)) .first(conn) .optional() }pub
fn list(&self) -> Result<Vec<AgentTarget>, diesel::result::Error>Lists all agent targets from the database.
Returns:
A Vec<AgentTarget> containing all agent targets, or a diesel::result::Error on failure.
Source
pub fn list(&self) -> Result<Vec<AgentTarget>, diesel::result::Error> { let conn = &mut self.dal.conn()?; agent_targets::table.load::<AgentTarget>(conn) }list_for_agent
Section titled “list_for_agent”pub
fn list_for_agent( &self, agent_id: Uuid,) -> Result<Vec<AgentTarget>, diesel::result::Error>Lists all agent targets for a specific agent.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
The UUID of the agent to list targets for. |
Returns:
A Vec<AgentTarget> for the specified agent, or a diesel::result::Error on failure.
Source
pub fn list_for_agent( &self, agent_id: Uuid, ) -> Result<Vec<AgentTarget>, diesel::result::Error> { let conn = &mut self.dal.conn()?; agent_targets::table .filter(agent_targets::agent_id.eq(agent_id)) .load::<AgentTarget>(conn) }list_for_stack
Section titled “list_for_stack”pub
fn list_for_stack( &self, stack_id: Uuid,) -> Result<Vec<AgentTarget>, diesel::result::Error>Lists all agent targets for a specific stack.
Parameters:
| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
The UUID of the stack to list targets for. |
Returns:
A Vec<AgentTarget> for the specified stack, or a diesel::result::Error on failure.
Source
pub fn list_for_stack( &self, stack_id: Uuid, ) -> Result<Vec<AgentTarget>, diesel::result::Error> { let conn = &mut self.dal.conn()?; agent_targets::table .filter(agent_targets::stack_id.eq(stack_id)) .load::<AgentTarget>(conn) }delete
Section titled “delete”pub
fn delete( &self, target_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes an agent target from the database.
Parameters:
| Name | Type | Description |
|---|---|---|
target_id |
Uuid |
The UUID of the agent target to delete. |
Returns:
The number of affected rows (0 or 1) on success, or a diesel::result::Error on failure.
Source
pub fn delete(&self, target_id: Uuid) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete(agent_targets::table.filter(agent_targets::id.eq(target_id))).execute(conn) }delete_for_agent
Section titled “delete_for_agent”pub
fn delete_for_agent( &self, agent_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes all agent targets for a specific agent.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
The UUID of the agent to delete targets for. |
Returns:
The number of affected rows on success, or a diesel::result::Error on failure.
Source
pub fn delete_for_agent(&self, agent_id: Uuid) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete(agent_targets::table.filter(agent_targets::agent_id.eq(agent_id))) .execute(conn) }delete_for_stack
Section titled “delete_for_stack”pub
fn delete_for_stack( &self, stack_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes all agent targets for a specific stack.
Parameters:
| Name | Type | Description |
|---|---|---|
stack_id |
Uuid |
The UUID of the stack to delete targets for. |
Returns:
The number of affected rows on success, or a diesel::result::Error on failure.
Source
pub fn delete_for_stack(&self, stack_id: Uuid) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete(agent_targets::table.filter(agent_targets::stack_id.eq(stack_id))) .execute(conn) }delete_by_agent_and_stack
Section titled “delete_by_agent_and_stack”pub
fn delete_by_agent_and_stack( &self, agent_id: Uuid, stack_id: Uuid,) -> Result<usize, diesel::result::Error>Deletes a specific target for an agent using a single indexed query.
This is more efficient than fetching all targets and filtering client-side.
Parameters:
| Name | Type | Description |
|---|---|---|
agent_id |
Uuid |
The UUID of the agent. |
stack_id |
Uuid |
The UUID of the stack to remove from targets. |
Returns:
The number of affected rows (0 or 1) on success, or a diesel::result::Error on failure.
Source
pub fn delete_by_agent_and_stack( &self, agent_id: Uuid, stack_id: Uuid, ) -> Result<usize, diesel::result::Error> { let conn = &mut self.dal.conn()?; diesel::delete( agent_targets::table .filter(agent_targets::agent_id.eq(agent_id)) .filter(agent_targets::stack_id.eq(stack_id)), ) .execute(conn) }