rust-mysql-simple icon indicating copy to clipboard operation
rust-mysql-simple copied to clipboard

Add pool_constraints method to OptsBuilder to set pool_min and pool_max

Open Elcoid opened this issue 1 year ago • 2 comments

Hello,

I added a method to OptsBuilder that sets pool_min and pool_max directly. This way, they can be set without having to instantiate a hashmap, then pass it to from_hash_map, then parse the strings in the map as integers. The method sets the two at the same time to ensure that pool_min <= pool_max (using a PoolConstraints).

Elcoid avatar Jan 23 '24 00:01 Elcoid

Hi. I don't really think it's a good idea to increase the API surface. Why don't you use OptsBuilder::pool_opts?

blackbeam avatar Jan 24 '24 09:01 blackbeam

Hello, Initially I searched for pool_min and pool_max in the sources, but the only thing I found was OptsBuilder::from_hash_map. That's why I thought an extra method would be good. However I just tried your suggestion and it works well (thanks for the idea). So I think my PR can be dismissed.

Here is what I ended up with, in case anyone else has the same problem as me:

let opts = OptsBuilder::new()
    /* [...] */
    .pool_opts(
        PoolOpts::default()
        .with_constraints(PoolConstraints::new(my_min, my_max).expect("Min is bigger than max!"))
    );

Elcoid avatar Jan 24 '24 16:01 Elcoid