svn>> bb8>> 返回
项目作者: djc

项目描述 :
Full-featured async (tokio-based) postgres connection pool (like r2d2)
高级语言: Rust
项目地址: git://github.com/djc/bb8.git
创建时间: 2018-01-29T21:38:04Z
项目社区:https://github.com/djc/bb8

开源协议:MIT License

下载


bb8

Documentation
Crates.io
Build status
codecov
Chat
License: MIT

A full-featured connection pool, designed for asynchronous connections (using
tokio). Originally based on r2d2.

Opening a new database connection every time one is needed is both inefficient
and can lead to resource exhaustion under high traffic conditions. A connection
pool maintains a set of open connections to a database, handing them out for
repeated use.

bb8 is agnostic to the connection type it is managing. Implementors of the
ManageConnection trait provide the database-specific logic to create and
check the health of connections.

A (possibly not exhaustive) list of adapters for different backends:

Backend Adapter Crate
tokio-postgres bb8-postgres (in-tree)
redis bb8-redis (in-tree)
redis_cluster_async bb8-redis-cluster
rsmq rsmq_async
bolt-client bb8-bolt
diesel diesel_async
tiberius bb8-tiberius
nebula-client bb8-nebula
memcache-async bb8-memcached
lapin bb8-lapin
arangors bb8-arangodb

Example

Using an imaginary “foodb” database.

  1. #[tokio::main]
  2. async fn main() {
  3. let manager = bb8_foodb::FooConnectionManager::new("localhost:1234");
  4. let pool = bb8::Pool::builder()
  5. .max_size(15)
  6. .build(manager)
  7. .await
  8. .unwrap();
  9. for _ in 0..20 {
  10. let pool = pool.clone();
  11. tokio::spawn(async move {
  12. let conn = pool.get().await.unwrap();
  13. // use the connection
  14. // it will be returned to the pool when it falls out of scope.
  15. });
  16. }
  17. }

License

Licensed under the MIT license (LICENSE).

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted
for inclusion in the work by you shall be licensed as above, without any
additional terms or conditions.