Skip to content

Commit

Permalink
Rename host argument in SDK's connect to spacetimedb_uri (#119)
Browse files Browse the repository at this point in the history
This commit renames the first argument to connect from host to spacetimedb_uri. It's not just a host(name), it's the URI of the SpacetimeDB instance.
  • Loading branch information
gefjon authored and cloutiertyler committed Aug 1, 2023
1 parent a2c712a commit 8230301
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
10 changes: 5 additions & 5 deletions crates/cli/src/subcommands/generate/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1001,7 +1001,7 @@ fn print_handle_event_defn(out: &mut Indenter, items: &[GenItem]) {
}

const CONNECT_DOCSTRING: &[&str] = &[
"/// Connect to a database named `db_name` accessible over the internet at the URI `host`.",
"/// Connect to a database named `db_name` accessible over the internet at the URI `spacetimedb_uri`.",
"///",
"/// If `credentials` are supplied, they will be passed to the new connection to",
"/// identify and authenticate the user. Otherwise, a set of `Credentials` will be",
Expand All @@ -1017,17 +1017,17 @@ fn print_connect_docstring(out: &mut Indenter) {
fn print_connect_defn(out: &mut Indenter) {
print_connect_docstring(out);
out.delimited_block(
"pub fn connect<Host>(host: Host, db_name: &str, credentials: Option<Credentials>) -> Result<()>
"pub fn connect<IntoUri>(spacetimedb_uri: IntoUri, db_name: &str, credentials: Option<Credentials>) -> Result<()>
where
\tHost: TryInto<spacetimedb_sdk::http::Uri>,
\t<Host as TryInto<spacetimedb_sdk::http::Uri>>::Error: std::error::Error + Send + Sync + 'static,
\tIntoUri: TryInto<spacetimedb_sdk::http::Uri>,
\t<IntoUri as TryInto<spacetimedb_sdk::http::Uri>>::Error: std::error::Error + Send + Sync + 'static,
{",
|out| out.delimited_block(
"with_connection_mut(|connection| {",
|out| {
writeln!(
out,
"connection.connect(host, db_name, credentials, handle_table_update, handle_resubscribe, invoke_row_callbacks, handle_event)?;"
"connection.connect(spacetimedb_uri, db_name, credentials, handle_table_update, handle_resubscribe, invoke_row_callbacks, handle_event)?;"
).unwrap();
writeln!(out, "Ok(())").unwrap();
},
Expand Down
12 changes: 6 additions & 6 deletions crates/sdk/src/background_connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ impl BackgroundDbConnection {
))
}

/// Connect to a database named `db_name` accessible over the internet at the URI `host`.
/// Connect to a database named `db_name` accessible over the internet at the URI `spacetimedb_uri`.
///
/// If `credentials` are supplied, they will be passed to the new connection to
/// identify and authenticate the user. Otherwise, a set of `Credentials` will be
Expand All @@ -293,9 +293,9 @@ impl BackgroundDbConnection {
// calls are autogenerated by the CLI,
// with a wrapper that takes only 3 arguments.
#[allow(clippy::too_many_arguments)]
pub fn connect<Host>(
pub fn connect<IntoUri>(
&mut self,
host: Host,
spacetimedb_uri: IntoUri,
db_name: &str,
credentials: Option<Credentials>,
handle_table_update: crate::client_cache::HandleTableUpdateFn,
Expand All @@ -304,14 +304,14 @@ impl BackgroundDbConnection {
handle_event: crate::callbacks::HandleEventFn,
) -> Result<()>
where
Host: TryInto<http::Uri>,
<Host as TryInto<http::Uri>>::Error: std::error::Error + Send + Sync + 'static,
IntoUri: TryInto<http::Uri>,
<IntoUri as TryInto<http::Uri>>::Error: std::error::Error + Send + Sync + 'static,
{
// `block_in_place` is required here, as tokio won't allow us to call
// `block_on` if it would block the current thread of an outer runtime
let connection = tokio::task::block_in_place(|| {
self.handle
.block_on(DbConnection::connect(host, db_name, credentials.as_ref()))
.block_on(DbConnection::connect(spacetimedb_uri, db_name, credentials.as_ref()))
})?;
let client_cache = Arc::new(Mutex::new(Arc::new(ClientCache::new(
handle_table_update,
Expand Down

0 comments on commit 8230301

Please sign in to comment.