pub struct DatabaseManager { /* private fields */ }
Expand description
Main database manager using sqlx for async operations
Implementations§
Source§impl DatabaseManager
impl DatabaseManager
Sourcepub async fn new(database_url: &str) -> Result<Self>
pub async fn new(database_url: &str) -> Result<Self>
Create a new database manager with automatic migrations
Sourcepub async fn new_in_memory() -> Result<Self>
pub async fn new_in_memory() -> Result<Self>
Create an in-memory database for testing
Sourcepub fn pool(&self) -> &SqlitePool
pub fn pool(&self) -> &SqlitePool
Get a reference to the connection pool
Sourcepub async fn begin_transaction(&self) -> Result<Transaction<'_, Sqlite>>
pub async fn begin_transaction(&self) -> Result<Transaction<'_, Sqlite>>
Start a new database transaction
Source§impl DatabaseManager
impl DatabaseManager
Sourcepub async fn upsert_agent(
&self,
agent_id: &str,
username: &str,
contact_uri: Option<&str>,
) -> Result<()>
pub async fn upsert_agent( &self, agent_id: &str, username: &str, contact_uri: Option<&str>, ) -> Result<()>
Register or update an agent
Sourcepub async fn update_agent_status(
&self,
agent_id: &str,
status: AgentStatus,
) -> Result<()>
pub async fn update_agent_status( &self, agent_id: &str, status: AgentStatus, ) -> Result<()>
Update agent status
Sourcepub async fn get_available_agents(&self) -> Result<Vec<DbAgent>>
pub async fn get_available_agents(&self) -> Result<Vec<DbAgent>>
Get available agents
Sourcepub async fn reserve_agent(&self, agent_id: &str) -> Result<bool>
pub async fn reserve_agent(&self, agent_id: &str) -> Result<bool>
Reserve an agent atomically
Sourcepub async fn update_agent_call_count(
&self,
agent_id: &str,
delta: i32,
) -> Result<()>
pub async fn update_agent_call_count( &self, agent_id: &str, delta: i32, ) -> Result<()>
Update agent call count
Sourcepub async fn get_agent_stats(&self) -> Result<AgentStats>
pub async fn get_agent_stats(&self) -> Result<AgentStats>
Get agent statistics
Source§impl DatabaseManager
impl DatabaseManager
Sourcepub async fn enqueue_call(
&self,
call_id: &str,
session_id: &str,
queue_id: &str,
customer_info: Option<&str>,
priority: i32,
expires_at: DateTime<Utc>,
) -> Result<()>
pub async fn enqueue_call( &self, call_id: &str, session_id: &str, queue_id: &str, customer_info: Option<&str>, priority: i32, expires_at: DateTime<Utc>, ) -> Result<()>
Enqueue a call
Sourcepub async fn get_next_queued_call(
&self,
queue_id: &str,
) -> Result<Option<DbQueuedCall>>
pub async fn get_next_queued_call( &self, queue_id: &str, ) -> Result<Option<DbQueuedCall>>
Get next call in queue
Sourcepub async fn dequeue_call(&self, session_id: &str) -> Result<bool>
pub async fn dequeue_call(&self, session_id: &str) -> Result<bool>
Remove call from queue
Source§impl DatabaseManager
impl DatabaseManager
Sourcepub async fn add_active_call(
&self,
call_id: &str,
agent_id: &str,
session_id: &str,
) -> Result<()>
pub async fn add_active_call( &self, call_id: &str, agent_id: &str, session_id: &str, ) -> Result<()>
Add an active call
Sourcepub async fn remove_active_call(&self, session_id: &str) -> Result<bool>
pub async fn remove_active_call(&self, session_id: &str) -> Result<bool>
Remove an active call
Sourcepub async fn assign_call_to_agent(
&self,
call_id: &str,
session_id: &str,
agent_id: &str,
) -> Result<()>
pub async fn assign_call_to_agent( &self, call_id: &str, session_id: &str, agent_id: &str, ) -> Result<()>
Assign call to agent atomically
pub async fn get_agent(&self, agent_id: &str) -> Result<Option<DbAgent>>
pub async fn list_agents(&self) -> Result<Vec<DbAgent>>
pub async fn mark_agent_offline(&self, agent_id: &str) -> Result<()>
pub async fn count_total_agents(&self) -> Result<i64>
pub async fn get_active_calls_count(&self) -> Result<i64>
pub async fn get_queue_depth(&self, queue_id: &str) -> Result<i64>
pub async fn remove_call_from_queue(&self, session_id: &str) -> Result<()>
pub async fn release_agent_reservation(&self, agent_id: &str) -> Result<()>
pub async fn dequeue_call_for_agent( &self, queue_id: &str, agent_id: &str, ) -> Result<Option<DbQueuedCall>>
pub async fn update_agent_call_count_with_retry( &self, agent_id: &str, delta: i32, ) -> Result<()>
pub async fn update_agent_status_with_retry( &self, agent_id: &str, status: AgentStatus, ) -> Result<()>
pub async fn atomic_assign_call_to_agent( &self, session_id: &str, agent_id: &str, _customer_sdp: String, ) -> Result<()>
pub async fn query(&self, sql: &str, _params: &[&str]) -> Result<()>
pub async fn execute(&self, sql: &str, params: &[String]) -> Result<()>
Trait Implementations§
Source§impl Clone for DatabaseManager
impl Clone for DatabaseManager
Source§fn clone(&self) -> DatabaseManager
fn clone(&self) -> DatabaseManager
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreAuto Trait Implementations§
impl Freeze for DatabaseManager
impl !RefUnwindSafe for DatabaseManager
impl Send for DatabaseManager
impl Sync for DatabaseManager
impl Unpin for DatabaseManager
impl !UnwindSafe for DatabaseManager
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more