rkt_sync_db_pools_codegen 0.3.2

Procedural macros for rocket_sync_db_pools.
Documentation
  • Coverage
  • 100%
    2 out of 2 items documented0 out of 1 items with examples
  • Size
  • Source code size: 39.1 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 306.49 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 7s Average build duration of successful builds.
  • all releases: 7s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • martynp

sync_db_pools ci.svg crates.io docs.svg

This crate provides traits, utilities, and a procedural macro for configuring and accessing database connection pools in Rocket. This implementation is backed by r2d2 and exposes connections through request guards.

Usage

First, enable the feature corresponding to your database type:

[dependencies.rkt_sync_db_pools]
version = "0.3.2"
features = ["diesel_sqlite_pool"]

A full list of supported databases and their associated feature names is available in the crate docs. In whichever configuration source you choose, configure a databases dictionary with a key for each database, here sqlite_logs in a TOML source:

[default.databases]
sqlite_logs = { url = "/path/to/database.sqlite" }

In your application's source code:

#[macro_use] extern crate rocket;

use rkt_sync_db_pools::{database, diesel};

#[database("sqlite_logs")]
struct LogsDbConn(diesel::SqliteConnection);

#[get("/logs/<id>")]
async fn get_logs(conn: LogsDbConn, id: usize) -> Result<Logs> {
    conn.run(|c| Logs::by_id(c, id)).await
}

#[launch]
fn rocket() -> _ {
    rkt::build().attach(LogsDbConn::fairing())
}

See the crate docs for full details.