liveBook · Manning

WebAssembly Text Format

As explained in Server-Side WebAssembly

WAT is the human-readable textual representation of WebAssembly modules and their instructions.

WebAssembly Text Format (WAT) is the human-readable representation of WebAssembly modules. It makes Wasm instructions easier to inspect, edit, debug, and define directly in libSQL. section 5.3.3 section 5.5

A WAT module can express:

  • Functions with typed parameters and results, such as a function accepting two i64 values and returning an i64. section 5.3.3
  • Instructions such as local.get and i64.add, which retrieve parameters and add their values. section 5.3.3
  • Exports that expose functions and memory to the embedding environment; memory may be required even when unused by a simple function. section 5.3.3

Define and test a libSQL function

Create a Wasm function named my_add with two i64 parameters, return their sum, and export both the function and memory. Register it with CREATE FUNCTION my_add LANGUAGE wasm, then run SELECT my_add(1, 41); to obtain 42. section 5.3.3

docker run --rm -v ./data:/data -it ghcr.io/danbugs/
➥serverside-wasm-book-code/libsql-wasmudf:latest

Use the libSQL environment to load SQL definitions and test Wasm-backed functions interactively. section 5.3.3

How Server-Side WebAssembly covers it

How deep it goes
Explains readable module syntax, typed functions, instructions, exports, and direct testing, stopping short of broader optimization details.
Examples
Uses a my_add function that adds two 64-bit integers and returns 42 when queried with 1 and 41.
What you can do after
Build it from scratch by writing, registering, and testing a simple WAT-based Wasm UDF in libSQL.
How it connects
Connects WebAssembly modules, user-defined functions, libSQL, SQL queries, and sandboxed database processing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Server-Side WebAssembly. The section links point to the parts of the book it draws on.