tursodatabase / tursodatabase/libsql

Allow implementing CHECK expressions in Wasm

Open
#19 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
17.2k
Forks
531
Avg merge
1h 12m
Merged PRs (30d)
1

Description

Described by @xfbs in https://github.com/libsql/libsql/discussions/8#discussioncomment-3798887

The idea is to allow people to code more complex check expressions in any language compilable to WebAssembly and have an interface which makes it easy to register such checks. The code sample proposed in discussion above was:

#[libsql::constraint]
fn check_is_ipv4(data: &[u8]) -> Result<(), ConstraintError> {
    Ipv4Addr::try_from(&data)?;
    Ok(())
}

and it's a great example of why this can be useful - users can rely on standard library implementations of things like IP validation and get a working CHECK expression.

This is an umbrella issue, because it has a few prerequisites, some shared with #1, in arbitrary order:

  • Define a Wasm<->libSQL ABI, which specifies how libSQL types should be expressed in WebAssembly functions:
    https://github.com/libsql/libsql/issues/16
  • Create helper libraries for handling this type translation in a few popular languages - with Rust leading the way:
    https://github.com/libsql/libsql/issues/15
  • Add a user-defined helper function (registered with sqlite3_create_function) which runs a WebAssembly function - e.g. it could take the WebAssembly module body as a blob in the first parameter, then the function name, and then forward the rest of the parameters to the WebAssembly model as is:
    https://github.com/libsql/libsql/issues/17
  • Add syntactic sugar for calling a Wasm function without using the runner above - e.g. creating a system table for storing compiled functions indexed by their names, adding a CREATE FUNCTION SQL command for compiling and registering it, and modifying the path for looking up user-defined functions to take a peek into ones created with CREATE FUNCTION:
    https://github.com/libsql/libsql/issues/18

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reading the linked discussion and prerequisite issues #16, #15, #17, and #18 to understand the proposed ABI, type-translation libraries, Wasm helper function, and CREATE FUNCTION syntax. The umbrella issue is done only when these prerequisites support implementing CHECK expressions through registered Wasm functions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, sql, wasm
Domain
databases
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.