Database

DatabaseConfig, from_env, from_url, pool, timeouts.

● ● ●
// .env
// DATABASE_URL=postgres://user:pass@localhost:5432/mydb

let config = DatabaseConfig::from_env()?
    .min_connections(1)
    .max_connections(20)
    .build();

// handed to the builder: .with_database(db)
let db = config.connect().await?;
let config = DatabaseConfig::from_url(
    "postgres://user:pass@localhost:5432/mydb"
)?
.max_connections(50)
.connect_timeout(Duration::from_secs(10))
.build();

let db = config.connect().await?;
postgres://  or  postgresql://   -> PostgreSQL
mysql://                         -> MySQL
mariadb://                       -> MariaDB
sqlite://                        -> SQLite

// Cargo.toml — exactly one engine (two at once is a compile error)
runique = { version = "3.0.0", features = ["postgres"] }
runique = { version = "3.0.0", features = ["mysql"] }    # or "mariadb"
runique = { version = "3.0.0", features = ["sqlite"] }