feat(postgres): Cloudflare Hyperdrive driver — tokio-postgres on wasm32 - #57
Merged
Conversation
Run the existing tokio-postgres driver inside Cloudflare Workers through
the Hyperdrive binding. Not a separate driver: worker::Socket implements
tokio's AsyncRead/AsyncWrite, so Config::connect_raw hands back the same
Client the native driver wraps — the entire query surface, transactions,
savepoints, prepared statements and cache, relational queries, migrate
(incl. dirty detection and repair), push, and introspect compile verbatim
for wasm32-unknown-unknown. The new module is only the dial:
postgres::hyperdrive::{connect, connect_raw}, spawning the connection
future via spawn_local and using NoTls per Hyperdrive's edge-terminated
TLS. PG's binary wire format means exact i64/numeric/bytea round-trips,
unlike the JS-number-bounded d1/durable drivers.
Feature wiring: the workspace tokio-postgres dep drops its runtime
feature (which only gates Config::connect and pulls tokio/net + mio);
native consumers re-add it additively, so native builds are unchanged.
The hyperdrive feature must use the weak form tokio-postgres?/js — the
plain form resolves to the same-named root feature and drags runtime
back in. CI gains wasm32 checks for hyperdrive and hyperdrive,query.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
|
Bugbot is not enabled for your account, so this pull request was not reviewed. Enable Bugbot in the Cursor dashboard to get automatic reviews on future PRs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Runs the existing tokio-postgres driver inside Cloudflare Workers through the Hyperdrive binding — not a separate driver.
worker::Socketimplements tokio's AsyncRead/AsyncWrite, soConfig::connect_rawyields the sameClientthe native driver wraps; the whole surface (queries, row streaming, transactions, savepoints, prepared statements + cache, relational direct/prepared, migrate incl. dirty detection and--repair, push, introspect) compiles verbatim for wasm32. The only new code is the 42-line dial modulepostgres::hyperdrive::{connect, connect_raw}(spawn_local for the connection future, NoTls per Hyperdrive's edge-terminated TLS).tokio-postgresdep dropsruntime(it only gatesConfig::connect); native consumers re-add it additively — native builds byte-identical.tokio-postgres, only the weaktokio-postgres?/jsform avoids re-enablingruntime.i64/numeric/bytea, unlike the JS-number-bounded d1/durable drivers.hyperdriveandhyperdrive,queryadded to the wasm-drivers job.Test plan
cargo check --target wasm32-unknown-unknown --no-default-features --features hyperdrive(+,query)--all-features --all-targets -D warnings, migrations/core/postgres crate suites, root sqlite suite🤖 Generated with Claude Code