mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-11 18:36:15 -04:00
e4098f98d9
## Description of Changes
This PR primarily affects the `bindings-macro` and `schema` crates to
review:
### Core changes
1. Replaces the `name` macro with `accessor` for **Tables, Views,
Procedures, and Reducers** in Rust modules.
2. Extends `RawModuleDefV10` with a new section for:
* case conversion policies
* explicit names
New sections are not validated in this PR so not functional.
3. Updates index behavior:
* Index names are now always **system-generated** for clients. Which
will be fixed in follow-up PR when we start validating RawModuleDef with
explicit names.
* The `accessor` name for an index is used only inside the module.
## Breaking changes (API/ABI)
1. **Rust modules**
* The `name` macro must be replaced with `accessor`.
2. **Client bindings (all languages)**
* Index names are now system-generated instead of using explicitly
provided names.
**Complexity:** 3
A follow-up PR will reintroduce explicit names with support for case
conversion.
---------
Co-authored-by: rekhoff <r.ekhoff@clockworklabs.io>
Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
Co-authored-by: clockwork-labs-bot <bot@clockworklabs.com>
54 lines
1.6 KiB
Python
54 lines
1.6 KiB
Python
from .. import Smoketest
|
|
|
|
class ModuleNestedOp(Smoketest):
|
|
MODULE_CODE = """
|
|
use spacetimedb::{log, ReducerContext, Table};
|
|
|
|
#[spacetimedb::table(accessor = account)]
|
|
pub struct Account {
|
|
name: String,
|
|
#[unique]
|
|
id: i32,
|
|
}
|
|
|
|
#[spacetimedb::table(accessor = friends)]
|
|
pub struct Friends {
|
|
friend_1: i32,
|
|
friend_2: i32,
|
|
}
|
|
|
|
#[spacetimedb::reducer]
|
|
pub fn create_account(ctx: &ReducerContext, account_id: i32, name: String) {
|
|
ctx.db.account().insert(Account { id: account_id, name } );
|
|
}
|
|
|
|
#[spacetimedb::reducer]
|
|
pub fn add_friend(ctx: &ReducerContext, my_id: i32, their_id: i32) {
|
|
// Make sure our friend exists
|
|
for account in ctx.db.account().iter() {
|
|
if account.id == their_id {
|
|
ctx.db.friends().insert(Friends { friend_1: my_id, friend_2: their_id });
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
|
|
#[spacetimedb::reducer]
|
|
pub fn say_friends(ctx: &ReducerContext) {
|
|
for friendship in ctx.db.friends().iter() {
|
|
let friend1 = ctx.db.account().id().find(&friendship.friend_1).unwrap();
|
|
let friend2 = ctx.db.account().id().find(&friendship.friend_2).unwrap();
|
|
log::info!("{} is friends with {}", friend1.name, friend2.name);
|
|
}
|
|
}
|
|
"""
|
|
|
|
def test_module_nested_op(self):
|
|
"""This tests uploading a basic module and calling some functions and checking logs afterwards."""
|
|
|
|
self.call("create_account", 1, "House")
|
|
self.call("create_account", 2, "Wilson")
|
|
self.call("add_friend", 1, 2)
|
|
self.call("say_friends")
|
|
self.assertIn("House is friends with Wilson", self.logs(2))
|