Skip to content
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

Rename host argument in SDK's connect to spacetimedb_uri #119

Merged
merged 1 commit into from
Jul 31, 2023
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: 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