tursodatabase / tursodatabase/libsql
Allow implementing CHECK expressions in Wasm
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 FUNCTIONSQL command for compiling and registering it, and modifying the path for looking up user-defined functions to take a peek into ones created withCREATE FUNCTION:
https://github.com/libsql/libsql/issues/18
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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