pub mod pool;
pub mod transaction;
pub use pool::{
AsyncConnectionManager, AsyncDbPool, AsyncPooledConnection, ConnectionManager, DbPool,
DbPoolConfig, DbPoolError, DbPoolStats, PooledConnection,
};
#[cfg(feature = "sqlite")]
pub mod sqlite;
#[cfg(feature = "postgres")]
pub mod postgres;
#[cfg(feature = "mysql")]
pub mod mysql;
#[cfg(feature = "sqlite")]
pub use sqlite::{SqliteConnection, SqliteError, SqliteRow, SqliteTransaction, SqliteValue};
#[cfg(feature = "postgres")]
pub use postgres::{
Format as PgFormat, FromSql as PgFromSql, IsNull as PgIsNull, PgColumn, PgConnectOptions,
PgConnection, PgError, PgRow, PgStatement, PgTransaction, PgValue, PreparedCacheStats, SslMode,
ToSql as PgToSql, oid as pg_oid,
};
#[cfg(feature = "mysql")]
pub use mysql::{
MySqlColumn, MySqlConnectOptions, MySqlConnection, MySqlConnectionManager, MySqlError,
MySqlPreparedCacheStats, MySqlRow, MySqlTransaction, MySqlValue, SslMode as MySqlSslMode,
column_type as mysql_column_type,
};
#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
pub(crate) fn remaining_budget(cx: &crate::cx::Cx) -> Option<std::time::Duration> {
let deadline = cx.budget().deadline?;
let now = cx
.timer_driver()
.map_or_else(crate::time::wall_now, |timer| timer.now());
Some(std::time::Duration::from_nanos(
deadline.duration_since(now),
))
}
#[cfg(feature = "sqlite")]
pub(crate) fn effective_statement_timeout(
cx: &crate::cx::Cx,
override_timeout: Option<std::time::Duration>,
) -> Option<std::time::Duration> {
[remaining_budget(cx), override_timeout]
.into_iter()
.flatten()
.min()
}
#[cfg(any(feature = "sqlite", feature = "postgres", feature = "mysql"))]
pub(crate) fn statement_timeout_millis(timeout: std::time::Duration) -> u64 {
let millis = timeout.as_millis();
let rounded = if timeout.subsec_nanos() % 1_000_000 == 0 {
millis
} else {
millis + 1
};
u64::try_from(rounded).unwrap_or(u64::MAX).max(1)
}
#[cfg(any(feature = "postgres", feature = "mysql"))]
pub(crate) fn wire_statement_timeout_ms(
cx: &crate::cx::Cx,
override_timeout: Option<std::time::Duration>,
) -> Option<u64> {
let remaining_ms = remaining_budget(cx).map(|remaining| {
let ms = statement_timeout_millis(remaining);
if ms <= 100 {
ms
} else {
ms.div_ceil(50).saturating_mul(50)
}
});
let override_ms = override_timeout.map(statement_timeout_millis);
[remaining_ms, override_ms].into_iter().flatten().min()
}