Skip to content

feat: export Connection type and document with_pool() for sharing an existing db pool#98

Open
Copilot wants to merge 2 commits intomasterfrom
copilot/add-diesel-adapter-constructor
Open

feat: export Connection type and document with_pool() for sharing an existing db pool#98
Copilot wants to merge 2 commits intomasterfrom
copilot/add-diesel-adapter-constructor

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 10, 2026

Users had no clear way to share an existing r2d2::Pool with DieselAdapter. The with_pool() constructor already existed but was undiscoverable — the Connection type alias it requires was internal, and there was no documentation or example showing its use.

Changes

  • src/lib.rs — Re-export actions::Connection so users can correctly type their pool as Pool<ConnectionManager<Connection>> without knowing the underlying concrete connection type
  • src/adapter.rs — Add doc comments to new() and with_pool(); with_pool() includes a runnable example; add test_with_pool unit test
  • README.md — Split the Example section into two subsections covering both constructors

Usage

use diesel::r2d2::{ConnectionManager, Pool};
use diesel_adapter::{casbin::prelude::*, Connection, DieselAdapter};

let database_url = std::env::var("DATABASE_URL").expect("DATABASE_URL must be set");
let manager = ConnectionManager::<Connection>::new(database_url);
let pool = Pool::builder().max_size(8).build(manager).unwrap();

// Pass your application's existing pool directly
let a = DieselAdapter::with_pool(pool)?;
let mut e = Enforcer::new(m, a).await?;
Original prompt

This section details on the original issue you should resolve

<issue_title>Use my existing Db pool for constructing diesel_adapter::DieselAdapter</issue_title>
<issue_description>I want to share my app's db pool to casbin, is it possible to have a new constructor that takes diesel:r2d2:Pool as parameter instead of taking number of connections?</issue_description>

Comments on the Issue (you are @copilot in this section)


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

… sharing existing db pool

Co-authored-by: hsluoyz <3787410+hsluoyz@users.noreply.github.com>
@CLAassistant
Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI changed the title [WIP] Add constructor for DieselAdapter using existing Db pool feat: export Connection type and document with_pool() for sharing an existing db pool Mar 10, 2026
@hsluoyz hsluoyz marked this pull request as ready for review March 10, 2026 10:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Use my existing Db pool for constructing diesel_adapter::DieselAdapter

3 participants