2 releases
Uses new Rust 2024
| 0.2.10 | Nov 3, 2025 |
|---|---|
| 0.2.9 | Nov 1, 2025 |
#1504 in Database interfaces
31KB
519 lines
librust-db
[!CAUTION] The content of this repository is publicly accessible; do not add secret or sensitive information.
lib.rs:
Database connection pooling and management using Diesel with async support.
This library provides a convenient wrapper around diesel-async with bb8 connection pooling, supporting both SSL and non-SSL PostgreSQL connections.
Example
use librust_db::sql::{Builder, PoolConfig, Pooling};
// Create a database connection with custom pool configuration
let pool_config = PoolConfig {
max_size: 10,
min_idle: Some(2),
connection_timeout_secs: 30,
max_lifetime_secs: Some(1800), // Close connections after 30 minutes
idle_timeout_secs: Some(600), // Close idle connections after 10 minutes
test_on_checkout: true, // Validate connections before use
retry_attempts: 3, // Retry connection acquisition 3 times
};
let db = Builder::new(Some("postgres://user:pass@localhost/mydb".to_string()))
.with_pool_config(pool_config)
.disable_ssl()
.await?;
// Check database health
db.health_check().await?;
// Get a connection with retry logic
let mut conn = db.get_connection_with_retry(3, 100).await?;
// Get pool statistics
let state = db.state();
println!("Active connections: {}", state.connections);
println!("Idle connections: {}", state.idle_connections);
Dependencies
~20–34MB
~588K SLoC