fernandobatels / rsfbclient

Rust Firebird Client
MIT License
76 stars 11 forks source link

Cannot get connectionpool working with embedded db #116

Closed rfx77 closed 3 years ago

rfx77 commented 3 years ago

Hi!

I cannot compile the r2d2 sample with embedded db:

    let builder =
        rsfbclient::builder_native()
            .with_dyn_load("C:\\develop\\libs\\fb4\\fbclient.dll")
            .with_embedded()
            .db_name("c:\\temp\\test.fdb")
            .user("SYSDBA");

    let manager = FirebirdConnectionManager::new(builder);
    let pool = Arc::new(r2d2::Pool::builder().max_size(4).build(manager).unwrap());

The Error is:

error[E0277]: the trait bound `&mut NativeConnectionBuilder<DynLoad, ConnEmbedded>: FirebirdClientFactory` is not satisfied
  --> src\main.rs:51:50
   |
51 |     let manager = FirebirdConnectionManager::new(builder);
   |                                                  ^^^^^^^ the trait `FirebirdClientFactory` is not implemented for `&mut NativeConnectionBuilder<DynLoad, ConnEmbedded>`
   |
   = help: the following implementations were found:
             <NativeConnectionBuilder<DynLoad, A> as FirebirdClientFactory>
   = note: required by `FirebirdConnectionManager::<F>::new`

i am new to rust so i cannot figure out how to fix this.

fernandobatels commented 3 years ago

This is not supported yet: https://github.com/fernandobatels/rsfbclient/blob/f870184931af227f7e9c0ab7fb08f51c1d8a4cee/r2d2_firebird/src/lib.rs#L30

jairinhohw commented 3 years ago

Try this:

let mut builder = rsfbclient::builder_native()
    .with_dyn_load("C:\\develop\\libs\\fb4\\fbclient.dll")
    .with_embedded();

builder.db_name("c:\\temp\\test.fdb").user("SYSDBA");

let manager = FirebirdConnectionManager::new(builder);
let pool = Arc::new(r2d2::Pool::builder().max_size(4).build(manager).unwrap());

The builder is a bit awkward because there are some methods that consume the builder and others that take it by mutable reference. with_dyn_load and with_embedded take the builder and return a new one, but the other ones just modify the existing builder, so you need to store the builder in a mutable variable, then call the functions.