From 6ee0931d3962ceb9fb5ab56495593a8ced8e30ec Mon Sep 17 00:00:00 2001 From: Tamaro Skaljic <49238587+tamaro-skaljic@users.noreply.github.com> Date: Thu, 27 Mar 2025 19:05:28 +0100 Subject: [PATCH 1/2] Rename module name to database name Fixes #2515 --- crates/sdk/examples/quickstart-chat/main.rs | 4 ++-- crates/sdk/src/db_connection.rs | 14 +++++++------- .../tests/connect_disconnect_client/src/main.rs | 4 ++-- crates/sdk/tests/test-client/src/main.rs | 10 +++++----- 4 files changed, 16 insertions(+), 16 deletions(-) diff --git a/crates/sdk/examples/quickstart-chat/main.rs b/crates/sdk/examples/quickstart-chat/main.rs index e04ff9cb3cc..33e926db2e4 100644 --- a/crates/sdk/examples/quickstart-chat/main.rs +++ b/crates/sdk/examples/quickstart-chat/main.rs @@ -29,7 +29,7 @@ fn main() { /// The URI of the SpacetimeDB instance hosting our chat module. const HOST: &str = "http://localhost:3000"; -/// The module name we chose when we published our module. +/// The database name we chose when we published our module. const DB_NAME: &str = "quickstart-chat"; /// Load credentials from a file and connect to the database. @@ -46,7 +46,7 @@ fn connect_to_db() -> DbConnection { // so we can re-authenticate as the same `Identity`. .with_token(creds_store().load().expect("Error loading credentials")) // Set the database name we chose when we called `spacetime publish`. - .with_module_name(DB_NAME) + .with_database_name(DB_NAME) // Set the URI of the SpacetimeDB host that's running our database. .with_uri(HOST) // Finalize configuration and connect! diff --git a/crates/sdk/src/db_connection.rs b/crates/sdk/src/db_connection.rs index e1e4133e3ca..f0685b91824 100644 --- a/crates/sdk/src/db_connection.rs +++ b/crates/sdk/src/db_connection.rs @@ -739,7 +739,7 @@ impl CallReducerFlagsMap { pub struct DbConnectionBuilder { uri: Option, - module_name: Option, + database_name: Option, token: Option, @@ -788,7 +788,7 @@ impl DbConnectionBuilder { pub fn new() -> Self { Self { uri: None, - module_name: None, + database_name: None, token: None, on_connect: None, on_connect_error: None, @@ -807,7 +807,7 @@ impl DbConnectionBuilder { /// the connection may still fail asynchronously, /// leading to the [`Self::on_connect_error`] callback being invoked. /// - /// Before calling this method, make sure to invoke at least [`Self::with_uri`] and [`Self::with_module_name`] + /// Before calling this method, make sure to invoke at least [`Self::with_uri`] and [`Self::with_database_name`] /// to configure the connection. #[must_use = " You must explicitly advance the connection by calling any one of: @@ -837,7 +837,7 @@ but you must call one of them, or else the connection will never progress. let ws_connection = tokio::task::block_in_place(|| { handle.block_on(WsConnection::connect( self.uri.unwrap(), - self.module_name.as_ref().unwrap(), + self.database_name.as_ref().unwrap(), self.token.as_deref(), get_connection_id(), self.params, @@ -892,9 +892,9 @@ but you must call one of them, or else the connection will never progress. self } - /// Set the name or identity of the remote module. - pub fn with_module_name(mut self, name_or_identity: impl Into) -> Self { - self.module_name = Some(name_or_identity.into()); + /// Set the name or identity of the remote database. + pub fn with_database_name(mut self, name_or_identity: impl Into) -> Self { + self.database_name = Some(name_or_identity.into()); self } diff --git a/crates/sdk/tests/connect_disconnect_client/src/main.rs b/crates/sdk/tests/connect_disconnect_client/src/main.rs index de9e9dd3fba..772e0624cc6 100644 --- a/crates/sdk/tests/connect_disconnect_client/src/main.rs +++ b/crates/sdk/tests/connect_disconnect_client/src/main.rs @@ -21,7 +21,7 @@ fn main() { let sub_applied_one_row_result = connect_test_counter.add_test("connected_row"); let connection = DbConnection::builder() - .with_module_name(db_name_or_panic()) + .with_database_name(db_name_or_panic()) .with_uri(LOCALHOST) .on_connect_error(|_ctx, error| panic!("on_connect_error: {:?}", error)) .on_connect(move |ctx, _, _| { @@ -75,7 +75,7 @@ fn main() { .on_connect(move |_ctx, _, _| { reconnected_result(Ok(())); }) - .with_module_name(db_name_or_panic()) + .with_database_name(db_name_or_panic()) .with_uri(LOCALHOST) .build() .unwrap(); diff --git a/crates/sdk/tests/test-client/src/main.rs b/crates/sdk/tests/test-client/src/main.rs index a16ea0c4bb3..a12a144575a 100644 --- a/crates/sdk/tests/test-client/src/main.rs +++ b/crates/sdk/tests/test-client/src/main.rs @@ -368,7 +368,7 @@ fn connect_with_then( let connected_result = test_counter.add_test(format!("on_connect_{on_connect_suffix}")); let name = db_name_or_panic(); let builder = DbConnection::builder() - .with_module_name(name) + .with_database_name(name) .with_uri(LOCALHOST) .on_connect(|ctx, _, _| { callback(ctx); @@ -1657,7 +1657,7 @@ fn exec_reauth_part_1() { save_result(creds_store().save(token).map_err(Into::into)); }) .on_connect_error(|_ctx, error| panic!("Connect failed: {:?}", error)) - .with_module_name(name) + .with_database_name(name) .with_uri(LOCALHOST) .build() .unwrap() @@ -1691,7 +1691,7 @@ fn exec_reauth_part_2() { } }) .on_connect_error(|_ctx, error| panic!("Connect failed: {:?}", error)) - .with_module_name(name) + .with_database_name(name) .with_token(Some(token)) .with_uri(LOCALHOST) .build() @@ -1709,7 +1709,7 @@ fn exec_reconnect_same_connection_id() { let disconnect_result = disconnect_test_counter.add_test("disconnect"); let initial_connection = DbConnection::builder() - .with_module_name(db_name_or_panic()) + .with_database_name(db_name_or_panic()) .with_uri(LOCALHOST) .on_connect_error(|_ctx, error| panic!("on_connect_error: {:?}", error)) .on_connect(move |_, _, _| { @@ -1737,7 +1737,7 @@ fn exec_reconnect_same_connection_id() { let addr_after_reconnect_result = reconnect_test_counter.add_test("addr_after_reconnect"); let re_connection = DbConnection::builder() - .with_module_name(db_name_or_panic()) + .with_database_name(db_name_or_panic()) .with_uri(LOCALHOST) .on_connect_error(|_ctx, error| panic!("on_connect_error: {:?}", error)) .on_connect(move |ctx, _, _| { From 18624e5bd00217858bbf88e14b33adb8b521adad Mon Sep 17 00:00:00 2001 From: Tamaro Skaljic <49238587+tamaro-skaljic@users.noreply.github.com> Date: Wed, 2 Apr 2025 20:44:07 +0200 Subject: [PATCH 2/2] Rework so that no major semver version bump is needed Instead of removing the with_module_name builder method: - add a with_database_method and - add the deprecated-attribute to the with_module_name method. - Also one test uses the with_module_name method instead of the with_databaseName method. --- crates/sdk/src/db_connection.rs | 10 ++++++++++ crates/sdk/tests/test-client/src/main.rs | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/crates/sdk/src/db_connection.rs b/crates/sdk/src/db_connection.rs index f0685b91824..e45b15ca678 100644 --- a/crates/sdk/src/db_connection.rs +++ b/crates/sdk/src/db_connection.rs @@ -892,6 +892,16 @@ but you must call one of them, or else the connection will never progress. self } + /// Set the name or identity of the remote database. + #[deprecated( + since = "1.0.2", + note = "You should instead use [`DbConnectionBuilder::with_module_name`]." + )] + pub fn with_module_name(mut self, name_or_identity: impl Into) -> Self { + self.database_name = Some(name_or_identity.into()); + self + } + /// Set the name or identity of the remote database. pub fn with_database_name(mut self, name_or_identity: impl Into) -> Self { self.database_name = Some(name_or_identity.into()); diff --git a/crates/sdk/tests/test-client/src/main.rs b/crates/sdk/tests/test-client/src/main.rs index a12a144575a..fc32e272ffa 100644 --- a/crates/sdk/tests/test-client/src/main.rs +++ b/crates/sdk/tests/test-client/src/main.rs @@ -368,7 +368,7 @@ fn connect_with_then( let connected_result = test_counter.add_test(format!("on_connect_{on_connect_suffix}")); let name = db_name_or_panic(); let builder = DbConnection::builder() - .with_database_name(name) + .with_module_name(name) .with_uri(LOCALHOST) .on_connect(|ctx, _, _| { callback(ctx);