Postgres Foreign Data Wrappers with Wasm
Supabase Wrappers, a Rust framework for building Postgres Foreign Data Wrappers, now supports WebAssembly FDWs that are downloaded from URLs like GitHub or S3, checksum-verified, cached and run in a sandboxed Wasm runtime inside the Postgres extension. The host extension provides the runtime, an HTTP interface and utilities, while each guest FDW fetches data from HTTP JSON APIs. TCP-based databases and local files are not yet supported. Snowflake and Paddle Wasm FDWs ship built in, a SQL walkthrough shows creating a Paddle server and foreign table, and wrappers from untrusted sources should never be installed.
Related posts
- Supabase Wrappers, a Postgres FDW framework written in Rust
Supabase mediumAdeptSupabase Wrappers is an alpha Rust framework, built on pgx, for writing Postgres Foreign Data Wrappers that expose external systems such as Stripe and Firebase as queryable foreign tables. A worked example connects a Stripe account, maps products to a foreign table and queries it with SQL or the Supabase JS client. Wrappers also support a "QETL" (query, extract, transform, load) pattern: query warehouses like Snowflake on demand, join remote data with local tables, and materialize results with pg_cron. The framework adds async support for REST-API-backed FDWs and early push-down support, with ClickHouse, BigQuery and Airtable wrappers in development.
- Supabase Wrappers v0.2: Query Pushdown & Remote Subqueries
Supabase mediumAdeptSupabase Wrappers v0.2, a Rust-based Postgres foreign data wrapper framework for querying third-party sources with SQL, adds query pushdown, remote subqueries and per-FDW usage statistics. Pushdown is implemented inside each wrapper, so a filter on a Stripe customer id becomes a single API call and ClickHouse queries can push down ORDER BY and LIMIT. Remote subqueries map a static query, or a parameterized ClickHouse/BigQuery view whose parameters are exposed as columns, onto a foreign table. A new wrappers_fdw_stats table records rows and bytes transferred in each direction for spotting bottlenecks, and the release also adds Airtable and S3 wrappers.
- Postgres WASM by Snaplet and Supabase
Supabase mediumAdeptpostgres-wasm runs a full PostgreSQL 14 server in the browser by emulating an x86 machine with v86 rather than compiling Postgres to WASM directly. It boots a minimal Buildroot Linux image and lazily loads the rest over a 9P filesystem via HTTPS, and it uses the page_poison=on kernel parameter so freed memory compresses well, which brings the snapshot of a running Postgres down to about 12MB. Networking goes through a forked websockproxy that converts raw ethernet frames into TCP, with an nginx reverse proxy that maps private IPs to ports so external clients like psql, PgAdmin or a logical replication peer can connect. Other hurdles included a v86 JIT bug that caused PG14 segfaults, worked around by switching Postgres to sysv shared memory, and an inbox-folder listener for running scripts inside the VM.
- Calendars in Postgres using Foreign Data Wrappers
Supabase mediumAdeptA Cal.com Foreign Data Wrapper, built on Supabase's Wasm-based Wrappers framework, lets Postgres read Cal.com event types and bookings and create bookings with a plain INSERT, so a signup and its calendar booking can happen in one transaction. Setup has three steps: enable the wrappers extension, create a wasm_wrapper foreign server pointing at the Cal.com FDW package with an API key, and define foreign tables whose single jsonb attrs column holds the API objects. Data is extracted with JSON operators and json_array_elements. Inserts require the rowid_column option on the bookings table.
- WebAssembly functions for your SQLite-compatible database
Turso mediumAdeptlibSQL, Turso's open-contribution fork of SQLite, adds user-defined functions written in WebAssembly and registered directly from SQL with a CREATE FUNCTION ... LANGUAGE wasm statement, instead of only through SQLite's C API. WebAssembly was chosen for its sandboxing, portability, performance and wide use as a compile target from languages such as Rust and Zig. A walkthrough compiles Rust encrypt/decrypt functions with the libsql_bindgen crate or its playground and loads them as binary blobs in the libSQL shell. Functions cannot touch system resources such as time, randomness or the network, and their signatures must map to INTEGER, REAL, TEXT and BLOB types.