pub struct Db { /* private fields */ }Expand description
Handles database interactions for registering JSON objects.
This struct manages the connection pool and executes SQL queries to insert or retrieve JSON objects. It uses optimized queries to handle concurrency and minimize round-trips.
Implementations§
Source§impl Db
impl Db
Sourcepub async fn new(
connection_string: &str,
table_name: &str,
id_column: &str,
jsonb_column: &str,
pool_size: u32,
acquire_timeout_secs: Option<u64>,
idle_timeout_secs: Option<u64>,
max_lifetime_secs: Option<u64>,
) -> Result<Self, Error>
pub async fn new( connection_string: &str, table_name: &str, id_column: &str, jsonb_column: &str, pool_size: u32, acquire_timeout_secs: Option<u64>, idle_timeout_secs: Option<u64>, max_lifetime_secs: Option<u64>, ) -> Result<Self, Error>
Creates a new Db instance.
§Arguments
connection_string- The PostgreSQL connection string.table_name- The name of the table.id_column- The name of the ID column.jsonb_column- The name of the JSONB column.pool_size- The maximum number of connections in the pool.acquire_timeout_secs- Optional timeout for acquiring connections (default: 5s).idle_timeout_secs- Optional timeout for idle connections (default: 600s).max_lifetime_secs- Optional maximum lifetime for connections (default: 1800s).
§Returns
A Result containing the new Db instance or a sqlx::Error.
Sourcepub async fn register_batch_objects(
&self,
json_strs: &[String],
) -> Result<Vec<i32>, Error>
pub async fn register_batch_objects( &self, json_strs: &[String], ) -> Result<Vec<i32>, Error>
Sourcepub fn pool_size(&self) -> usize
pub fn pool_size(&self) -> usize
Returns the current size of the connection pool.
This is the total number of connections (both idle and active) currently in the pool. Useful for monitoring pool utilization.
§Returns
The number of connections in the pool.
Sourcepub fn idle_connections(&self) -> usize
pub fn idle_connections(&self) -> usize
Returns the number of idle connections in the pool.
Idle connections are available for immediate use. A low idle count during high load may indicate the pool is undersized.
§Returns
The number of idle connections.
Auto Trait Implementations§
impl Freeze for Db
impl !RefUnwindSafe for Db
impl Send for Db
impl Sync for Db
impl Unpin for Db
impl !UnwindSafe for Db
Blanket Implementations§
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> 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