13 stable releases (3 major)

4.1.0 Mar 21, 2024
4.0.1 Mar 14, 2023
4.0.0 Feb 28, 2023
3.0.2 Sep 10, 2022
1.0.5 Jun 20, 2021

#1284 in Database interfaces

Download history 1/week @ 2024-02-13 48/week @ 2024-02-20 16/week @ 2024-02-27 1/week @ 2024-03-05 12/week @ 2024-03-12 156/week @ 2024-03-19 18/week @ 2024-03-26 89/week @ 2024-04-02

550 downloads per month
Used in 2 crates

MIT license

9KB
91 lines

License Cargo Documentation

Simple static diesel r2d2 connection pooling.

ENV Configuration

  • DATABASE_URL sets connection url

  • MAX_DB_CONNECTIONS sets max connections within connection pool

The dotenv feature flag enables dotenv loading during pre-main static initialization via dotenvy.


lib.rs:

Static diesel r2d2 connection pooling with env configuration

Composible connection urls are provided by environment variables using env-url using the DATABASE prefix:

 | ENV                     |                            |
 | -----------------------:|:--------------------------:|
 | DATABASE_URL            | set connection url         |
 | DATABASE_HOST           | set url host               |
 | DATABASE_PORT           | set url port               |
 | DATABASE_PATH           | set selected database      |
 | DATABASE_USERINFO       | set connnection userinfo   |

MAX_DB_CONNECTIONS env sets max connections within connection pool

The dotenv feature flag enables automatic at-most-once dotenv loading via dotenvy. This is necessary because pool statics are initialized pre-main via static_init.

use diesel_connection::{pg::get_connection, PoolError};

#[actix_rt::main]
async fn main() -> Result<(), PoolError> {
  let conn = get_connection()?;
}

Dependencies

~5–14MB
~203K SLoC