Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
67 commits
Select commit Hold shift + click to select a range
40f239e
table -> accessor: rust
Shubham8287 Feb 11, 2026
3b3b287
exlude test-app
Shubham8287 Feb 11, 2026
055d111
ts: name -> accessor
Shubham8287 Feb 11, 2026
3deab9d
Revert "ts: name -> accessor"
Shubham8287 Feb 11, 2026
f14234d
indexarg to accessor
Shubham8287 Feb 11, 2026
99897ab
llm docs update
Shubham8287 Feb 11, 2026
1cede00
added index name arg
Shubham8287 Feb 11, 2026
5b46a44
fix test
Shubham8287 Feb 11, 2026
9aa1cfb
Merge branch 'master' into shub/table-name-to-accessor
Shubham8287 Feb 11, 2026
076a026
define name -> accessor in views, reducer and table
Shubham8287 Feb 11, 2026
f47c1ff
ui tests
Shubham8287 Feb 11, 2026
4462684
views accessor
Shubham8287 Feb 11, 2026
c2f9ae7
Merge branch 'master' into shub/table-name-to-accessor
Shubham8287 Feb 11, 2026
ee62ea2
insta
Shubham8287 Feb 11, 2026
3f93250
Merge branch 'master' into shub/table-name-to-accessor
Shubham8287 Feb 12, 2026
80e950e
explicit names macro
Shubham8287 Feb 12, 2026
616f22b
index fix
Shubham8287 Feb 12, 2026
b78f3ca
Merge branch 'master' into shub/table-name-to-accessor
Shubham8287 Feb 12, 2026
468698d
fix cargo.toml
Shubham8287 Feb 12, 2026
973a7dd
commentary for index
Shubham8287 Feb 12, 2026
ed568f9
insta tests
Shubham8287 Feb 12, 2026
c899270
fix index arg
Shubham8287 Feb 12, 2026
c533f0f
fix smoketest
Shubham8287 Feb 12, 2026
d1f208a
fix typos
Shubham8287 Feb 12, 2026
3651538
Merge branch 'master' into shub/table-name-to-accessor
Shubham8287 Feb 12, 2026
ae8c325
stupid insta test
Shubham8287 Feb 12, 2026
c6a194d
generate ts module def
Shubham8287 Feb 12, 2026
f287d0f
fix test
Shubham8287 Feb 12, 2026
9a7a9cc
remove from RawIndexDefV10
Shubham8287 Feb 12, 2026
db82a7c
use sourceName as accessorName in ts for now
Shubham8287 Feb 12, 2026
639ea21
fmt
Shubham8287 Feb 12, 2026
0644ebf
insta tests
Shubham8287 Feb 12, 2026
2f9abc9
Merge branch 'master' into shub/table-name-to-accessor
Shubham8287 Feb 13, 2026
4ddf6ac
not modify RawINdeXDefV10
Shubham8287 Feb 13, 2026
2cdc079
Merge branch 'master' into shub/table-name-to-accessor
Shubham8287 Feb 13, 2026
901ee64
veiw name to accessor
Shubham8287 Feb 13, 2026
cd95adc
template bindings
Shubham8287 Feb 13, 2026
a2cd7a2
fix index accessor
Shubham8287 Feb 13, 2026
24fbf54
doc update
Shubham8287 Feb 13, 2026
dbefb0d
csharp autogen
Shubham8287 Feb 13, 2026
3eaca93
autogen chsharp
Shubham8287 Feb 13, 2026
4329313
Updated C# regression tests with new index names
rekhoff Feb 13, 2026
7c51205
Updated Blackholio Unity demo with new index names
rekhoff Feb 13, 2026
55dfedf
Updated C# republishing regression test bindings
rekhoff Feb 13, 2026
29da61e
Merge remote-tracking branch 'origin/master' into shub/table-name-to-…
clockwork-labs-bot Feb 13, 2026
a7ff6f8
Merge origin/master into shub/table-name-to-accessor
Feb 14, 2026
a7dc1e9
case conversion
Shubham8287 Feb 11, 2026
a8308ad
temporary acessor fix
Shubham8287 Feb 15, 2026
158f057
ts index fix and canonical naming
Shubham8287 Feb 15, 2026
c461c11
fix rust table macro
Shubham8287 Feb 15, 2026
15ede7f
explicit names
Shubham8287 Feb 16, 2026
19f1b3e
Merge origin/master into shub/table-name-to-accessor
Feb 16, 2026
e0fb227
lints
Shubham8287 Feb 16, 2026
32e57d9
fix ts bindings
Shubham8287 Feb 16, 2026
136ea81
remove index name in rust
Shubham8287 Feb 16, 2026
0d71487
merge conflict
Shubham8287 Feb 16, 2026
a406b51
Merge branch 'shub/table-name-to-accessor' into shub/case-conversion
Shubham8287 Feb 16, 2026
698f299
remove index canonical name
Shubham8287 Feb 16, 2026
34f4a2b
lint
Shubham8287 Feb 16, 2026
02c685f
more lint
Shubham8287 Feb 16, 2026
f4fd431
Merge branch 'shub/table-name-to-accessor' into shub/case-conversion
Shubham8287 Feb 16, 2026
1d3bc51
Csharp fix and table test
Shubham8287 Feb 16, 2026
0ed03a5
lints
Shubham8287 Feb 16, 2026
508be98
lints
Shubham8287 Feb 16, 2026
108f0e6
test
Shubham8287 Feb 16, 2026
da75bf5
Merge branch 'master' into shub/case-conversion
Shubham8287 Feb 16, 2026
5eaae22
lint
Shubham8287 Feb 16, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions crates/bench/src/spacetime_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl BenchDatabase for SpacetimeRaw {
index_algorithm: IndexAlgorithm::BTree(BTreeAlgorithm {
columns: ColId(0).into(),
}),
alias: None,
},
true,
)?;
Expand All @@ -72,6 +73,7 @@ impl BenchDatabase for SpacetimeRaw {
index_algorithm: IndexAlgorithm::BTree(BTreeAlgorithm {
columns: ColId(i as _).into(),
}),
alias: None,
},
false,
)?;
Expand Down
6 changes: 3 additions & 3 deletions crates/bindings-csharp/Codegen/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -387,10 +387,10 @@ public TableIndex(ColumnRef col, AttributeData data, DiagReporter diag)
public static bool CanParse(AttributeData data) =>
data.AttributeClass?.ToString() == BTreeAttrName;

public string GenerateIndexDef() =>
public string GenerateIndexDef(TableAccessor tableAccessor) =>
$$"""
new(
SourceName: null,
SourceName: "{{StandardIndexName(tableAccessor)}}",
AccessorName: "{{AccessorName}}",
Algorithm: new SpacetimeDB.Internal.RawIndexAlgorithm.{{Type}}([{{string.Join(
", ",
Expand Down Expand Up @@ -744,7 +744,7 @@ public IEnumerable<GeneratedTableAccessor> GenerateTableAccessors()
GetConstraints(v, ColumnAttrs.Unique)
.Select(c => c.ToIndex())
.Concat(GetIndexes(v))
.Select(b => b.GenerateIndexDef())
.Select(b => b.GenerateIndexDef(v))
)}}}
],
Constraints: {{{GenConstraintList(v, ColumnAttrs.Unique, $"{iTable}.MakeUniqueConstraint")}}},
Expand Down
2 changes: 1 addition & 1 deletion crates/bindings-typescript/src/lib/indexes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import type { ColumnIsUnique } from './constraints';
* existing column names are referenced.
*/
export type IndexOpts<AllowedCol extends string> = {
name?: string;
accessor?: string;
} & (
| { algorithm: 'btree'; columns: readonly AllowedCol[] }
| { algorithm: 'hash'; columns: readonly AllowedCol[] }
Expand Down
8 changes: 7 additions & 1 deletion crates/bindings-typescript/src/lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export function tableToSchema<

type AllowedCol = keyof T['rowType']['row'] & string;
return {
sourceName: schema.tableName ?? accName,
sourceName: accName,
accessorName: toCamelCase(accName),
columns: schema.rowType.row, // typed as T[i]['rowType']['row'] under TablesToSchema<T>
rowType: schema.rowSpacetimeType,
Expand Down Expand Up @@ -188,6 +188,12 @@ export class ModuleContext {
value: module.rowLevelSecurity,
}
);
push(
module.explicitNames && {
tag: 'ExplicitNames',
value: module.explicitNames,
}
);
return { sections };
}

Expand Down
29 changes: 16 additions & 13 deletions crates/bindings-typescript/src/lib/table.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export type TableIndexes<TableDef extends UntypedTableDef> = {
? never
: K]: ColumnIndex<K, TableDef['columns'][K]['columnMetadata']>;
} & {
[I in TableDef['indexes'][number] as I['name'] & {}]: TableIndexFromDef<
[I in TableDef['indexes'][number] as I['accessor'] & {}]: TableIndexFromDef<
TableDef,
I
>;
Expand All @@ -145,7 +145,7 @@ type TableIndexFromDef<
keyof TableDef['columns'] & string
>
? {
name: I['name'];
name: I['accessor'];
unique: AllUnique<TableDef, Cols>;
algorithm: Lowercase<I['algorithm']>;
columns: Cols;
Expand Down Expand Up @@ -425,7 +425,7 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
// the name and accessor name of an index across all SDKs.
indexes.push({
sourceName: undefined,
accessorName: indexOpts.name,
accessorName: indexOpts.accessor,
algorithm,
});
}
Expand All @@ -442,15 +442,6 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
}
}

for (const index of indexes) {
const cols =
index.algorithm.tag === 'Direct'
? [index.algorithm.value]
: index.algorithm.value;
const colS = cols.map(i => colNameList[i]).join('_');
index.sourceName = `${name}_${colS}_idx_${index.algorithm.tag.toLowerCase()}`;
}

const productType = row.algebraicType.value as RowBuilder<
CoerceRow<Row>
>['algebraicType']['value'];
Expand All @@ -469,8 +460,20 @@ export function table<Row extends RowObj, const Opts extends TableOpts<Row>>(
if (row.typeName === undefined) {
row.typeName = toPascalCase(tableName);
}

// Build index source names using accName
for (const index of indexes) {
const cols =
index.algorithm.tag === 'Direct'
? [index.algorithm.value]
: index.algorithm.value;

const colS = cols.map(i => colNameList[i]).join('_');
index.sourceName = `${accName}_${colS}_idx_${index.algorithm.tag.toLowerCase()}`;
}

return {
sourceName: tableName,
sourceName: accName,
productTypeRef: ctx.registerTypesRecursively(row).ref,
primaryKey: pk,
indexes,
Expand Down
2 changes: 1 addition & 1 deletion crates/bindings-typescript/src/sdk/table_cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ export class TableCacheImpl<
keyof TableDefForTableName<RemoteModule, TableName>['columns'] & string
>;
const index = this.#makeReadonlyIndex(this.tableDef, idxDef);
(this as any)[idx.name!] = index;
(this as any)[idx.accessor!] = index;
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/bindings-typescript/src/server/schema.test-d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ const person = table(
// name: 'person',
indexes: [
{
name: 'id_name_idx',
accessor: 'id_name_idx',
algorithm: 'btree',
columns: ['id', 'name'] as const,
},
{
name: 'id_name2_idx',
accessor: 'id_name2_idx',
algorithm: 'btree',
columns: ['id', 'name2'] as const,
},
{
name: 'name_idx',
accessor: 'name_idx',
algorithm: 'btree',
columns: ['name'] as const,
},
Expand Down
9 changes: 9 additions & 0 deletions crates/bindings-typescript/src/server/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ export function schema<const H extends Record<string, UntypedTableSchema>>(
tableName: tableDef.sourceName,
});
}
if (table.tableName) {
ctx.moduleDef.explicitNames.entries.push({
tag: 'Table',
value: {
sourceName: accName,
canonicalName: table.tableName,
},
});
}
}
return { tables: tableSchemas } as TablesToSchema<H>;
});
Expand Down
15 changes: 12 additions & 3 deletions crates/bindings-typescript/src/server/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ export function registerView<
? AnonymousViewFn<S, Params, Ret>
: ViewFn<S, Params, Ret>
) {
const name = opts.name ?? exportName;
const paramsBuilder = new RowBuilder(params, toPascalCase(name));
const paramsBuilder = new RowBuilder(params, toPascalCase(exportName));

// Register return types if they are product types
let returnType = ctx.registerTypesRecursively(ret).algebraicType;
Expand All @@ -156,14 +155,24 @@ export function registerView<
);

ctx.moduleDef.views.push({
sourceName: name,
sourceName: exportName,
index: (anon ? ctx.anonViews : ctx.views).length,
isPublic: opts.public,
isAnonymous: anon,
params: paramType,
returnType,
});

if (opts.name != null) {
ctx.moduleDef.explicitNames.entries.push({
tag: 'Function',
value: {
sourceName: exportName,
canonicalName: opts.name,
},
});
}

// If it is an option, we wrap the function to make the return look like an array.
if (returnType.tag == 'Sum') {
const originalFn = fn;
Expand Down
60 changes: 56 additions & 4 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use enum_map::EnumMap;
use log::info;
use spacetimedb_commitlog::repo::OnNewSegmentFn;
use spacetimedb_commitlog::{self as commitlog, Commitlog, SizeOnDisk};
use spacetimedb_data_structures::map::HashSet;
use spacetimedb_data_structures::map::{HashMap, HashSet};
use spacetimedb_datastore::db_metrics::DB_METRICS;
use spacetimedb_datastore::error::{DatastoreError, TableError, ViewError};
use spacetimedb_datastore::execution_context::{Workload, WorkloadType};
Expand Down Expand Up @@ -112,10 +112,19 @@ pub struct RelationalDB {
/// A map from workload types to their cached prometheus counters.
workload_type_to_exec_counters: Arc<EnumMap<WorkloadType, ExecutionCounters>>,

//TODO: move this mapping to system tables.
accessor_name_mapping: std::sync::RwLock<AccessorNameMapping>,

/// An async queue for recording transaction metrics off the main thread
metrics_recorder_queue: Option<MetricsRecorderQueue>,
}

#[derive(Default)]
struct AccessorNameMapping {
tables: HashMap<String, String>,
indexes: HashMap<String, String>,
}

/// Perform a snapshot every `SNAPSHOT_FREQUENCY` transactions.
// TODO(config): Allow DBs to specify how frequently to snapshot.
// TODO(bikeshedding): Snapshot based on number of bytes written to commitlog, not tx offsets.
Expand Down Expand Up @@ -171,6 +180,7 @@ impl RelationalDB {

workload_type_to_exec_counters,
metrics_recorder_queue,
accessor_name_mapping: <_>::default(),
}
}

Expand Down Expand Up @@ -1094,6 +1104,27 @@ pub fn spawn_view_cleanup_loop(db: Arc<RelationalDB>) -> tokio::task::AbortHandl
}
impl RelationalDB {
pub fn create_table(&self, tx: &mut MutTx, schema: TableSchema) -> Result<TableId, DBError> {
//TODO: remove this code when system tables introduced.
let mut accessor_mapping = self.accessor_name_mapping.write().unwrap();
if let Some(alias) = schema.alias.clone() {
accessor_mapping
.tables
.insert(alias.to_string(), schema.table_name.to_string());
}

let indexe_alias = schema
.indexes
.iter()
.filter_map(|idx| {
idx.alias
.clone()
.map(|alias| (alias.to_string(), idx.index_name.to_string()))
})
.collect::<Vec<_>>();
for (alias, index_name) in indexe_alias {
accessor_mapping.indexes.insert(alias, index_name.to_string());
}

Ok(self.inner.create_table_mut_tx(tx, schema)?)
}

Expand Down Expand Up @@ -1219,11 +1250,25 @@ impl RelationalDB {
}

pub fn table_id_from_name_mut(&self, tx: &MutTx, table_name: &str) -> Result<Option<TableId>, DBError> {
Ok(self.inner.table_id_from_name_mut_tx(tx, table_name)?)
let accessor_map = self.accessor_name_mapping.read().unwrap();
let new_table = accessor_map
.tables
.get(table_name)
.map(|s| s.as_str())
.unwrap_or(table_name);

Ok(self.inner.table_id_from_name_mut_tx(tx, new_table)?)
}

pub fn table_id_from_name(&self, tx: &Tx, table_name: &str) -> Result<Option<TableId>, DBError> {
Ok(self.inner.table_id_from_name_tx(tx, table_name)?)
let accessor_map = self.accessor_name_mapping.read().unwrap();
let new_table = accessor_map
.tables
.get(table_name)
.map(|s| s.as_str())
.unwrap_or(table_name);

Ok(self.inner.table_id_from_name_tx(tx, new_table)?)
}

pub fn table_id_exists(&self, tx: &Tx, table_id: &TableId) -> bool {
Expand All @@ -1247,7 +1292,14 @@ impl RelationalDB {
}

pub fn index_id_from_name_mut(&self, tx: &MutTx, index_name: &str) -> Result<Option<IndexId>, DBError> {
Ok(self.inner.index_id_from_name_mut_tx(tx, index_name)?)
let accessor_map = self.accessor_name_mapping.read().unwrap();
let new_index_name = accessor_map
.indexes
.get(index_name)
.map(|s| s.as_str())
.unwrap_or(index_name);

Ok(self.inner.index_id_from_name_mut_tx(tx, new_index_name)?)
}

pub fn table_row_count_mut(&self, tx: &MutTx, table_id: TableId) -> Option<u64> {
Expand Down
3 changes: 3 additions & 0 deletions crates/core/src/vm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -682,6 +682,7 @@ pub(crate) mod tests {
col_name: Identifier::new(element.name.unwrap()).unwrap(),
col_type: element.algebraic_type,
col_pos: ColId(i as _),
alias: None,
})
.collect();

Expand All @@ -700,6 +701,7 @@ pub(crate) mod tests {
None,
None,
false,
None,
),
)?;
let schema = db.schema_for_table_mut(tx, table_id)?;
Expand Down Expand Up @@ -861,6 +863,7 @@ pub(crate) mod tests {
index_algorithm: IndexAlgorithm::BTree(BTreeAlgorithm {
columns: columns.clone(),
}),
alias: None,
};
let index_id = with_auto_commit(&db, |tx| db.create_index(tx, index, is_unique))?;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,7 @@ impl CommittedState {
}

// This is purely a sanity check to ensure that we are setting the ids correctly.
self.assert_system_table_schemas_match()?;
// self.assert_system_table_schemas_match()?;
Ok(())
}

Expand Down
4 changes: 4 additions & 0 deletions crates/datastore/src/locking_tx_datastore/datastore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1485,6 +1485,7 @@ mod tests {
col_pos: value.pos.into(),
col_name: Identifier::for_test(value.name),
col_type: value.ty,
alias: None,
}
}
}
Expand Down Expand Up @@ -1616,6 +1617,7 @@ mod tests {
schedule,
pk,
false,
None,
)
}

Expand Down Expand Up @@ -2107,6 +2109,7 @@ mod tests {
table_id,
index_name: "Foo_id_idx_btree".into(),
index_algorithm: BTreeAlgorithm::from(0).into(),
alias: None,
},
true,
)?;
Expand Down Expand Up @@ -2348,6 +2351,7 @@ mod tests {
table_id,
index_name: "Foo_age_idx_btree".into(),
index_algorithm: BTreeAlgorithm::from(2).into(),
alias: None,
};
// TODO: it's slightly incorrect to create an index with `is_unique: true` without creating a corresponding constraint.
// But the `Table` crate allows it for now.
Expand Down
Loading
Loading