Skip to content

Commit 38a8b43

Browse files
konardclaude
andcommitted
fix(module): use accessor = links syntax for spacetimedb #[table] macro
The spacetimedb v2 #[table] attribute uses `accessor = name` not `name = name`. The `accessor` parameter specifies both: - the SQL table name (used in subscriptions: SELECT * FROM links) - the Rust method name (used in reducers: ctx.db.links()) Also fix delete/find calls to pass references (&id) not values (id) as required by the SpacetimeDB API for primary key lookup methods. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent bbe83de commit 38a8b43

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

  • rust/spacetime-module/src

rust/spacetime-module/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use spacetimedb::{reducer, table, ReducerContext, Table};
22

3-
#[table(name = links, public)]
3+
#[table(accessor = links, public)]
44
pub struct Link {
55
#[primary_key]
66
#[auto_inc]
@@ -27,7 +27,7 @@ pub fn create_link(ctx: &ReducerContext, source: u64, target: u64) {
2727

2828
#[reducer]
2929
pub fn update_link(ctx: &ReducerContext, id: u64, source: u64, target: u64) {
30-
if let Some(link) = ctx.db.links().id().find(id) {
30+
if let Some(link) = ctx.db.links().id().find(&id) {
3131
ctx.db.links().id().update(Link {
3232
id: link.id,
3333
source,
@@ -38,13 +38,13 @@ pub fn update_link(ctx: &ReducerContext, id: u64, source: u64, target: u64) {
3838

3939
#[reducer]
4040
pub fn delete_link(ctx: &ReducerContext, id: u64) {
41-
ctx.db.links().id().delete(id);
41+
ctx.db.links().id().delete(&id);
4242
}
4343

4444
#[reducer]
4545
pub fn delete_all_links(ctx: &ReducerContext) {
4646
let ids: Vec<u64> = ctx.db.links().iter().map(|l| l.id).collect();
4747
for id in ids {
48-
ctx.db.links().id().delete(id);
48+
ctx.db.links().id().delete(&id);
4949
}
5050
}

0 commit comments

Comments
 (0)