liveBook · Manning

Libsql_bindgen

As explained in Server-Side WebAssembly

libsql_bindgen is a Rust crate that generates bindings between Rust functions and libSQL user-defined-function interfaces.

libsql_bindgen connects Rust functions to libSQL user-defined-function interfaces, simplifying custom Wasm functions that execute inside the database’s sandboxed environment. section 5.3.1

A typical Rust UDF project uses libsql_bindgen to:

  • Create a Cargo library that produces a cdylib Wasm module. section 5.3.1
  • Annotate exported Rust functions with the libsql_bindgen macro. section 5.3.1
  • Limit parameters and return values to types compatible with Wasm and libSQL. section 5.3.1

Encryption and decryption UDFs

A Rust library can expose encrypt(data, key) and decrypt(data, key) functions with the #[libsql_bindgen::libsql_bindgen] attribute. These functions keep encryption logic inside the database, reducing the need to transfer unencrypted data elsewhere. section 5.3.1

How Server-Side WebAssembly covers it

How deep it goes
Explains macro-based binding generation, project setup, and type restrictions without detailing the crate’s internal implementation.
Examples
Demonstrates encrypt and decrypt functions in a Cargo library configured to produce a cdylib.
What it assumes
Starts with a direct Cargo library workflow and distinguishes Wasm modules from the newer, still-nascent component SQL embedding approach.
What you can do after
Build it from scratch by annotating Rust functions and packaging them as libSQL-compatible Wasm UDFs.
How it connects
Connects Rust, WebAssembly, libSQL, user-defined functions, sandboxing, and database-resident encryption.

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.