Skip to content

brokkr-broker::dal::template_targets

Rust

Data Access Layer for TemplateTarget operations.

This module provides functionality to interact with the template_targets table in the database, allowing CRUD operations on TemplateTarget entities.

pub

Handles database operations for TemplateTarget entities.

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

pub

fn create(
&self,
new_target: &NewTemplateTarget,
) -> Result<TemplateTarget, diesel::result::Error>

Creates a new template target in the database.

Parameters:

Name Type Description
new_target &NewTemplateTarget The new template target details to be inserted.

Returns:

The created TemplateTarget on success, or a diesel::result::Error on failure.

Source
pub fn create(
&self,
new_target: &NewTemplateTarget,
) -> Result<TemplateTarget, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::insert_into(template_targets::table)
.values(new_target)
.get_result(conn)
}

pub

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

Retrieves a template target by its ID.

Parameters:

Name Type Description
target_id Uuid The UUID of the template target to retrieve.

Returns:

An Option<TemplateTarget> if found, or a diesel::result::Error on failure.

Source
pub fn get(&self, target_id: Uuid) -> Result<Option<TemplateTarget>, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
template_targets::table
.filter(template_targets::id.eq(target_id))
.first(conn)
.optional()
}

pub

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

Lists all template targets from the database.

Returns:

A Vec<TemplateTarget> containing all template targets, or a diesel::result::Error on failure.

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

pub

fn list_for_template(
&self,
template_id: Uuid,
) -> Result<Vec<TemplateTarget>, diesel::result::Error>

Lists all template targets for a specific template.

Parameters:

Name Type Description
template_id Uuid The UUID of the template to list targets for.

Returns:

A Vec<TemplateTarget> for the specified template, or a diesel::result::Error on failure.

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

pub

fn list_for_stack(
&self,
stack_id: Uuid,
) -> Result<Vec<TemplateTarget>, diesel::result::Error>

Lists all template targets for a specific stack.

Parameters:

Name Type Description
stack_id Uuid The UUID of the stack to list targets for.

Returns:

A Vec<TemplateTarget> for the specified stack, or a diesel::result::Error on failure.

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

pub

fn exists(
&self,
template_id: Uuid,
stack_id: Uuid,
) -> Result<bool, diesel::result::Error>

Checks if a specific template-stack association exists.

Parameters:

Name Type Description
template_id Uuid The UUID of the template.
stack_id Uuid The UUID of the stack.

Returns:

true if the association exists, false otherwise.

Source
pub fn exists(&self, template_id: Uuid, stack_id: Uuid) -> Result<bool, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
let count: i64 = template_targets::table
.filter(template_targets::template_id.eq(template_id))
.filter(template_targets::stack_id.eq(stack_id))
.count()
.get_result(conn)?;
Ok(count > 0)
}

pub

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

Deletes a template target from the database.

Parameters:

Name Type Description
target_id Uuid The UUID of the template 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(template_targets::table.filter(template_targets::id.eq(target_id)))
.execute(conn)
}

pub

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

Deletes all template targets for a specific template.

Parameters:

Name Type Description
template_id Uuid The UUID of the template to delete targets for.

Returns:

The number of affected rows on success, or a diesel::result::Error on failure.

Source
pub fn delete_for_template(&self, template_id: Uuid) -> Result<usize, diesel::result::Error> {
let conn = &mut self.dal.conn()?;
diesel::delete(
template_targets::table.filter(template_targets::template_id.eq(template_id)),
)
.execute(conn)
}

pub

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

Deletes all template 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(template_targets::table.filter(template_targets::stack_id.eq(stack_id)))
.execute(conn)
}