https://github.com/exograph/wasm-pg-cloudflare-explorations
Code accompanying https://exograph.dev/blog/wasm-pg-explorations-1 and https://exograph.dev/blog/wasm-pg-explorations-2
https://github.com/exograph/wasm-pg-cloudflare-explorations
Last synced: 10 days ago
JSON representation
Code accompanying https://exograph.dev/blog/wasm-pg-explorations-1 and https://exograph.dev/blog/wasm-pg-explorations-2
- Host: GitHub
- URL: https://github.com/exograph/wasm-pg-cloudflare-explorations
- Owner: exograph
- License: apache-2.0
- Created: 2024-06-06T12:32:36.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-06-06T13:20:17.000Z (over 1 year ago)
- Last Synced: 2025-03-23T08:22:44.437Z (10 months ago)
- Language: Rust
- Homepage: https://exograph.dev/blog/wasm-pg-explorations-1
- Size: 18.6 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Code accompanying the blog post "Latency at the Edge with Rust/WebAssembly and Postgres" [Part 1](https://exograph.dev/blog/wasm-pg-explorations-1) and [Part 2](https://exograph.dev/blog/wasm-pg-explorations-2).
## Common setup
Visit [Neon](https://neon.tech) and create a database, say, `todo-db`, with the following table:
```sql
CREATE TABLE todos (
id SERIAL PRIMARY KEY,
title TEXT NOT NULL,
completed BOOLEAN NOT NULL
);
```
## Creating a Hyperdrive
You need to create a Hyperdrive instance only once but update `wrangler.toml` for each project.
Replace the connection string with the one from the Neon dashboard.
```sh
npx wrangler hyperdrive create todo-db-hyperdrive --caching-disabled --connection-string "postgres://alex:AbC123dEf@ep-cool-darkness-123456.us-east-2.aws.neon.tech/dbname"
```
Add the following to `wrangler.toml` in each `rust-hyperdrive-*` project:
```toml
[[hyperdrive]]
binding = "todo-db-hyperdrive"
id = ""
```
## Setting the DATABASE_URL secret
For all `rust-direct-*` projects, set the following environment variables. Alternatively, you can use the "Integration" tab in the Cloudflare Worker's dashboard to add the Neon integration, which does the same thing.
```sh
npx wrangler secret put DATABASE_URL
```
This will ask for the connection URL, which you can obtain from the Neon dashboard.
## Deploying
```sh
npx wrangler deploy
```
## Testing performance
Install [oha](https://github.com/hatoo/oha) using `cargo install oha`.
```sh
oha -c 1 -n 100
```
Of course, you can adjust the concurrency and number of requests as needed.