{"id":29675759,"url":"https://github.com/oxidecomputer/async-bb8-diesel","last_synced_at":"2025-07-22T23:38:36.363Z","repository":{"id":38191641,"uuid":"400912854","full_name":"oxidecomputer/async-bb8-diesel","owner":"oxidecomputer","description":"Safe asynchronous access to Diesel and the bb8 connection manager","archived":false,"fork":false,"pushed_at":"2025-06-07T06:42:52.000Z","size":115,"stargazers_count":15,"open_issues_count":8,"forks_count":13,"subscribers_count":19,"default_branch":"master","last_synced_at":"2025-07-10T13:36:30.270Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/oxidecomputer.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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,"zenodo":null}},"created_at":"2021-08-28T23:52:37.000Z","updated_at":"2025-04-04T04:33:02.000Z","dependencies_parsed_at":"2025-06-07T07:33:46.098Z","dependency_job_id":null,"html_url":"https://github.com/oxidecomputer/async-bb8-diesel","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/oxidecomputer/async-bb8-diesel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fasync-bb8-diesel","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fasync-bb8-diesel/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fasync-bb8-diesel/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fasync-bb8-diesel/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/oxidecomputer","download_url":"https://codeload.github.com/oxidecomputer/async-bb8-diesel/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/oxidecomputer%2Fasync-bb8-diesel/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266591232,"owners_count":23953082,"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","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-07-22T23:38:26.146Z","updated_at":"2025-07-22T23:38:36.340Z","avatar_url":"https://github.com/oxidecomputer.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# async-bb8-diesel\n\nThis crate provides an interface for asynchronously accessing a bb8 connection\npool atop [Diesel](https://github.com/diesel-rs/diesel).\n\nThis is accomplished by implementing an async version\nof Diesel's \"RunQueryDsl\" trait, aptly named \"AsyncRunQueryDsl\",\nwhich operates on an async-compatible connection. When called\nfrom an async context, these operations transfer the query\nto a blocking tokio thread, where it may be executed.\n\nNOTE: This crate pre-dated [diesel-async](https://docs.rs/diesel-async/).\nFor new code, consider using that interface directly.\n\n# Pre-requisites\n\n- A willingness to tolerate some instability. This crate effectively originated\n  as a stop-gap until more native asynchronous support existed within Diesel.\n\n# Comparisons with existing crates\n\nThis crate was heavily inspired by both\n[tokio-diesel](https://github.com/mehcode/tokio-diesel) and\n[bb8-diesel](https://github.com/overdrivenpotato/bb8-diesel), but serves a\nslightly different purpose.\n\n## What do those crates do?\n\nBoth of those crates rely heavily on the\n[`tokio::block_in_place`](https://docs.rs/tokio/1.10.1/tokio/task/fn.block_in_place.html)\nfunction to actually execute synchronous Diesel queries.\n\nTheir flow is effectively:\n- A query is issued (in the case of tokio-diesel, it's async. In the case\nof bb8-diesel, it's synchronous - but you're using bb8, so presumably\ncalling from an asynchronous task).\n- The query and connection to the DB are moved into the `block_in_place` call.\n- Diesel's native synchronous API is used within `block_in_place`.\n\nThese crates have some advantages by taking this approach:\n- The tokio executor knows not to schedule additional async tasks for the\n  duration of the `block_in_place` call.\n- The callback used within `block_in_place` doesn't need to be `Send` - it\n  executes synchronously within the otherwise asynchronous task.\n\nHowever, they also have some downsides:\n- The call to `block_in_place` effectively pauses an async thread for the\n  duration of the call. This *requires* a multi-threaded runtime, and reduces\n  efficacy of one of these threads for the duration of the call.\n- The call to `block_in_place` starves all other asynchronous code running in\n  the same task.\n\nThis starvation results in some subtle inhibition of other futures, such as in\nthe following example, where a timeout would be ignored if a long-running\ndatabase operation was issued from the same task as a timeout.\n\n```rust\ntokio::select! {\n  // Calls \"tokio::block_in_place\", doing a synchronous Diesel operation\n  // on the calling thread...\n  _ = perform_database_operation() =\u003e {},\n  // ... meaning this asynchronous timeout cannot complete!\n  _ = sleep_until(timeout) = {},\n}\n```\n\n## What does this crate do?\n\nThis crate attempts to avoid calls to `block_in_place` - which would block the\ncalling thread - and prefers to use\n[`tokio::spawn_blocking`](https://docs.rs/tokio/1.10.1/tokio/task/fn.spawn_blocking.html)\nfunction. This function moves the requested operation to an entirely distinct\nthread where blocking is acceptable, but does *not* prevent the current task\nfrom executing other asynchronous work.\n\nThis isn't entirely free - as this work now needs to be transferred to a new\nthread, it imposes a \"Send + 'static\" constraint on the queries which are\nconstructed.\n\n## Which one is right for me?\n\n- If you care about preserving typically expected semantics for asynchronous\n  operations, we recommend this crate.\n- If you don't - maybe you have an asynchronous workload, but you *know*\n  when you can block those threads - you can use either of the\n  tokio-diesel or bb8-diesel crates, depending on whether or not you\n  want access to the asynchronous thread pool.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxidecomputer%2Fasync-bb8-diesel","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Foxidecomputer%2Fasync-bb8-diesel","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Foxidecomputer%2Fasync-bb8-diesel/lists"}