8 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 0a3251708a Add ProcedureContext::with_tx (#3638)
# Description of Changes

Adds `ProcedureContext::{with_tx, try_with_tx}`.

Fixes https://github.com/clockworklabs/SpacetimeDB/issues/3515.

# API and ABI breaking changes

None

# Expected complexity level and risk

2

# Testing

An integration test `test_calling_with_tx` is added.
2025-11-19 20:33:02 +00:00
joshua-spacetime 1874b0e8a2 Generate client bindings for views (#3564)
# Description of Changes

Specifically generate client table handles for views.

# API and ABI breaking changes

None

# Expected complexity level and risk

1

# Testing

Added a `#[view]` to `module-test` and generated new client snapshots
2025-11-04 21:22:25 +00:00
Phoebe Goldman dcd8640543 Rust module bindings and macros for defining procedures (#3444)
# Description of Changes

This commit adds a macro attribute `#[procedure]` which applies to
functions, and various in-WASM machinery for defining, calling and
running procedures.

A simple example of a procedure, included in `modules/module-test`:

```rust
fn sleep_one_second(ctx: &mut ProcedureContext) {
    let prev_time = ctx.timestamp;
    let target = prev_time + Duration::from_secs(1);
    ctx.sleep_until(target);
    let new_time = ctx.timestamp;
    let actual_delta = new_time.duration_since(prev_time).unwrap();
    log::info!("Slept from {prev_time} to {new_time}, a total of {actual_delta:?}");
}
```

We intend eventually to make procedures be `async` functions (with the
trivial `now_or_never` executor from `future-util`), but I found that
making the types work for this was giving me a lot of trouble, and
decided to put it off in the interest of unblocking more parallelizable
work.

Host-side infrastructure for executing procedures is not included in
this commit. I have a prototype working, but cleaning it up for review
and merge will come a bit later.

One item of complexity in this PR is enabling scheduled tables to
specify either reducers or procedures, while still providing
compile-time diagnostics for ill-typed scheduled functions (as opposed
to publish-time). I had to rewrite the previous
`schedule_reducer_typecheck` into a more complex `schedule_typecheck`
with a trait `ExportFunctionForScheduledTable`, which takes a "tacit
trait parameter" encoding reducer-ness or procedure-ness, as described
in https://willcrichton.net/notes/defeating-coherence-rust/ .

The trait name `ExportFunctionForScheduledTable` is user-facing in the
sense that it will appear in compiler diagnostics in ill-typed modules.
As such, I am open to bikeshedding.

# API and ABI breaking changes

Adds a new user-facing API, which we intend to change before releasing.

# Expected complexity level and risk

2? Mostly pretty mechanical changes to macros and bindings.

# Testing

- [x] Added a procedure definition to `module-test`, saw that it
typechecks.
- [x] Executed same procedure definition using #3390 , the prototype
implementation this PR draws from.
2025-10-24 14:35:32 +00:00
Shubham Mishra cfb185a235 rust: default macro (#3177)
# Description of Changes
PR introduces support for column-level default values via a new
`#[default(...)]` attribute.

It also validates, `default` macro is not used along with `primary_key`,
`unique` or `auto_inc`.

# API and ABI breaking changes

NA

# Expected complexity level and risk
2

# Testing
Start using macro in `module-test`.

---------

Co-authored-by: James Gilles <jameshgilles@gmail.com>
2025-09-16 08:39:52 +00:00
Noa 742303ca49 Bump rust-toolchain to rust 1.88 (#2749)
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-07-15 17:39:41 +00:00
Rafael Guerreiro 0f70e63304 Simple implementation of insert_or_update and try_insert_or_update (#2678)
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2025-05-02 15:51:48 -04:00
Phoebe Goldman aedc601145 Rename Address to ConnectionId (#2220)
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: James Gilles <jameshgilles@gmail.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2025-02-10 00:40:16 +00:00
Tyler Cloutier e54a28584a Standardized module names and added module-test-cs based on module-test (#2232) 2025-02-09 05:58:19 +00:00