Skip to content

Rename module name to database name #2516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions crates/sdk/examples/quickstart-chat/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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!
Expand Down
22 changes: 16 additions & 6 deletions crates/sdk/src/db_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ impl CallReducerFlagsMap {
pub struct DbConnectionBuilder<M: SpacetimeModule> {
uri: Option<Uri>,

module_name: Option<String>,
database_name: Option<String>,

token: Option<String>,

Expand Down Expand Up @@ -788,7 +788,7 @@ impl<M: SpacetimeModule> DbConnectionBuilder<M> {
pub fn new() -> Self {
Self {
uri: None,
module_name: None,
database_name: None,
token: None,
on_connect: None,
on_connect_error: None,
Expand All @@ -807,7 +807,7 @@ impl<M: SpacetimeModule> DbConnectionBuilder<M> {
/// 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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -892,9 +892,19 @@ but you must call one of them, or else the connection will never progress.
self
}

/// Set the name or identity of the remote module.
/// 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<String>) -> Self {
self.module_name = Some(name_or_identity.into());
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<String>) -> Self {
self.database_name = Some(name_or_identity.into());
self
}

Expand Down
4 changes: 2 additions & 2 deletions crates/sdk/tests/connect_disconnect_client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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, _, _| {
Expand Down Expand Up @@ -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();
Expand Down
8 changes: 4 additions & 4 deletions crates/sdk/tests/test-client/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1663,7 +1663,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()
Expand Down Expand Up @@ -1697,7 +1697,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()
Expand All @@ -1715,7 +1715,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 |_, _, _| {
Expand Down Expand Up @@ -1743,7 +1743,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, _, _| {
Expand Down