wasm_node

command
v0.67.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 5, 2026 License: AGPL-3.0 Imports: 9 Imported by: 0

README

tinySQL WASM Node.js (wasm_node)

Part of tinySQL. See the command index for browser and server variants.

Compiles tinySQL to WebAssembly for Node.js. wasm_runner.js bootstraps the module and exposes the engine to Node scripts and the command line.

Build

cd cmd/wasm_node

# Build only (produces tinySQL.wasm + wasm_exec.js)
./build.sh --build-only

# Build and run the built-in demo
./build.sh --run
./build.sh --run --query "SELECT 42"

# Run existing assets without rebuilding
./build.sh --skip-build --run

Manual equivalent:

cd cmd/wasm_node
GOOS=js GOARCH=wasm go build -tags=tinysql_minimal -trimpath -ldflags="-s -w" -o tinySQL.wasm .
cp "$(go env GOROOT)/lib/wasm/wasm_exec.js" ./

Build scripts default to WASM_PROFILE=minimal, excluding SQL HTTP(), HTML_TEMPLATE(), YAML imports and the HTTP problem writer. HTML_ESCAPE() and core SQL remain available. Set WASM_PROFILE=full to restore optional features with the Go compiler. TinyGo retains its target-specific restrictions. Set WASM_OPTIMIZE=false to skip Binaryen optimisation. Always distribute wasm_exec.js from the same build alongside the WASM binary.

Run

node wasm_runner.js                                             # status (default)
node wasm_runner.js query "SELECT 1 AS n, 'hello' AS greeting"
node wasm_runner.js exec "CREATE TABLE t (id INT)"

The runner starts the Go runtime asynchronously and waits until the global tinySQL API is ready, then opens an in-memory database, runs the command, and closes it again.

Embed in your own Node script

Use wasm_runner.js as the bootstrap reference: instantiate tinySQL.wasm, call go.run(instance) without awaiting its never-ending runtime promise, and wait for global.tinySQL. The runner is a CLI helper, not a CommonJS module.

Notes

  • Requires Node.js 18+ (WebAssembly support).
  • The database is in-memory and does not persist between Node process runs.
  • Builds use stripped symbols and optionally wasm-opt when Binaryen is installed.
  • For the browser variant see ../wasm_browser/.

The Node build shares the browser build's adaptive result-transfer bridge. Large primitive results use bounded JSON blocks internally; callers still receive native JavaScript objects. Blocks contain at most 1,024 rows with a conservative 256 KiB encoded-row budget. Special values and oversized rows use direct conversion without disabling batching for neighboring rows.

Queries remain synchronous and fully materialized. Use SQL projections and LIMIT to control result memory. See WASM result performance for measurements, benchmark commands and compatibility guarantees.

Documentation

Rendered for js/wasm
The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL