sfackler / r2d2

A generic connection pool for Rust
Apache License 2.0
1.49k stars 80 forks source link

Adds an `always_keep_alive` function for in-memory databases like sqlite #102

Closed joelgallant closed 4 years ago

joelgallant commented 4 years ago

Because of things like tokio-diesel, sometimes it makes sense to use r2d2 with an in-memory database. It was very confusing to see r2d2 handle things totally fine until 30 minutes (max lifetime), until realizing what was actually happening.

This could very well be a documentation item too, I have no real opinion. But somewhere greppable for :memory:/sqlite would be awesome.

sfackler commented 4 years ago

If you only want one connection to the database, why use a pool at all rather than just a Mutex<SqliteConnection>?

joelgallant commented 4 years ago

Specifically, I use tokio-diesel (which has an impl for r2d2), and I only have one case in my application (can't say very much about it) which is :memory:, and by configuration could be in-memory or not. I wouldn't want to write two implementations of every database call just to handle that, so my solution is to use r2d2 with only one persistent "connection" to :memory:. Maybe there's a better way?

sfackler commented 4 years ago

Given that this seems like a pretty niche use case and you can use the existing configuration to support it, I don't really think it's necessary to introduce a "compound" configuration option for the first time.