Creating a Pool from Opts / Optsbuilder
peternormann opened this issue · 2 comments
Hi,
I am having a hard time figuring out how the Optsbuilder is supposed to be used. Maybe it's a relic from earlier versions?
I am trying to get a Pool connection, building the Opts used for the connection manually (not using an .env DATABASE_URL variable), but I can't figure out how to get from an Opts(/-builder) to a Pool.
Looking at the Pool:
#[derive(Debug, Clone)]
pub struct Pool {
opts: Opts,
inner: Arc<Inner>,
drop: mpsc::UnboundedSender<Option<Conn>>,
}
impl Pool {
...
pub fn new<O>(opts: O) -> Pool
where
Opts: TryFrom<O>,
<Opts as TryFrom<O>>::Error: std::error::Error,
{
let opts = Opts::try_from(opts).unwrap(); // <-- needs a &str
let pool_opts = opts.pool_opts().clone();
let (tx, rx) = mpsc::unbounded_channel();
Pool {
opts,
<private properties>
}
Even though I have successfully build the Opts instance using Optsbuilder, PoolOptions, Constraints and whatnot, I can't instantiate a Pool connection.
The constraints for the Pool:new method seems to be met, but the first line let opts = Opts::try_from(opts).unwrap();
insists the opts variable is a &str and not an Opts instance.
Since the properties for the Pool struct are private, I can't manually return one from my method and I can't find anywhere I can get a Pool instance using an Opts.
Is it necessary to build a url string rather than make use of the Optsbuilder?
What am I missing?
Hi.
I just compiled the following code without issues, so could you please provide a code sample that illustrates your issue?
// `get_opts` here is just a helper that
// returns an OptsBuilder instance
let opts = Opts::from(get_opts());
let pool = Pool::new(opts);
Please also note, that you can call Poll:new right with an OptsBuilder instance.
Hi, appreciate you taking the time to respond.
It appears I was barking up the wrong tree. It compiles now that I fixed something else. The IDE is complaining about passing the builder to the Pool::new(), but it compiles just fine now. Still trying to learn the ropes here.