{"id":13822554,"url":"https://github.com/importcjj/mobc","last_synced_at":"2025-05-14T10:07:47.115Z","repository":{"id":39618216,"uuid":"217090972","full_name":"importcjj/mobc","owner":"importcjj","description":"A generic connection pool for Rust with async/await support","archived":false,"fork":false,"pushed_at":"2025-01-24T19:20:55.000Z","size":286,"stargazers_count":285,"open_issues_count":10,"forks_count":44,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-04-08T09:12:22.937Z","etag":null,"topics":["async","await","connection-pool","database","pool","postgres","redis","rust","rust-lang"],"latest_commit_sha":null,"homepage":"https://docs.rs/mobc","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/importcjj.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE-APACHE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-23T15:27:15.000Z","updated_at":"2025-02-21T14:59:02.000Z","dependencies_parsed_at":"2023-09-27T16:21:57.958Z","dependency_job_id":"885f93e5-84d8-4ce4-9241-90801816dbd1","html_url":"https://github.com/importcjj/mobc","commit_stats":{"total_commits":236,"total_committers":25,"mean_commits":9.44,"dds":"0.27542372881355937","last_synced_commit":"523cccf413e91daa040d212ea0be051f167d8be3"},"previous_names":[],"tags_count":12,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Fmobc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Fmobc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Fmobc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/importcjj%2Fmobc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/importcjj","download_url":"https://codeload.github.com/importcjj/mobc/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248336076,"owners_count":21086706,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["async","await","connection-pool","database","pool","postgres","redis","rust","rust-lang"],"created_at":"2024-08-04T08:02:05.886Z","updated_at":"2025-04-11T03:33:34.178Z","avatar_url":"https://github.com/importcjj.png","language":"Rust","funding_links":[],"categories":["Rust"],"sub_categories":[],"readme":"# Mobc\n\nA generic connection pool with async/await support.\n\nInspired by Deadpool, Sqlx, r2d2 and Golang SQL package.\n\n[Changelog](https://github.com/importcjj/mobc/blob/main/CHANGELOG.md)\n\n**Note: mobc requires at least Rust 1.60.**\n\n## Usage\n\n```toml\n[dependencies]\nmobc = \"0.8\"\n\n# For async-std runtime\n# mobc = { version = \"0.8\", features = [\"async-std\"] }\n\n# For actix-rt 1.0\n# mobc = { version = \"0.8\", features = [\"actix-rt\"] }\n```\n\n## Features\n\n- Support async/.await syntax\n- Support both `tokio` and `async-std`\n- Tokio metric support\n- Production battle tested\n- High performance\n- Easy to customize\n- Dynamic configuration\n\n## Adaptors\n\n| Backend                                                                                   | Adaptor Crate                                                           |\n| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------- |\n| [bolt-client](https://crates.io/crates/bolt-client)                                       | [mobc-bolt](https://crates.io/crates/mobc-bolt)                         |\n| [tokio-postgres](https://github.com/sfackler/rust-postgres)                               | [mobc-postgres](https://github.com/importcjj/mobc-postgres)             |\n| [redis](https://github.com/mitsuhiko/redis-rs)                                            | [mobc-redis](https://github.com/importcjj/mobc-redis)                   |\n| [arangodb](https://github.com/fMeow/arangors)                                             | [mobc-arangors](https://github.com/inzanez/mobc-arangors)               |\n| [lapin](https://github.com/CleverCloud/lapin)                                             | [mobc-lapin](https://github.com/zupzup/mobc-lapin)                      |\n| [reql](https://github.com/rethinkdb/rethinkdb-rs)                                         | [mobc-reql](https://github.com/rethinkdb/rethinkdb-rs)                  |\n| [redis-cluster](https://docs.rs/redis_cluster_async/0.6.0/redis_cluster_async/index.html) | [mobc-redis-cluster](https://github.com/rogeriob2br/mobc-redis-cluster) |\n\nMore DB adaptors are welcome.\n\n## Examples\n\nMore [examples](https://github.com/importcjj/mobc/tree/main/examples)\n\nUsing an imaginary \"foodb\" database.\n\n```rust\nuse mobc::{async_trait, Manager};\n\n#[derive(Debug)]\npub struct FooError;\n\npub struct FooConnection;\n\nimpl FooConnection {\n    pub async fn query(\u0026self) -\u003e String {\n        \"PONG\".to_string()\n    }\n}\n\npub struct FooManager;\n\n#[async_trait]\nimpl Manager for FooManager {\n    type Connection = FooConnection;\n    type Error = FooError;\n\n    async fn connect(\u0026self) -\u003e Result\u003cSelf::Connection, Self::Error\u003e {\n        Ok(FooConnection)\n    }\n\n    async fn check(\u0026self, conn: Self::Connection) -\u003e Result\u003cSelf::Connection, Self::Error\u003e {\n        Ok(conn)\n    }\n}\n```\n\n## Configures\n\n#### max_open\n\nSets the maximum number of connections managed by the pool.\n\n\u003e 0 means unlimited, defaults to 10.\n\n#### max_idle\n\nSets the maximum idle connection count maintained by the pool. The pool will maintain at most this many idle connections at all times, while respecting the value of max_open.\n\n#### max_lifetime\n\nSets the maximum lifetime of connections in the pool. Expired connections may be closed lazily before reuse.\n\n\u003e None meas reuse forever, defaults to None.\n\n#### get_timeout\n\nSets the get timeout used by the pool. Calls to Pool::get will wait this long for a connection to become available before returning an error.\n\n\u003e None meas never timeout, defaults to 30 seconds.\n\n## Variable\n\nSome of the connection pool configurations can be adjusted dynamically. Each connection pool instance has the following methods:\n\n- set_max_open_conns\n- set_max_idle_conns\n- set_conn_max_lifetime\n\n## Stats\n\n- max_open - Maximum number of open connections to the database.\n- connections - The number of established connections both in use and idle.\n- in_use - The number of connections currently in use.\n- idle - The number of idle connections.\n- wait_count - The total number of connections waited for.\n- wait_duration - The total time blocked waiting for a new connection.\n- max_idle_closed - The total number of connections closed due to max_idle.\n- max_lifetime_closed - The total number of connections closed due to max_lifetime.\n\n## Metrics\n\n- Counters\n    - `mobc_pool_connections_opened_total` - Total number of Pool Connections opened\n    - `mobc_pool_connections_closed_total` - Total number of Pool Connections closed\n- Gauges\n    - `mobc_pool_connections_open` - Number of currently open Pool Connections\n    - `mobc_pool_connections_busy` - Number of currently busy Pool Connections (executing a database query)\"\n    - `mobc_pool_connections_idle` - Number of currently unused Pool Connections (waiting for the next pool query to run)\n    - `mobc_client_queries_wait` - Number of queries currently waiting for a connection\n- Histograms\n    - `mobc_client_queries_wait_histogram_ms` - Histogram of the wait time of all queries in ms\n  \n## Compatibility\n\nBecause tokio is not compatible with other runtimes, such as async-std. So a database driver written with tokio cannot run in the async-std runtime. For example, you can't use redis-rs in tide because it uses tokio, so the connection pool which bases on redis-res can't be used in tide either.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimportcjj%2Fmobc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fimportcjj%2Fmobc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fimportcjj%2Fmobc/lists"}