Skip to content

Latest commit

 

History

History
31 lines (21 loc) · 1.22 KB

File metadata and controls

31 lines (21 loc) · 1.22 KB

Postgres example

In this example, we showcase how to make async (non blocking) connections to Postgres databases from WasmEdge Rust apps. It utilizes the tokio-postgres_wasi crate, which is derived from tokio-postgres.

Linux CLI usage

Prerequisites:

  • Install the Rust compiler and Cargo tools
  • Install the WasmEdge Runtime
  • Install and start the PostgreSQL server
    • Create a username wasmedge with password 'rocks`
    • Create a database testdb for user wasmedge

The following commands build and run the example.

cargo build --target wasm32-wasip1 --release
wasmedge --env "DATABASE_URL=postgres://wasmedge:rocks@localhost/testdb" target/wasm32-wasip1/release/crud.wasm

Docker usage

The following command builds and starts two containers. All you need is Docker Desktop. There is no need to install Rust or Redis or even WasmEdge.

  • One is a Wasm container for the PostgreSQL client app. The entire container image is only 0.9MB -- far smaller than any Linux container.
  • The second is a Linux container for the PostgreSQL server.
docker compose up