Developing a Wasm Wrapper
This guide will create a GitHub FDW which you can use to query the GitHub Events API using Postgres.
Install pre-requisites
The template uses The WebAssembly Component Model to build the WebAssembly package, so we need to install various dependencies.
- Install the Rust Toolchain if it is not already installed on your machine.
- Add
wasm32-unknown-unknown
target:1
rustup target add wasm32-unknown-unknown
- Install the WebAssembly Component Model subcommand:
1
cargo install cargo-component --locked --version 0.13.2
Fork the Wasm FDW Template
Our quickstart template will allow you to create a new Wasm Wrapper that can query the GitHub Events API. To get started:
- Go to github.com/supabase-community/postgres-wasm-fdw
- Fork the repo to your own GitHub account by by clicking the
Use this template
button on top right of this page - Clone the repo to your local machine.
Rename and create a new version
Open Cargo.toml
and update the following lines to any name and version you want:
1 2 3 4 5 6 |
|
In our example, we're going to update it to these credentials:
1 2 3 4 5 6 |
|
Open wit/world.wit
and update the package name and version:
1 |
|
Save and commit your code:
1 2 3 |
|
Release the Wasm FDW package
To create a release of the Wasm FDW package, create a version tag and then push it.
1 2 |
|
This will trigger a GitHub workflow to build the package and create a release on your repo. It may take a few minutes:
After the GitHub action has completed, expand the Create README.txt
step, which will have your installation instructions at the bottom - something like:
1 2 3 4 5 |
|
Install your FDW
You can install the FDW on any Postgres platform that supports Wrappers >=0.4.1
.
Check compatibility
1 2 3 |
|
Enable Wrappers
Enable the Wrappers extension and initialize the Wasm FDW on any platform that supports Wrappers:
1 2 3 4 5 |
|
Install your Wrapper from GitHub
Create foreign server and foreign table like below. You will need to update the options
to match your release above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Tip
You can copy the DDL from released README.txt
file, which can be downloaded from the release page like: https://github.com/<ORG>/<REPO>/releases/tag/v0.2.0
Query your wrapper
Query the foreign table to see what's happening on GitHub:
1 2 3 4 5 6 7 8 9 |
|
👏 👏 Congratulations! You have built your first Wasm FDW.
Clean up
Run the following code to remove the FDW:
1 2 |
|