Coder Social home page Coder Social logo

bb8's Introduction

bb8

Documentation Crates.io Build status codecov 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 bb8-diesel
tiberius bb8-tiberius
nebula-client bb8-nebula
memcache-async bb8-memcached
lapin bb8-lapin
arangors bb8-arangodb

Example

Using an imaginary "foodb" database.

#[tokio::main]
async fn main() {
    let manager = bb8_foodb::FooConnectionManager::new("localhost:1234");
    let pool = bb8::Pool::builder()
        .max_size(15)
        .build(manager)
        .await
        .unwrap();

    for _ in 0..20 {
        let pool = pool.clone();
        tokio::spawn(async move {
            let conn = pool.get().await.unwrap();
            // use the connection
            // it will be returned to the pool when it falls out of scope.
        });
    }
}

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.

bb8's People

Contributors

djc avatar khuey avatar elpiel avatar dependabot-preview[bot] avatar zainkabani avatar bbigras avatar vorot93 avatar pksunkara avatar nyurik avatar dependabot[bot] avatar evdokimovs avatar r-ml avatar jspeis avatar film42 avatar christophwurst avatar christianbeilschmidt avatar singulared avatar x04 avatar vkill avatar naerbnic avatar crsov avatar 0xwof avatar brokenthorn avatar ta3pks avatar levkk avatar kaibyao avatar jaymell avatar gabor-boros avatar davidpdrsn avatar ricogit avatar

Stargazers

fabio avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.