brokkr-broker::dal
Rust
Data Access Layer (DAL) Module
This module provides an abstraction layer for database operations in the Brokkr Broker. It includes structures and methods for interacting with various data entities such as agents, stacks, deployment objects, and more.
Main Structures
DAL: The main Data Access Layer struct that provides access to all sub-DALs.FilterType: An enum used for specifying filter types in queries.
Usage
To use the DAL in your code:
use brokkr_broker::dal::DAL;use brokkr_broker::db::create_shared_connection_pool;
let pool = create_shared_connection_pool("database_url", "app_name", 5);let dal = DAL::new(pool);
// Now you can use dal to access various data operationslet agents = dal.agents().list().expect("Failed to list agents");Structs
Section titled “Structs”struct DAL
Section titled “struct DAL”pub
Derives: Clone
The main Data Access Layer struct.
This struct serves as the central point for database operations, managing a connection pool and providing access to specific DAL implementations for different entities.
Fields
Section titled “Fields”| Name | Type | Description |
|---|---|---|
pool |
ConnectionPool |
A connection pool for PostgreSQL database connections with schema support. |
auth_cache |
Option<Cache<String, AuthPayload>> |
In-memory cache for PAK authentication results, keyed by PAK hash. |
Methods
Section titled “Methods”pub
fn new(pool: ConnectionPool) -> SelfCreates a new DAL instance with the given connection pool.
Parameters:
| Name | Type | Description |
|---|---|---|
pool |
ConnectionPool |
A connection pool for PostgreSQL database connections with schema support. |
Returns:
A new DAL instance.
Source
pub fn new(pool: ConnectionPool) -> Self { DAL { pool, auth_cache: None, } }new_with_auth_cache
Section titled “new_with_auth_cache”pub
fn new_with_auth_cache( pool: ConnectionPool, auth_cache_ttl_seconds: u64,) -> SelfCreates a new DAL instance with an auth cache.
Parameters:
| Name | Type | Description |
|---|---|---|
pool |
ConnectionPool |
A connection pool for PostgreSQL database connections with schema support. |
auth_cache_ttl_seconds |
u64 |
TTL for cached auth results. 0 disables caching. |
Source
pub fn new_with_auth_cache(pool: ConnectionPool, auth_cache_ttl_seconds: u64) -> Self { let auth_cache = if auth_cache_ttl_seconds > 0 { Some( Cache::builder() .time_to_live(Duration::from_secs(auth_cache_ttl_seconds)) .max_capacity(10_000) .build(), ) } else { None }; DAL { pool, auth_cache } }pub
fn conn( &self,) -> Result< diesel::r2d2::PooledConnection< diesel::r2d2::ConnectionManager<diesel::PgConnection>, >, diesel::result::Error,>Borrows a pooled database connection (with the schema search_path set).
Returns the r2d2 pool error mapped to a diesel::result::Error so DAL
methods can ? it on their existing Result<_, diesel::result::Error>
surface instead of panicking. There is no From<r2d2::Error> for the
diesel error, so it is wrapped as an UnableToSendCommand database
error. Pool exhaustion / DB outage thus becomes a normal 500 result
(via ApiError::from_diesel) rather than an unwind caught by the
outer CatchPanicLayer.
Source
pub fn conn( &self, ) -> Result< diesel::r2d2::PooledConnection<diesel::r2d2::ConnectionManager<diesel::PgConnection>>, diesel::result::Error, > { self.pool.get().map_err(|e| { diesel::result::Error::DatabaseError( diesel::result::DatabaseErrorKind::UnableToSendCommand, Box::new(format!("failed to get DB connection from pool: {e}")), ) }) }invalidate_auth_cache
Section titled “invalidate_auth_cache”pub
fn invalidate_auth_cache(&self, pak_hash: &str)Invalidates a specific entry in the auth cache by PAK hash.
Source
pub fn invalidate_auth_cache(&self, pak_hash: &str) { if let Some(cache) = &self.auth_cache { cache.invalidate(pak_hash); } }invalidate_all_auth_cache
Section titled “invalidate_all_auth_cache”pub
fn invalidate_all_auth_cache(&self)Invalidates all entries in the auth cache.
Source
pub fn invalidate_all_auth_cache(&self) { if let Some(cache) = &self.auth_cache { cache.invalidate_all(); } }agents
Section titled “agents”pub
fn agents(&self) -> AgentsDAL<'_>Provides access to the Agents Data Access Layer.
Returns:
An instance of AgentsDAL.
Source
pub fn agents(&self) -> AgentsDAL<'_> { AgentsDAL { dal: self } }agent_annotations
Section titled “agent_annotations”pub
fn agent_annotations(&self) -> AgentAnnotationsDAL<'_>Provides access to the Agent Annotations Data Access Layer.
Returns:
An instance of AgentAnontationsDAL.
Source
pub fn agent_annotations(&self) -> AgentAnnotationsDAL<'_> { AgentAnnotationsDAL { dal: self } }agent_events
Section titled “agent_events”pub
fn agent_events(&self) -> AgentEventsDAL<'_>Provides access to the Agent Events Data Access Layer.
Returns:
An instance of AgentEventsDAL.
Source
pub fn agent_events(&self) -> AgentEventsDAL<'_> { AgentEventsDAL { dal: self } }agent_k8s_events
Section titled “agent_k8s_events”pub
fn agent_k8s_events(&self) -> AgentK8sEventsDAL<'_>Provides access to the agent kube-Events telemetry buffer (agent_k8s_events). Bounded by the 6h retention ceiling enforced in ws::eviction.
Source
pub fn agent_k8s_events(&self) -> AgentK8sEventsDAL<'_> { AgentK8sEventsDAL { dal: self } }agent_pod_logs
Section titled “agent_pod_logs”pub
fn agent_pod_logs(&self) -> AgentPodLogsDAL<'_>Provides access to the agent pod-logs telemetry buffer (agent_pod_logs). Bounded by the 6h retention ceiling enforced in ws::eviction.
Source
pub fn agent_pod_logs(&self) -> AgentPodLogsDAL<'_> { AgentPodLogsDAL { dal: self } }agent_labels
Section titled “agent_labels”pub
fn agent_labels(&self) -> AgentLabelsDAL<'_>Provides access to the Agent Labels Data Access Layer.
Returns:
An instance of AgentLabelsDAL.
Source
pub fn agent_labels(&self) -> AgentLabelsDAL<'_> { AgentLabelsDAL { dal: self } }agent_targets
Section titled “agent_targets”pub
fn agent_targets(&self) -> AgentTargetsDAL<'_>Provides access to the Agent Targets Data Access Layer.
Returns:
An instance of AgentTargetssDAL.
Source
pub fn agent_targets(&self) -> AgentTargetsDAL<'_> { AgentTargetsDAL { dal: self } }agent_generator_registrations
Section titled “agent_generator_registrations”pub
fn agent_generator_registrations( &self,) -> AgentGeneratorRegistrationsDAL<'_>Provides access to the Agent Generator Registrations Data Access Layer.
Source
pub fn agent_generator_registrations(&self) -> AgentGeneratorRegistrationsDAL<'_> { AgentGeneratorRegistrationsDAL { dal: self } }stack_labels
Section titled “stack_labels”pub
fn stack_labels(&self) -> StackLabelsDAL<'_>Provides access to the Stack Labels Data Access Layer.
Returns:
An instance of StackLabelsDAL.
Source
pub fn stack_labels(&self) -> StackLabelsDAL<'_> { StackLabelsDAL { dal: self } }stack_annotations
Section titled “stack_annotations”pub
fn stack_annotations(&self) -> StackAnnotationsDAL<'_>Provides access to the Stack Annotations Data Access Layer.
Returns:
An instance of StackAnontationsDAL.
Source
pub fn stack_annotations(&self) -> StackAnnotationsDAL<'_> { StackAnnotationsDAL { dal: self } }stacks
Section titled “stacks”pub
fn stacks(&self) -> StacksDAL<'_>Provides access to the Stacks Data Access Layer.
Returns:
An instance of StacksDAL.
Source
pub fn stacks(&self) -> StacksDAL<'_> { StacksDAL { dal: self } }deployment_health
Section titled “deployment_health”pub
fn deployment_health(&self) -> DeploymentHealthDAL<'_>Provides access to the Deployment Health Data Access Layer.
Returns:
An instance of DeploymentHealthDAL.
Source
pub fn deployment_health(&self) -> DeploymentHealthDAL<'_> { DeploymentHealthDAL { dal: self } }deployment_objects
Section titled “deployment_objects”pub
fn deployment_objects(&self) -> DeploymentObjectsDAL<'_>Provides access to the Deployment Objects Data Access Layer.
Returns:
An instance of DeploymentObjectsDAL.
Source
pub fn deployment_objects(&self) -> DeploymentObjectsDAL<'_> { DeploymentObjectsDAL { dal: self } }generators
Section titled “generators”pub
fn generators(&self) -> GeneratorsDAL<'_>Provides access to the Generators Data Access Layer.
Returns:
An instance of GeneratorsDal.
Source
pub fn generators(&self) -> GeneratorsDAL<'_> { GeneratorsDAL { dal: self } }templates
Section titled “templates”pub
fn templates(&self) -> TemplatesDAL<'_>Provides access to the Templates Data Access Layer.
Returns:
An instance of TemplatesDAL.
Source
pub fn templates(&self) -> TemplatesDAL<'_> { TemplatesDAL { dal: self } }template_labels
Section titled “template_labels”pub
fn template_labels(&self) -> TemplateLabelsDAL<'_>Provides access to the Template Labels Data Access Layer.
Returns:
An instance of TemplateLabelsDAL.
Source
pub fn template_labels(&self) -> TemplateLabelsDAL<'_> { TemplateLabelsDAL { dal: self } }template_annotations
Section titled “template_annotations”pub
fn template_annotations(&self) -> TemplateAnnotationsDAL<'_>Provides access to the Template Annotations Data Access Layer.
Returns:
An instance of TemplateAnnotationsDAL.
Source
pub fn template_annotations(&self) -> TemplateAnnotationsDAL<'_> { TemplateAnnotationsDAL { dal: self } }template_targets
Section titled “template_targets”pub
fn template_targets(&self) -> TemplateTargetsDAL<'_>Provides access to the Template Targets Data Access Layer.
Returns:
An instance of TemplateTargetsDAL.
Source
pub fn template_targets(&self) -> TemplateTargetsDAL<'_> { TemplateTargetsDAL { dal: self } }rendered_deployment_objects
Section titled “rendered_deployment_objects”pub
fn rendered_deployment_objects( &self,) -> RenderedDeploymentObjectsDAL<'_>Provides access to the Rendered Deployment Objects Data Access Layer.
Returns:
An instance of RenderedDeploymentObjectsDAL.
Source
pub fn rendered_deployment_objects(&self) -> RenderedDeploymentObjectsDAL<'_> { RenderedDeploymentObjectsDAL { dal: self } }work_orders
Section titled “work_orders”pub
fn work_orders(&self) -> WorkOrdersDAL<'_>Provides access to the Work Orders Data Access Layer.
Returns:
An instance of WorkOrdersDAL.
Source
pub fn work_orders(&self) -> WorkOrdersDAL<'_> { WorkOrdersDAL { dal: self } }diagnostic_requests
Section titled “diagnostic_requests”pub
fn diagnostic_requests(&self) -> DiagnosticRequestsDAL<'_>Provides access to the Diagnostic Requests Data Access Layer.
Returns:
An instance of DiagnosticRequestsDAL.
Source
pub fn diagnostic_requests(&self) -> DiagnosticRequestsDAL<'_> { DiagnosticRequestsDAL { dal: self } }diagnostic_results
Section titled “diagnostic_results”pub
fn diagnostic_results(&self) -> DiagnosticResultsDAL<'_>Provides access to the Diagnostic Results Data Access Layer.
Returns:
An instance of DiagnosticResultsDAL.
Source
pub fn diagnostic_results(&self) -> DiagnosticResultsDAL<'_> { DiagnosticResultsDAL { dal: self } }webhook_subscriptions
Section titled “webhook_subscriptions”pub
fn webhook_subscriptions(&self) -> WebhookSubscriptionsDAL<'_>Provides access to the Webhook Subscriptions Data Access Layer.
Returns:
An instance of WebhookSubscriptionsDAL.
Source
pub fn webhook_subscriptions(&self) -> WebhookSubscriptionsDAL<'_> { WebhookSubscriptionsDAL { dal: self } }webhook_deliveries
Section titled “webhook_deliveries”pub
fn webhook_deliveries(&self) -> WebhookDeliveriesDAL<'_>Provides access to the Webhook Deliveries Data Access Layer.
Returns:
An instance of WebhookDeliveriesDAL.
Source
pub fn webhook_deliveries(&self) -> WebhookDeliveriesDAL<'_> { WebhookDeliveriesDAL { dal: self } }audit_logs
Section titled “audit_logs”pub
fn audit_logs(&self) -> AuditLogsDAL<'_>Provides access to the Audit Logs Data Access Layer.
Returns:
An instance of AuditLogsDAL.
Source
pub fn audit_logs(&self) -> AuditLogsDAL<'_> { AuditLogsDAL { dal: self } }enum DalError
Section titled “enum DalError”pub
Error types for DAL operations.
Variants
Section titled “Variants”ConnectionPool- Failed to get a connection from the poolQuery- Database query errorNotFound- Resource not found
enum FilterType
Section titled “enum FilterType”pub
Variants
Section titled “Variants”AndOr