Skip to content

Commit 4ddf6ac

Browse files
committed
not modify RawINdeXDefV10
1 parent 2f9abc9 commit 4ddf6ac

9 files changed

Lines changed: 17 additions & 10 deletions

File tree

crates/bindings-macro/src/table.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,8 +453,9 @@ impl ValidatedIndex<'_> {
453453
let index_name = &self.index_name;
454454
// Note: we do not pass the index_name through here.
455455
// We trust the schema validation logic to reconstruct the name we've stored in `self.name`.
456+
//TODO(shub): pass generated index name instead of accessor name as source_name
456457
quote!(spacetimedb::table::IndexDesc {
457-
accessor_name: #accessor_name,
458+
source_name: #accessor_name,
458459
index_name: #index_name,
459460
algo: #algo,
460461
})

crates/bindings-typescript/src/lib/autogen/raw_index_def_v_10_type.ts

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-typescript/src/lib/schema.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,8 +100,7 @@ function tableToSchema<T extends UntypedTableSchema>(
100100
? [idx.algorithm.value]
101101
: idx.algorithm.value;
102102
return {
103-
// use accessor name?
104-
name: idx.sourceName!,
103+
name: idx.accessorName!,
105104
unique: tableDef.constraints.some(c =>
106105
c.data.value.columns.every(col => columnIds.includes(col))
107106
),

crates/bindings-typescript/src/lib/table.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -350,6 +350,7 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
350350
}
351351
indexes.push({
352352
sourceName: undefined, // Unnamed indexes will be assigned a globally unique name
353+
accessorName: name,
353354
algorithm,
354355
});
355356
}
@@ -419,6 +420,7 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
419420
// the name and accessor name of an index across all SDKs.
420421
indexes.push({
421422
sourceName: undefined,
423+
accessorName: indexOpts.name,
422424
algorithm,
423425
});
424426
}

crates/bindings-typescript/src/server/runtime.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -794,11 +794,10 @@ function makeTableView(
794794
} as RangedIndex<any, any>;
795795
}
796796

797-
//TODO: use accessor name
798-
if (Object.hasOwn(tableView, indexDef.sourceName!)) {
799-
freeze(Object.assign(tableView[indexDef.sourceName!], index));
797+
if (Object.hasOwn(tableView, indexDef.accessorName!)) {
798+
freeze(Object.assign(tableView[indexDef.accessorName!], index));
800799
} else {
801-
tableView[indexDef.sourceName!] = freeze(index) as any;
800+
tableView[indexDef.accessorName!] = freeze(index) as any;
802801
}
803802
}
804803

crates/bindings/src/rt.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -746,7 +746,7 @@ pub fn register_table<T: Table>() {
746746
table = table.with_unique_constraint(col);
747747
}
748748
for index in T::INDEXES {
749-
table = table.with_index(index.algo.into(), index.accessor_name);
749+
table = table.with_index(index.algo.into(), index.source_name);
750750
}
751751
if let Some(primary_key) = T::PRIMARY_KEY {
752752
table = table.with_primary_key(primary_key);

crates/bindings/src/table.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub trait TableInternal: Sized {
138138
/// Describe a named index with an index type over a set of columns identified by their IDs.
139139
#[derive(Clone, Copy)]
140140
pub struct IndexDesc<'a> {
141-
pub accessor_name: &'a str,
141+
pub source_name: &'a str,
142142
pub index_name: &'a str,
143143
pub algo: IndexAlgo<'a>,
144144
}

crates/lib/src/db/raw_def/v10.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,9 @@ pub struct RawIndexDefV10 {
367367
/// Even though there is ABSOLUTELY NO REASON TO.
368368
pub source_name: Option<RawIdentifier>,
369369

370+
// not to be used in v10
371+
pub accessor_name: Option<RawIdentifier>,
372+
370373
/// The algorithm parameters for the index.
371374
pub algorithm: RawIndexAlgorithm,
372375
}
@@ -1146,6 +1149,7 @@ impl RawTableDefBuilderV10<'_> {
11461149
pub fn with_index(mut self, algorithm: RawIndexAlgorithm, source_name: impl Into<RawIdentifier>) -> Self {
11471150
self.table.indexes.push(RawIndexDefV10 {
11481151
source_name: Some(source_name.into()),
1152+
accessor_name: None,
11491153
algorithm,
11501154
});
11511155
self
@@ -1155,6 +1159,7 @@ impl RawTableDefBuilderV10<'_> {
11551159
pub fn with_index_no_accessor_name(mut self, algorithm: RawIndexAlgorithm) -> Self {
11561160
self.table.indexes.push(RawIndexDefV10 {
11571161
source_name: None,
1162+
accessor_name: None,
11581163
algorithm,
11591164
});
11601165
self

crates/schema/src/def.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -855,7 +855,7 @@ impl From<IndexDef> for RawIndexDefV10 {
855855
fn from(val: IndexDef) -> Self {
856856
RawIndexDefV10 {
857857
source_name: Some(val.name),
858-
// accessor_name: val.accessor_name.map(Into::into),
858+
accessor_name: None,
859859
algorithm: val.algorithm.into(),
860860
}
861861
}

0 commit comments

Comments
 (0)