Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
10 changes: 10 additions & 0 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ derive_more = "0.99"
dialoguer = { version = "0.11", default-features = false }
dirs = "5.0.1"
duct = "0.13.5"
ecow = "0.2.6"
either = "1.9"
email_address = "0.2.4"
enum-as-inner = "0.6"
Expand Down
3 changes: 2 additions & 1 deletion crates/bench/benches/special.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use spacetimedb_bench::{
use spacetimedb_lib::sats::{self, bsatn};
use spacetimedb_lib::{bsatn::ToBsatn as _, ProductValue};
use spacetimedb_schema::schema::TableSchema;
use spacetimedb_schema::table_name::TableName;
use spacetimedb_table::page_pool::PagePool;
use spacetimedb_testing::modules::{Csharp, ModuleLanguage, Rust};
use std::sync::Arc;
Expand Down Expand Up @@ -136,7 +137,7 @@ fn serialize_benchmarks<
});

let mut table_schema = TableSchema::from_product_type(T::product_type());
table_schema.table_name = name.into();
table_schema.table_name = TableName::new_from_str(name);
let mut table = spacetimedb_table::table::Table::new(
Arc::new(table_schema),
spacetimedb_table::indexes::SquashedOffset::COMMITTED_STATE,
Expand Down
3 changes: 2 additions & 1 deletion crates/bench/benches/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ use spacetimedb_primitives::{col_list, TableId};
use spacetimedb_query::compile_subscription;
use spacetimedb_sats::{bsatn, product, AlgebraicType, AlgebraicValue, ProductValue};

use spacetimedb_schema::table_name::TableName;
#[cfg(not(target_env = "msvc"))]
use tikv_jemallocator::Jemalloc;

Expand Down Expand Up @@ -54,7 +55,7 @@ fn create_table_footprint(db: &RelationalDB) -> Result<TableId, DBError> {
fn insert_op(table_id: TableId, table_name: &str, row: ProductValue) -> DatabaseTableUpdate {
DatabaseTableUpdate {
table_id,
table_name: table_name.into(),
table_name: TableName::new_from_str(table_name),
inserts: [row].into(),
deletes: [].into(),
}
Expand Down
5 changes: 3 additions & 2 deletions crates/bench/src/schemas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use serde::Deserialize;
use spacetimedb_lib::de::Deserialize as SatsDeserializer;
use spacetimedb_lib::sats;
use spacetimedb_schema::table_name::TableName;
use std::fmt::Debug;
use std::hash::Hash;

Expand Down Expand Up @@ -159,11 +160,11 @@ impl IndexStrategy {
}
}

pub fn table_name<T: BenchTable>(style: IndexStrategy) -> String {
pub fn table_name<T: BenchTable>(style: IndexStrategy) -> TableName {
let prefix = style.name();
let name = T::name();

format!("{prefix}_{name}")
TableName::new_from_str(&format!("{prefix}_{name}"))
}

// ---------- data synthesis ----------
Expand Down
5 changes: 3 additions & 2 deletions crates/bench/src/spacetime_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use spacetimedb_lib::{
};
use spacetimedb_paths::RootDir;
use spacetimedb_primitives::ColId;
use spacetimedb_schema::table_name::TableName;
use spacetimedb_testing::modules::{start_runtime, LoggerRecord, ModuleHandle, ModuleLanguage};
use tokio::runtime::Runtime;

Expand Down Expand Up @@ -192,6 +193,6 @@ impl<L: ModuleLanguage> BenchDatabase for SpacetimeModule<L> {

#[derive(Debug, Clone)]
pub struct TableId {
pascal_case: String,
snake_case: String,
pascal_case: TableName,
snake_case: TableName,
}
2 changes: 1 addition & 1 deletion crates/bench/src/spacetime_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl BenchDatabase for SpacetimeRaw {
let name = table_name::<T>(index_strategy);
self.db.with_auto_commit(Workload::Internal, |tx| {
let mut table_schema = TableSchema::from_product_type(T::product_type());
table_schema.table_name = name.clone().into();
table_schema.table_name = name.clone();
let table_id = self.db.create_table(tx, table_schema)?;
self.db.rename_table(tx, table_id, &name)?;
match index_strategy {
Expand Down
3 changes: 2 additions & 1 deletion crates/bench/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use rusqlite::Connection;
use spacetimedb_data_structures::map::HashMap;
use spacetimedb_lib::sats::{AlgebraicType, AlgebraicValue, ProductType};
use spacetimedb_primitives::ColId;
use spacetimedb_schema::table_name::TableName;
use std::{
fmt::Write,
hint::black_box,
Expand Down Expand Up @@ -47,7 +48,7 @@ impl BenchDatabase for SQLite {
})
}

type TableId = String;
type TableId = TableName;

/// We derive the SQLite schema from the AlgebraicType of the table.
fn create_table<T: BenchTable>(
Expand Down
11 changes: 6 additions & 5 deletions crates/codegen/src/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use spacetimedb_lib::sats::layout::PrimitiveType;
use spacetimedb_lib::sats::AlgebraicTypeRef;
use spacetimedb_schema::def::{ModuleDef, ProcedureDef, ReducerDef, ScopedTypeName, TableDef, TypeDef};
use spacetimedb_schema::identifier::Identifier;
use spacetimedb_schema::reducer_name::ReducerName;
use spacetimedb_schema::schema::TableSchema;
use spacetimedb_schema::type_for_generate::{AlgebraicTypeDef, AlgebraicTypeUse};
use std::collections::BTreeSet;
Expand Down Expand Up @@ -1089,19 +1090,19 @@ fn table_access_trait_name(table_name: &Identifier) -> String {
table_name.deref().to_case(Case::Pascal) + "TableAccess"
}

fn function_args_type_name(function_name: &Identifier) -> String {
function_name.deref().to_case(Case::Pascal) + "Args"
fn function_args_type_name(function_name: &str) -> String {
function_name.to_case(Case::Pascal) + "Args"
}

fn reducer_variant_name(reducer_name: &Identifier) -> String {
fn reducer_variant_name(reducer_name: &ReducerName) -> String {
reducer_name.deref().to_case(Case::Pascal)
}

fn reducer_callback_id_name(reducer_name: &Identifier) -> String {
fn reducer_callback_id_name(reducer_name: &ReducerName) -> String {
reducer_name.deref().to_case(Case::Pascal) + "CallbackId"
}

fn reducer_module_name(reducer_name: &Identifier) -> String {
fn reducer_module_name(reducer_name: &ReducerName) -> String {
reducer_name.deref().to_case(Case::Snake) + "_reducer"
}

Expand Down
7 changes: 4 additions & 3 deletions crates/codegen/src/typescript.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use spacetimedb_lib::sats::AlgebraicTypeRef;
use spacetimedb_primitives::ColId;
use spacetimedb_schema::def::{ConstraintDef, IndexDef, ModuleDef, ReducerDef, ScopedTypeName, TableDef, TypeDef};
use spacetimedb_schema::identifier::Identifier;
use spacetimedb_schema::reducer_name::ReducerName;
use spacetimedb_schema::schema::TableSchema;
use spacetimedb_schema::type_for_generate::{AlgebraicTypeDef, AlgebraicTypeUse, ProductTypeDef};

Expand Down Expand Up @@ -213,7 +214,7 @@ impl Lang for TypeScript {
for reducer in iter_reducers(module) {
let reducer_name = &reducer.name;
let reducer_module_name = reducer_module_name(reducer_name);
let args_type = reducer_args_type_name(&reducer.name);
let args_type = reducer_args_type_name(reducer_name);
writeln!(out, "import {args_type} from \"./{reducer_module_name}\";");
writeln!(out, "export {{ {args_type} }};");
}
Expand Down Expand Up @@ -818,15 +819,15 @@ fn table_module_name(table_name: &Identifier) -> String {
table_name.deref().to_case(Case::Snake) + "_table"
}

fn reducer_args_type_name(reducer_name: &Identifier) -> String {
fn reducer_args_type_name(reducer_name: &ReducerName) -> String {
reducer_name.deref().to_case(Case::Pascal) + "Reducer"
}

fn procedure_args_type_name(reducer_name: &Identifier) -> String {
reducer_name.deref().to_case(Case::Pascal) + "Procedure"
}

fn reducer_module_name(reducer_name: &Identifier) -> String {
fn reducer_module_name(reducer_name: &ReducerName) -> String {
reducer_name.deref().to_case(Case::Snake) + "_reducer"
}

Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/client/message_handlers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use spacetimedb_datastore::execution_context::WorkloadType;
use spacetimedb_lib::de::serde::DeserializeWrapper;
use spacetimedb_lib::identity::RequestId;
use spacetimedb_lib::{bsatn, ConnectionId, Timestamp};
use spacetimedb_schema::reducer_name::ReducerName;
use std::borrow::Cow;
use std::sync::Arc;
use std::time::{Duration, Instant};
Expand Down Expand Up @@ -178,7 +179,7 @@ impl MessageExecutionError {
caller_identity: self.caller_identity,
caller_connection_id: self.caller_connection_id,
function_call: ModuleFunctionCall {
reducer: self.reducer.unwrap_or_else(|| "<none>".into()).into(),
reducer: ReducerName::new_from_str(&self.reducer.unwrap_or_else(|| "<none>".into())),
reducer_id: self.reducer_id.unwrap_or(u32::MAX.into()),
args: Default::default(),
},
Expand Down
14 changes: 8 additions & 6 deletions crates/core/src/client/messages.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use crate::subscription::row_list_builder_pool::BsatnRowListBuilderPool;
use crate::subscription::websocket_building::{brotli_compress, decide_compression, gzip_compress};
use bytes::{BufMut, Bytes, BytesMut};
use bytestring::ByteString;
use core::ops::Deref;
use derive_more::From;
use spacetimedb_client_api_messages::websocket::{
BsatnFormat, Compression, FormatSwitch, JsonFormat, OneOffTable, RowListLen, WebsocketFormat,
Expand All @@ -18,6 +19,7 @@ use spacetimedb_lib::ser::serde::SerializeWrapper;
use spacetimedb_lib::{AlgebraicValue, ConnectionId, TimeDuration, Timestamp};
use spacetimedb_primitives::TableId;
use spacetimedb_sats::bsatn;
use spacetimedb_schema::table_name::TableName;
use std::sync::Arc;
use std::time::Instant;

Expand Down Expand Up @@ -281,7 +283,7 @@ impl ToProtocol for TransactionUpdateMessage {
status,
caller_identity: event.caller_identity,
reducer_call: ws::ReducerCallInfo {
reducer_name: event.function_call.reducer.to_owned().into(),
reducer_name: event.function_call.reducer.deref().into(),
reducer_id: event.function_call.reducer_id.into(),
args,
request_id,
Expand Down Expand Up @@ -378,7 +380,7 @@ pub struct SubscriptionData {
#[derive(Debug, Clone)]
pub struct SubscriptionRows {
pub table_id: TableId,
pub table_name: Box<str>,
pub table_name: TableName,
pub table_rows: FormatSwitch<ws::TableUpdate<BsatnFormat>, ws::TableUpdate<JsonFormat>>,
}

Expand Down Expand Up @@ -449,7 +451,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name,
table_name: result.table_name.to_boxed_str(),
table_rows,
},
}
Expand All @@ -462,7 +464,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name,
table_name: result.table_name.to_boxed_str(),
table_rows,
},
}
Expand All @@ -480,7 +482,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name,
table_name: result.table_name.to_boxed_str(),
table_rows,
},
}
Expand All @@ -493,7 +495,7 @@ impl ToProtocol for SubscriptionMessage {
query_id,
rows: ws::SubscribeRows {
table_id: result.table_id,
table_name: result.table_name,
table_name: result.table_name.to_boxed_str(),
table_rows,
},
}
Expand Down
3 changes: 2 additions & 1 deletion crates/core/src/db/durability.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ mod tests {
use futures::FutureExt as _;
use pretty_assertions::assert_matches;
use spacetimedb_sats::product;
use spacetimedb_schema::table_name::TableName;
use tokio::sync::watch;

use super::*;
Expand Down Expand Up @@ -317,7 +318,7 @@ mod tests {
let mut txdata = TxData::default();
txdata.set_tx_offset(i);
// Ensure the transaction is non-empty.
txdata.set_inserts_for_table(4000.into(), "foo", [product![42u8]].into());
txdata.set_inserts_for_table(4000.into(), &TableName::new_from_str("foo"), [product![42u8]].into());

worker.request_durability(None, &Arc::new(txdata));
}
Expand Down
5 changes: 3 additions & 2 deletions crates/core/src/db/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::sync::Arc;

use enum_map::EnumMap;
use spacetimedb_schema::reducer_name::ReducerName;
use tokio::sync::mpsc;

use crate::subscription::ExecutionCounters;
Expand Down Expand Up @@ -37,7 +38,7 @@ pub struct Config {
/// We use a separate task to record metrics to avoid blocking transactions.
pub struct MetricsMessage {
/// The reducer the produced these metrics.
reducer: String,
reducer: ReducerName,
/// Metrics from a mutable transaction.
metrics_for_writer: Option<TxMetrics>,
/// Metrics from a read-only transaction.
Expand All @@ -60,7 +61,7 @@ pub struct MetricsRecorderQueue {
impl MetricsRecorderQueue {
pub fn send_metrics(
&self,
reducer: String,
reducer: ReducerName,
metrics_for_writer: Option<TxMetrics>,
metrics_for_reader: Option<TxMetrics>,
tx_data: Option<Arc<TxData>>,
Expand Down
Loading
Loading