Commit Graph

84 Commits

Author SHA1 Message Date
Mazdak Farrokhzad 8544e6cf02 Add Hash indices (#3976)
# Description of Changes

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

Adds hash indices and exposes them through `#[index(hash)]` for Rust
modules,
with support for typescript and C# to come in follow ups.
On the client/sdk side, for now, any index is backed via a BTree/native
index as it is the most general.

A hash index may only be queried through point scan and never ranged
scans.
Attempting a ranged scan results in an error, with the mechanism
implemented in the previous PR
(https://github.com/clockworklabs/SpacetimeDB/pull/3974).



# API and ABI breaking changes

None

# Expected complexity level and risk

2?

# Testing

A test for ensuring that hash indices cannot be used for range scans is
added.
Tests exercising hash indices will come in the next PR.
2026-01-14 09:44:20 +00:00
Mazdak Farrokhzad 492e591845 Add WASM point scan ABIs & use them in Rust bindings (#3863)
# Description of Changes

Provides new WASM ABIs:

- `datastore_index_scan_point_bsatn`
- `datastore_delete_by_index_scan_point_bsatn`

These are then used where applicable to speed up `.find(_)` and friends.

Point scans are also used more internally where applicable.

What remains after this is use in C# module bindings and to expose this
in TS as well.

The PR makes TPS go from roughly 36k to 38k TPS on my machine and also
makes a difference in flamegraphs where the time spent in some index
scans are substantially decreased.

# API and ABI breaking changes

None

# Expected complexity level and risk

3? This touches the datastore an how we expose it to modules.

# Testing

Some existing tests now exercise the new ABIs by changing what
`.find(_)` and friends do.

---------

Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-12-12 22:07:54 +00:00
Shubham Mishra c99a6131c8 [Rust] Query builder Integration. (#3823)
# Description of Changes
Patch contain few different things, required to run query builder end to
end.
Git history seems messed up but it can be reviewed commitwise from -
69c1907b3e.

1. Decouples generic type `T` from table name, as type represents the
`struct` and not table, and there couple be multiple tables implemented
from same struct.
2. modify table macro implementaiton to generate code supporting
`traits` and types required for query builder,
3. Disable aliasing in sql queries for now, as it was causing
semantically wrong query when we were doing joins on `FromWhere` (as
original `Expr` were referencing to original table names).
4. smoketests.


# API and ABI breaking changes
Add `Query<T>` type as Views return type.


# Expected complexity level and risk
2, changes are simple but not splitted up well.

# Testing
1. Added smoketest.

TODO:
ui test.

---------

Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2025-12-04 17:45:29 +00:00
joshua-spacetime 6401818fe5 Disable parameterized views in rust (#3629)
# Description of Changes

Disables parameterized views in rust until we can pass arguments from
sql. Note parameters are already disabled in C# and typescript.

# API and ABI breaking changes

None

# Expected complexity level and risk

1

# Testing

Needed to update some tests. Will revert these changes once we re-enable
parameters.
2025-11-10 22:51:29 +00:00
joshua-spacetime 8f11ac81e3 Make name a required parameter of view macro (#3480)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

Makes `name` a required parameter of the `#[view]` macro. This is to be
consistent with the `#[table]` macro since views should expose the same
interface as tables.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

None

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

1

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] Added new compile tests
- [x] Updated existing compile tests
2025-10-24 20:43:33 +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
joshua-spacetime 0d325b2dcc Add macro bindings for views (#3429)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

Adds the `#[view]` procedural macro and module describers for views.
```rust
#[view(public)]
fn player(ctx: &ViewContext) -> Vec<Player> {
    ctx.db.player().identity().find(ctx.sender).into_iter().collect()
}

#[view(public)]
fn player(ctx: &AnonymousViewContext, level: u32) -> Vec<Player> {
    ctx.db.player().level().filter(level).collect()
}
```

Note, this deviates from the proposal in that views may only return
`Vec<T>` or `Option<T>`. They can't return an arbitrary `SpacetimeType`.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

This technically isn't a breaking change, but it's worth mentioning that
this patch refactors `ReducerInfo` so that we can use it for views as
well.

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

2

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] Negative compile tests
- [x] Negative publish (module validation) tests
- [x] Test system tables are updated accurately
2025-10-22 20:23:48 +00:00
joshua-spacetime 9f59118e24 Generate read-only table handles for #[table] (#3364)
# Description of Changes

<!-- Please describe your change, mention any related tickets, and so on
here. -->

The `#[table]` macro now generates read-only table and index handles.

# API and ABI breaking changes

<!-- If this is an API or ABI breaking change, please apply the
corresponding GitHub label. -->

None

# Expected complexity level and risk

<!--
How complicated do you think these changes are? Grade on a scale from 1
to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex
change.

This complexity rating applies not only to the complexity apparent in
the diff,
but also to its interactions with existing and future code.

If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning
ways. -->

1

# Testing

<!-- Describe any testing you've done, and any testing you'd like your
reviewers to do,
so that you're confident that all the changes work as expected! -->

- [x] positive and negative test cases using
`ReducerContext::as_read_only()`
2025-10-07 19:26:42 +00:00
Shubham Mishra 54b07d0b87 cli: pre-publish endpoint call. (#3278)
# Description of Changes
PR contains:

* CLI changes for the `pre_publish` endpoint when publishing a module.
* The regular `--yes` flag will not bypasses the *break clients* warning
prompt — an extra confirmation is now required. For CI, a hidden flag
`--break-clients` is added.
* Added smoketest.
* Some trivial naming changes in `client-api-*` crates for consistency
reasons.
* `pre_publish` route to accept similar Body size limit as `publish`
route.



# API and ABI breaking changes
an additive API change, does not break anything.

# Expected complexity level and risk
2

# Testing
- Existing smoketests passing for backward compatibility.
- New smoketest for add columns

---------

Signed-off-by: Shubham Mishra <shivam828787@gmail.com>
Co-authored-by: Phoebe Goldman <phoebe@clockworklabs.io>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
2025-10-01 18:26:03 +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
Zeke Foppa f6f0909ea4 Update all licenses (#3002)
# Description of Changes

We recently merged several repos together. This PR clarifies the license
terms for several subdirectories, as well as the relationship between
the licenses.

The licenses in our subdirectories have become symbolic links to
licenses in our toplevel `licenses` directory. For any particular
subdirectory's license file in the diff, you can click `... -> View
file` and then click on the text that says "Symbolic Link" on that page.
This will take you to the license file that it links to.

I have also updated the `tools/upgrade-version` script to update the
change date in the new `licenses/BSL.txt` file.

# API and ABI breaking changes

None.

# Expected complexity level and risk

1

# Testing

None. Only changes to license files.

---------

Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
2025-08-12 18:20:58 +00:00
Mazdak Farrokhzad 6c97ba4d6a V8: Use clearer lifetime names (#3009)
# Description of Changes

As requested by @gefjon 

Most of this is:
- `'a` -> `'this`
- `'s` -> `'scope`

# API and ABI breaking changes

None

# Expected complexity level and risk

0

# Testing

No semantic changes.
2025-08-11 13:50:27 +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
Mazdak Farrokhzad 4dcf5f89ea SATS: make field_names/variant_names return iterator + add FieldNameVisitor::visit_seq (#2927) 2025-07-08 19:55:23 +00:00
Phoebe Goldman 57fa739c6d Add docs for FilterableValue to rust bindings crate (#2547)
Co-authored-by: Mazdak Farrokhzad <twingoow@gmail.com>
2025-04-15 01:56:35 +00:00
Mazdak Farrokhzad c39f7fa64c Plain enums as index keys with specialized indices (#2506) 2025-04-09 18:52:15 +00:00
james gilles 8a317041d4 Update Rust module documentation (#2050)
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2025-02-21 03:48:46 +00:00
Mazdak Farrokhzad 0b2364b3a4 Add fast ser/de paths for structs of prims with repr(C) (#2251) 2025-02-11 22:07:14 +00:00
Mazdak Farrokhzad b50b6841f1 Add direct indices to datastore (#2221) 2025-02-07 01:06:38 +00:00
Mazdak Farrokhzad 1a3f3af255 add direct indices, except for in datastore & C# (#2205) 2025-02-06 00:40:46 +00:00
Noa 293aebaef9 Bump to Rust 1.84 (#2001) 2025-01-28 23:11:29 +00:00
Noa 179993c4ef Fix autocomplete issues in bindings crate (#2157) 2025-01-23 18:31:40 +00:00
Noa cf6ac18eaf Lookup lifecycle reducers by lifecycle flag, not by name (#2132) 2025-01-17 23:21:52 +00:00
Phoebe Goldman dc0bdce324 Rework RLS macro for amended syntax (#2105)
Signed-off-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2025-01-14 21:21:35 +00:00
Phoebe Goldman 44d7b76d29 Fix defining multiple tables on the same struct in Rust modules (#2103) 2025-01-10 01:58:20 +00:00
Noa 4015237f6a Tweak scheduled_at macro syntax (#2054) 2025-01-02 18:26:44 +00:00
Noa 94c66c97da Don't autogen schedule fields (#1894)
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
2024-11-22 18:39:39 +00:00
james gilles c657b4f088 Rip useless names out of RawDef (#1918) 2024-11-20 21:02:00 +00:00
Noa 97bff92efb Optimize integrate_generated_columns (#1895) 2024-11-12 16:36:50 +00:00
Noa 2d8224a6fd Reorganize macro crate (#1406) 2024-10-23 20:30:14 +00:00
Noa 209d12ce4e Have the scheduled_id/at columns be specified in the schema, not by the column name (#1861) 2024-10-18 22:51:36 +00:00
Mario Montoya 637d6d77b2 RLS: Adding a new filter! macro (#1849)
Signed-off-by: Mario Montoya <mamcx@elmalabarista.com>
Co-authored-by: joshua-spacetime <josh@clockworklabs.io>
2024-10-17 18:31:22 +00:00
Noa a4d097c92c Improve bindings diagnostics and add ui tests (#1216) 2024-10-16 18:18:52 +00:00
Noa c73625cdba Replace iter_by_col_eq in UniqueColumn impl (#1771) 2024-09-30 22:22:15 +00:00
Noa 53758420ec Rust module API rework (#1660) 2024-09-27 20:09:36 +00:00
Noa f6bc6dcfe5 Switch Rust codegen to use new ModuleDef (#1675) 2024-09-17 18:32:35 +00:00
Noa 8daab8e20f Impl macro rework (#1314) 2024-09-09 23:30:31 +00:00
Mazdak Farrokhzad da71d0f9b1 WASM ABI: insert -> datastore_insert_bsatn & impl new semantics (#1639) 2024-09-05 19:32:26 +00:00
Mazdak Farrokhzad 2b69583f76 WASM ABI: get_table_id -> table_id_from_name (#1634) 2024-08-27 22:33:47 +00:00
Mazdak Farrokhzad 4c086fef96 [WASM ABI 1.0] impl __call_reducer__ & __describe_module__ using bytes_sink_write (#1615) 2024-08-27 15:48:40 +00:00
Mazdak Farrokhzad 3be5c83d99 [WASM ABI 1.0] __call_reducer__ receives Identity & Address by value (#1607)
Signed-off-by: Mazdak Farrokhzad <twingoow@gmail.com>
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
Co-authored-by: Noa <coolreader18@gmail.com>
2024-08-19 22:20:57 +00:00
Mazdak Farrokhzad 1ca9b1a933 [WASM ABI 1.0] Change ColId from u32 to u16 (#1597) 2024-08-19 17:56:28 +00:00
Mazdak Farrokhzad 1e8e18d74b Add support for I256 and U256 (#1477) 2024-08-08 18:40:35 +00:00
Kim Altintop 4ffeff792b Remove support for the update reducer (#1557) 2024-07-31 06:26:06 +00:00
james gilles 45b2ceee9a Move schemas to schema crate, rename Def to RawDefV8 (#1498) 2024-07-24 17:38:30 +00:00
james gilles f81f2a7492 Move db module from spacetimedb_sats to spacetimedb_lib (#1479) 2024-07-17 20:59:44 +00:00
Shubham Mishra 276387d2b3 Timer Table Implementation (#1449)
Co-authored-by: Ingvar Stepanyan <me@rreverser.com>
2024-07-16 08:38:56 +00:00
Noa 10b151b999 Protobufectomy: server (#1077)
Co-authored-by: Phoebe Goldman <phoebe@goldman-tribe.org>
Co-authored-by: Jeremie Pelletier <jeremiep@gmail.com>
2024-07-12 18:02:18 +00:00
Snoppy 335c5b6e45 chore: fix typos (#1241)
* chore: fix typos

Signed-off-by: snoppy <michaleli@foxmail.com>

* Update lib.rs

Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>

---------

Signed-off-by: snoppy <michaleli@foxmail.com>
Signed-off-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
Co-authored-by: Tyler Cloutier <cloutiertyler@users.noreply.github.com>
2024-06-06 00:05:54 -04:00
Mazdak Farrokhzad 5e47b61f8a Tables only become public explicitly via #[spacetimedb(table(public))] (#1278)
* make user tables private by default and define privacy via attribute

* switch to spacetimedb(table(public)) syntax

* accept codegen snap changes

* sdk: use public in define_tables!

* bindings-macro: adjust some doc comments

* sdk-test-connect-disconnect: make Connected/Disconnected public tables

* Make Public Private again
2024-06-03 11:22:58 +00:00