mirror of
https://github.com/clockworklabs/SpacetimeDB.git
synced 2026-05-06 07:26:43 -04:00
Rename with_module_name -> with_database_name (#4267)
# Description of Changes Modules are like programs, databases are like processes. Your client connects to a remote database, not a remote module. <!-- Please describe your change, mention any related tickets, and so on here. --> # API and ABI breaking changes Yep! # Expected complexity level and risk 2? I made this change with find + replace, and it's possible that I borked the edit, or missed some reference somehow. It seems unlikely, however, that this change will have deeper implications we haven't considered. # Testing N/a
This commit is contained in:
@@ -25,7 +25,7 @@ import { DbConnection } from './module_bindings';
|
||||
|
||||
const connection = DbConnection.builder()
|
||||
.withUri('ws://localhost:3000')
|
||||
.withModuleName('MODULE_NAME')
|
||||
.withDatabaseName('MODULE_NAME')
|
||||
.onDisconnect(() => {
|
||||
console.log('disconnected');
|
||||
})
|
||||
@@ -71,7 +71,7 @@ This module also include React hooks to subscribe to tables under the `spacetime
|
||||
```tsx
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri('ws://localhost:3000')
|
||||
.withModuleName('MODULE_NAME')
|
||||
.withDatabaseName('MODULE_NAME')
|
||||
.withLightMode(true)
|
||||
.onDisconnect(() => {
|
||||
console.log('disconnected');
|
||||
|
||||
@@ -57,13 +57,13 @@ export class DbConnectionBuilder<DbConnection extends DbConnectionImpl<any>> {
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the name or Identity of the database module to connect to.
|
||||
* Set the name or Identity of the remote database to connect to.
|
||||
*
|
||||
* @param nameOrAddress
|
||||
*
|
||||
* @returns The `DbConnectionBuilder` instance.
|
||||
*/
|
||||
withModuleName(nameOrAddress: string): this {
|
||||
withDatabaseName(nameOrAddress: string): this {
|
||||
this.#nameOrAddress = nameOrAddress;
|
||||
return this;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ export class DbConnectionBuilder<DbConnection extends DbConnectionImpl<any>> {
|
||||
* const host = "http://localhost:3000";
|
||||
* const name_or_address = "database_name"
|
||||
* const auth_token = undefined;
|
||||
* DbConnection.builder().withUri(host).withModuleName(name_or_address).withToken(auth_token).build();
|
||||
* DbConnection.builder().withUri(host).withDatabaseName(name_or_address).withToken(auth_token).build();
|
||||
* ```
|
||||
*/
|
||||
build(): DbConnection {
|
||||
|
||||
@@ -7,7 +7,7 @@ import { DbConnection, query } from './module_bindings/index.ts';
|
||||
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri('ws://localhost:3000')
|
||||
.withModuleName('game')
|
||||
.withDatabaseName('game')
|
||||
.withLightMode(true)
|
||||
.onDisconnect(() => {
|
||||
console.log('disconnected');
|
||||
|
||||
@@ -24,7 +24,7 @@ const onConnectError = (_ctx: ErrorContext, err: Error) => {
|
||||
// set all the settings you need, be sure your Uri and Module Name are correct
|
||||
const connBuilder = DbConnection.builder()
|
||||
.withUri('ws://localhost:3000')
|
||||
.withModuleName('simple-stdb-react-hooks-example')
|
||||
.withDatabaseName('simple-stdb-react-hooks-example')
|
||||
.withToken(localStorage.getItem('stdbToken') || '')
|
||||
.onConnect(onConnect)
|
||||
.onConnectError(onConnectError)
|
||||
|
||||
@@ -73,7 +73,7 @@ describe('DbConnection', () => {
|
||||
let connectCalled = false;
|
||||
const client = DbConnection.builder()
|
||||
.withUri('ws://127.0.0.1:1234')
|
||||
.withModuleName('db')
|
||||
.withDatabaseName('db')
|
||||
.withWSFn(() => {
|
||||
return Promise.reject(new Error('Failed to connect'));
|
||||
})
|
||||
@@ -99,7 +99,7 @@ describe('DbConnection', () => {
|
||||
let called = false;
|
||||
const client = DbConnection.builder()
|
||||
.withUri('ws://127.0.0.1:1234')
|
||||
.withModuleName('db')
|
||||
.withDatabaseName('db')
|
||||
.withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter) as any)
|
||||
.onConnect(() => {
|
||||
called = true;
|
||||
@@ -126,7 +126,7 @@ describe('DbConnection', () => {
|
||||
const wsAdapter = new WebsocketTestAdapter();
|
||||
const client = DbConnection.builder()
|
||||
.withUri('ws://127.0.0.1:1234')
|
||||
.withModuleName('db')
|
||||
.withDatabaseName('db')
|
||||
.withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter) as any)
|
||||
.onConnect(() => {})
|
||||
.build();
|
||||
@@ -305,7 +305,7 @@ describe('DbConnection', () => {
|
||||
const wsAdapter = new WebsocketTestAdapter();
|
||||
const client = DbConnection.builder()
|
||||
.withUri('ws://127.0.0.1:1234')
|
||||
.withModuleName('db')
|
||||
.withDatabaseName('db')
|
||||
.withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter) as any)
|
||||
.onConnect(() => {})
|
||||
.build();
|
||||
@@ -373,7 +373,7 @@ describe('DbConnection', () => {
|
||||
const wsAdapter = new WebsocketTestAdapter();
|
||||
const client = DbConnection.builder()
|
||||
.withUri('ws://127.0.0.1:1234')
|
||||
.withModuleName('db')
|
||||
.withDatabaseName('db')
|
||||
.withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter) as any)
|
||||
.onConnect(() => {})
|
||||
.build();
|
||||
@@ -451,7 +451,7 @@ describe('DbConnection', () => {
|
||||
const wsAdapter = new WebsocketTestAdapter();
|
||||
const client = DbConnection.builder()
|
||||
.withUri('ws://127.0.0.1:1234')
|
||||
.withModuleName('db')
|
||||
.withDatabaseName('db')
|
||||
.withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter) as any)
|
||||
.onConnect(() => {})
|
||||
.build();
|
||||
@@ -585,7 +585,7 @@ describe('DbConnection', () => {
|
||||
const wsAdapter = new WebsocketTestAdapter();
|
||||
const client = DbConnection.builder()
|
||||
.withUri('ws://127.0.0.1:1234')
|
||||
.withModuleName('db')
|
||||
.withDatabaseName('db')
|
||||
.withWSFn(wsAdapter.createWebSocketFn.bind(wsAdapter) as any)
|
||||
.build();
|
||||
await client['wsPromise'];
|
||||
|
||||
@@ -2854,7 +2854,7 @@ fn generate_db_connection_builder_class(output: &mut UnrealCppAutogen, api_macro
|
||||
writeln!(output, " UFUNCTION(BlueprintCallable, Category = \"SpacetimeDB\")");
|
||||
writeln!(
|
||||
output,
|
||||
" UDbConnectionBuilder* WithModuleName(const FString& InName);"
|
||||
" UDbConnectionBuilder* WithDatabaseName(const FString& InName);"
|
||||
);
|
||||
writeln!(output, " UFUNCTION(BlueprintCallable, Category = \"SpacetimeDB\")");
|
||||
writeln!(output, " UDbConnectionBuilder* WithToken(const FString& InToken);");
|
||||
@@ -3455,12 +3455,12 @@ fn generate_client_implementation(
|
||||
writeln!(output, "}}");
|
||||
writeln!(
|
||||
output,
|
||||
"UDbConnectionBuilder* UDbConnectionBuilder::WithModuleName(const FString& InName)"
|
||||
"UDbConnectionBuilder* UDbConnectionBuilder::WithDatabaseName(const FString& InName)"
|
||||
);
|
||||
writeln!(output, "{{");
|
||||
writeln!(
|
||||
output,
|
||||
"\treturn Cast<UDbConnectionBuilder>(WithModuleNameBase(InName));"
|
||||
"\treturn Cast<UDbConnectionBuilder>(WithDatabaseNameBase(InName));"
|
||||
);
|
||||
writeln!(output, "}}");
|
||||
writeln!(
|
||||
|
||||
@@ -27,7 +27,7 @@ public class PlayModeExampleTest
|
||||
{
|
||||
Debug.Assert(false, "Connection failed!");
|
||||
}).WithUri("http://127.0.0.1:3000")
|
||||
.WithModuleName("blackholio").Build();
|
||||
.WithDatabaseName("blackholio").Build();
|
||||
|
||||
while (!connected)
|
||||
{
|
||||
|
||||
@@ -42,7 +42,7 @@ public class GameManager : MonoBehaviour
|
||||
.OnConnectError(HandleConnectError)
|
||||
.OnDisconnect(HandleDisconnect)
|
||||
.WithUri(SERVER_URL)
|
||||
.WithModuleName(MODULE_NAME);
|
||||
.WithDatabaseName(MODULE_NAME);
|
||||
|
||||
// If the user has a SpacetimeDB auth token stored in the Unity PlayerPrefs,
|
||||
// we can use it to authenticate the connection.
|
||||
|
||||
@@ -65,7 +65,7 @@ void AGameManager::BeginPlay()
|
||||
|
||||
UDbConnectionBuilder* Builder = UDbConnection::Builder()
|
||||
->WithUri(ServerUri)
|
||||
->WithModuleName(ModuleName)
|
||||
->WithDatabaseName(ModuleName)
|
||||
->OnConnect(ConnectDelegate)
|
||||
->OnDisconnect(DisconnectDelegate)
|
||||
->OnConnectError(ConnectErrorDelegate);
|
||||
@@ -338,4 +338,4 @@ AFood* AGameManager::SpawnFood(const FFoodType& FoodEntity)
|
||||
EntityMap.Add(FoodEntity.EntityId, Food);
|
||||
}
|
||||
return Food;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -981,9 +981,9 @@ UDbConnectionBuilder* UDbConnectionBuilder::WithUri(const FString& InUri)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithUriBase(InUri));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithModuleName(const FString& InName)
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithDatabaseName(const FString& InName)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithModuleNameBase(InName));
|
||||
return Cast<UDbConnectionBuilder>(WithDatabaseNameBase(InName));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithToken(const FString& InToken)
|
||||
{
|
||||
|
||||
+1
-1
@@ -1257,7 +1257,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithUri(const FString& InUri);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithModuleName(const FString& InName);
|
||||
UDbConnectionBuilder* WithDatabaseName(const FString& InName);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithToken(const FString& InToken);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
|
||||
@@ -61,7 +61,7 @@ npm run build
|
||||
<script>
|
||||
const conn = DbConnection.builder()
|
||||
.withUri('ws://localhost:3000')
|
||||
.withModuleName('my-spacetime-app')
|
||||
.withDatabaseName('my-spacetime-app')
|
||||
.withToken(localStorage.getItem('auth_token'))
|
||||
.onConnect((conn, identity, token) => {
|
||||
localStorage.setItem('auth_token', token);
|
||||
|
||||
@@ -167,7 +167,7 @@ import { DbConnection } from './module_bindings/index.js';
|
||||
// Build and establish connection
|
||||
DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(await loadToken()) // Load saved token from file
|
||||
.onConnect((conn, identity, token) => {
|
||||
console.log('Connected! Identity:', identity.toHexString());
|
||||
|
||||
@@ -1387,7 +1387,7 @@ const onConnectError = (_ctx: ErrorContext, err: Error) => {
|
||||
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri('ws://localhost:3000')
|
||||
.withModuleName('quickstart-chat')
|
||||
.withDatabaseName('quickstart-chat')
|
||||
.withToken(localStorage.getItem('auth_token') || undefined)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
@@ -1761,7 +1761,7 @@ A connection to a SpacetimeDB database is represented by a `DbConnection`. We co
|
||||
In our case, we'll supply the following options:
|
||||
|
||||
1. A `WithUri` call, to specify the URI of the SpacetimeDB host where our database is running.
|
||||
2. A `WithModuleName` call, to specify the name or `Identity` of our database. Make sure to pass the same name here as you supplied to `spacetime publish`.
|
||||
2. A `WithDatabaseName` call, to specify the name or `Identity` of our database. Make sure to pass the same name here as you supplied to `spacetime publish`.
|
||||
3. A `WithToken` call, to supply a token to authenticate with.
|
||||
4. An `OnConnect` callback, to run when the remote database acknowledges and accepts our connection.
|
||||
5. An `OnConnectError` callback, to run if the remote database is unreachable or it rejects our connection.
|
||||
@@ -1782,7 +1782,7 @@ DbConnection ConnectToDB()
|
||||
DbConnection? conn = null;
|
||||
conn = DbConnection.Builder()
|
||||
.WithUri(HOST)
|
||||
.WithModuleName(DB_NAME)
|
||||
.WithDatabaseName(DB_NAME)
|
||||
.WithToken(AuthToken.Token)
|
||||
.OnConnect(OnConnected)
|
||||
.OnConnectError(OnConnectError)
|
||||
@@ -2318,7 +2318,7 @@ In our case, we'll supply the following options:
|
||||
2. An `on_connect_error` callback, to run if the remote database is unreachable or it rejects our connection.
|
||||
3. An `on_disconnect` callback, to run when our connection ends.
|
||||
4. A `with_token` call, to supply a token to authenticate with.
|
||||
5. A `with_module_name` call, to specify the name or `Identity` of our database. Make sure to pass the same name here as you supplied to `spacetime publish`.
|
||||
5. A `with_database_name` call, to specify the name or `Identity` of our database. Make sure to pass the same name here as you supplied to `spacetime publish`.
|
||||
6. A `with_uri` call, to specify the URI of the SpacetimeDB host where our database is running.
|
||||
|
||||
To `src/main.rs`, add:
|
||||
@@ -2344,7 +2344,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!
|
||||
|
||||
@@ -732,7 +732,7 @@ public class GameManager : MonoBehaviour
|
||||
.OnConnectError(HandleConnectError)
|
||||
.OnDisconnect(HandleDisconnect)
|
||||
.WithUri(SERVER_URL)
|
||||
.WithModuleName(MODULE_NAME);
|
||||
.WithDatabaseName(MODULE_NAME);
|
||||
|
||||
// If the user has a SpacetimeDB auth token stored in the Unity PlayerPrefs,
|
||||
// we can use it to authenticate the connection.
|
||||
|
||||
@@ -803,7 +803,7 @@ void AGameManager::BeginPlay()
|
||||
|
||||
UDbConnectionBuilder* Builder = UDbConnection::Builder()
|
||||
->WithUri(ServerUri)
|
||||
->WithModuleName(ModuleName)
|
||||
->WithDatabaseName(ModuleName)
|
||||
->OnConnect(ConnectDelegate)
|
||||
->OnDisconnect(DisconnectDelegate)
|
||||
->OnConnectError(ConnectErrorDelegate);
|
||||
|
||||
@@ -22,7 +22,7 @@ import { DbConnection, User, Message } from './module_bindings';
|
||||
// Connect to the database
|
||||
const conn = DbConnection.builder()
|
||||
.withUri('wss://maincloud.spacetimedb.com')
|
||||
.withModuleName('my_module')
|
||||
.withDatabaseName('my_module')
|
||||
.onConnect((ctx) => {
|
||||
// Subscribe to users and messages
|
||||
ctx.subscriptionBuilder()
|
||||
@@ -60,7 +60,7 @@ conn.db.user.onUpdate((ctx, oldUser, newUser) => {
|
||||
// Connect to the database
|
||||
var conn = DbConnection.Builder()
|
||||
.WithUri("wss://maincloud.spacetimedb.com")
|
||||
.WithModuleName("my_module")
|
||||
.WithDatabaseName("my_module")
|
||||
.OnConnect((ctx) =>
|
||||
{
|
||||
// Subscribe to users and messages
|
||||
@@ -104,7 +104,7 @@ conn.Db.User.OnUpdate += (ctx, oldUser, newUser) =>
|
||||
// Connect to the database
|
||||
let conn = DbConnection::builder()
|
||||
.with_uri("wss://maincloud.spacetimedb.com")
|
||||
.with_module_name("my_module")
|
||||
.with_database_name("my_module")
|
||||
.on_connect(|ctx| {
|
||||
// Subscribe to users and messages
|
||||
ctx.subscription_builder()
|
||||
@@ -288,7 +288,7 @@ import { DbConnection } from './module_bindings';
|
||||
|
||||
const conn = DbConnection.builder()
|
||||
.withUri('https://maincloud.spacetimedb.com')
|
||||
.withModuleName('my_module')
|
||||
.withDatabaseName('my_module')
|
||||
.build();
|
||||
|
||||
// Register a subscription with the database
|
||||
@@ -435,7 +435,7 @@ You subscribe to `shop_items` and `shop_discounts` when a player is at level 5:
|
||||
```typescript
|
||||
const conn = DbConnection.builder()
|
||||
.withUri('https://maincloud.spacetimedb.com')
|
||||
.withModuleName('my_module')
|
||||
.withDatabaseName('my_module')
|
||||
.build();
|
||||
|
||||
const shopItemsSubscription = conn
|
||||
@@ -576,7 +576,7 @@ This will improve throughput by reducing the amount of data transferred from the
|
||||
```typescript
|
||||
const conn = DbConnection.builder()
|
||||
.withUri('https://maincloud.spacetimedb.com')
|
||||
.withModuleName('my_module')
|
||||
.withDatabaseName('my_module')
|
||||
.build();
|
||||
|
||||
// Never need to unsubscribe from global subscriptions
|
||||
@@ -666,7 +666,7 @@ unsubscribing from it does not result in any server processing or data serializt
|
||||
```typescript
|
||||
const conn = DbConnection.builder()
|
||||
.withUri('https://maincloud.spacetimedb.com')
|
||||
.withModuleName('my_module')
|
||||
.withDatabaseName('my_module')
|
||||
.build();
|
||||
|
||||
// Initial subscription: player at level 5.
|
||||
|
||||
@@ -244,7 +244,7 @@ export default function App() {
|
||||
const connectionBuilder = useMemo(() => {
|
||||
return DbConnection.builder()
|
||||
.withUri('<YOUR SPACETIMEDB URL>')
|
||||
.withModuleName('<YOUR SPACETIMEDB MODULE NAME>')
|
||||
.withDatabaseName('<YOUR SPACETIMEDB MODULE NAME>')
|
||||
.withToken(idToken)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
|
||||
@@ -246,7 +246,7 @@ export default function App() {
|
||||
const connectionBuilder = useMemo(() => {
|
||||
return DbConnection.builder()
|
||||
.withUri('<YOUR SPACETIMEDB URL>')
|
||||
.withModuleName('<YOUR SPACETIMEDB MODULE NAME>')
|
||||
.withDatabaseName('<YOUR SPACETIMEDB MODULE NAME>')
|
||||
.withToken(token)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
|
||||
@@ -28,7 +28,7 @@ import { DbConnection } from './module_bindings';
|
||||
|
||||
const conn = new DbConnection.builder()
|
||||
.withUri("https://maincloud.spacetimedb.com")
|
||||
.withModuleName("my_database");
|
||||
.withDatabaseName("my_database");
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -39,7 +39,7 @@ using SpacetimeDB;
|
||||
|
||||
var conn = DbConnection.Builder()
|
||||
.WithUri(new Uri("https://maincloud.spacetimedb.com"))
|
||||
.WithModuleName("my_database")
|
||||
.WithDatabaseName("my_database")
|
||||
.Build();
|
||||
```
|
||||
|
||||
@@ -51,7 +51,7 @@ use module_bindings::DbConnection;
|
||||
|
||||
let conn = DbConnection::builder()
|
||||
.with_uri("https://maincloud.spacetimedb.com")
|
||||
.with_module_name("my_database")
|
||||
.with_database_name("my_database")
|
||||
.build();
|
||||
```
|
||||
|
||||
@@ -63,7 +63,7 @@ let conn = DbConnection::builder()
|
||||
|
||||
UDbConnection* Conn = UDbConnection::Builder()
|
||||
->WithUri(TEXT("https://maincloud.spacetimedb.com"))
|
||||
->WithModuleName(TEXT("my_database"))
|
||||
->WithDatabaseName(TEXT("my_database"))
|
||||
->Build();
|
||||
```
|
||||
|
||||
@@ -82,7 +82,7 @@ To connect to a database hosted on MainCloud:
|
||||
```typescript
|
||||
const conn = new DbConnection.builder()
|
||||
.withUri("https://maincloud.spacetimedb.com")
|
||||
.withModuleName("my_database");
|
||||
.withDatabaseName("my_database");
|
||||
```
|
||||
|
||||
</TabItem>
|
||||
@@ -91,7 +91,7 @@ const conn = new DbConnection.builder()
|
||||
```csharp
|
||||
var conn = DbConnection.Builder()
|
||||
.WithUri(new Uri("https://maincloud.spacetimedb.com"))
|
||||
.WithModuleName("my_database")
|
||||
.WithDatabaseName("my_database")
|
||||
.Build();
|
||||
```
|
||||
|
||||
@@ -101,7 +101,7 @@ var conn = DbConnection.Builder()
|
||||
```rust
|
||||
let conn = DbConnection::builder()
|
||||
.with_uri("https://maincloud.spacetimedb.com")
|
||||
.with_module_name("my_database")
|
||||
.with_database_name("my_database")
|
||||
.build();
|
||||
```
|
||||
|
||||
@@ -111,7 +111,7 @@ let conn = DbConnection::builder()
|
||||
```cpp
|
||||
UDbConnection* Conn = UDbConnection::Builder()
|
||||
->WithUri(TEXT("https://maincloud.spacetimedb.com"))
|
||||
->WithModuleName(TEXT("my_database"))
|
||||
->WithDatabaseName(TEXT("my_database"))
|
||||
->Build();
|
||||
```
|
||||
|
||||
@@ -128,7 +128,7 @@ To authenticate with a token (for example, from [SpacetimeAuth](../00500-authent
|
||||
```typescript
|
||||
const conn = new DbConnection.builder()
|
||||
.withUri("https://maincloud.spacetimedb.com")
|
||||
.withModuleName("my_database")
|
||||
.withDatabaseName("my_database")
|
||||
.withToken("your_auth_token_here");
|
||||
```
|
||||
|
||||
@@ -138,7 +138,7 @@ const conn = new DbConnection.builder()
|
||||
```csharp
|
||||
var conn = DbConnection.Builder()
|
||||
.WithUri(new Uri("https://maincloud.spacetimedb.com"))
|
||||
.WithModuleName("my_database")
|
||||
.WithDatabaseName("my_database")
|
||||
.WithToken("your_auth_token_here")
|
||||
.Build();
|
||||
```
|
||||
@@ -149,7 +149,7 @@ var conn = DbConnection.Builder()
|
||||
```rust
|
||||
let conn = DbConnection::builder()
|
||||
.with_uri("https://maincloud.spacetimedb.com")
|
||||
.with_module_name("my_database")
|
||||
.with_database_name("my_database")
|
||||
.with_token("your_auth_token_here")
|
||||
.build();
|
||||
```
|
||||
@@ -160,7 +160,7 @@ let conn = DbConnection::builder()
|
||||
```cpp
|
||||
UDbConnection* Conn = UDbConnection::Builder()
|
||||
->WithUri(TEXT("https://maincloud.spacetimedb.com"))
|
||||
->WithModuleName(TEXT("my_database"))
|
||||
->WithDatabaseName(TEXT("my_database"))
|
||||
->WithToken(TEXT("your_auth_token_here"))
|
||||
->Build();
|
||||
```
|
||||
@@ -233,7 +233,7 @@ Register callbacks to observe connection state changes:
|
||||
```typescript
|
||||
const conn = DbConnection.builder()
|
||||
.withUri("https://maincloud.spacetimedb.com")
|
||||
.withModuleName("my_database")
|
||||
.withDatabaseName("my_database")
|
||||
.onConnect((conn, identity, token) => {
|
||||
console.log(`Connected! Identity: ${identity.toHexString()}`);
|
||||
// Save token for reconnection
|
||||
@@ -253,7 +253,7 @@ const conn = DbConnection.builder()
|
||||
```csharp
|
||||
var conn = DbConnection.Builder()
|
||||
.WithUri(new Uri("https://maincloud.spacetimedb.com"))
|
||||
.WithModuleName("my_database")
|
||||
.WithDatabaseName("my_database")
|
||||
.OnConnect((conn, identity, token) =>
|
||||
{
|
||||
Console.WriteLine($"Connected! Identity: {identity}");
|
||||
@@ -283,7 +283,7 @@ var conn = DbConnection.Builder()
|
||||
```rust
|
||||
let conn = DbConnection::builder()
|
||||
.with_uri("https://maincloud.spacetimedb.com")
|
||||
.with_module_name("my_database")
|
||||
.with_database_name("my_database")
|
||||
.on_connect(|_ctx, _identity, token| {
|
||||
println!("Connected! Saving token...");
|
||||
// Save token for reconnection
|
||||
@@ -319,7 +319,7 @@ DisconnectDelegate.BindDynamic(this, &AMyActor::OnDisconnected);
|
||||
// Build connection with callbacks
|
||||
UDbConnection* Conn = UDbConnection::Builder()
|
||||
->WithUri(TEXT("https://maincloud.spacetimedb.com"))
|
||||
->WithModuleName(TEXT("my_database"))
|
||||
->WithDatabaseName(TEXT("my_database"))
|
||||
->OnConnect(ConnectDelegate)
|
||||
->OnConnectError(ErrorDelegate)
|
||||
->OnDisconnect(DisconnectDelegate)
|
||||
|
||||
@@ -76,12 +76,12 @@ impl DbConnection {
|
||||
}
|
||||
```
|
||||
|
||||
Construct a `DbConnection` by calling `DbConnection::builder()` and chaining configuration methods, then calling `.build()`. You must at least specify `with_uri`, to supply the URI of the SpacetimeDB to which you published your module, and `with_module_name`, to supply the human-readable SpacetimeDB domain name or the raw `Identity` which identifies the database.
|
||||
Construct a `DbConnection` by calling `DbConnection::builder()` and chaining configuration methods, then calling `.build()`. You must at least specify `with_uri`, to supply the URI of the SpacetimeDB to which you published your module, and `with_database_name`, to supply the human-readable SpacetimeDB domain name or the raw `Identity` which identifies the database.
|
||||
|
||||
| Name | Description |
|
||||
| ------------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
||||
|---------------------------------------------------------------|--------------------------------------------------------------------------------------|
|
||||
| [`with_uri` method](#method-with_uri) | Set the URI of the SpacetimeDB instance which hosts the remote database. |
|
||||
| [`with_module_name` method](#method-with_module_name) | Set the name or `Identity` of the remote database. |
|
||||
| [`with_database_name` method](#method-with_database_name) | Set the name or `Identity` of the remote database. |
|
||||
| [`with_confirmed_reads` method](#method-with_confirmed_reads) | Enable or disable confirmed reads. |
|
||||
| [`on_connect` callback](#callback-on_connect) | Register a callback to run when the connection is successfully established. |
|
||||
| [`on_connect_error` callback](#callback-on_connect_error) | Register a callback to run if the connection is rejected or the host is unreachable. |
|
||||
@@ -99,11 +99,11 @@ impl DbConnectionBuilder {
|
||||
|
||||
Configure the URI of the SpacetimeDB instance or cluster which hosts the remote database containing the module.
|
||||
|
||||
#### Method `with_module_name`
|
||||
#### Method `with_database_name`
|
||||
|
||||
```rust
|
||||
impl DbConnectionBuilder {
|
||||
fn with_module_name(self, name_or_identity: impl ToString) -> Self;
|
||||
fn with_database_name(self, name_or_identity: impl ToString) -> Self;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -79,12 +79,12 @@ class DbConnection
|
||||
}
|
||||
```
|
||||
|
||||
Construct a `DbConnection` by calling `DbConnection.Builder()`, chaining configuration methods, and finally calling `.Build()`. At a minimum, you must specify `WithUri` to provide the URI of the SpacetimeDB instance, and `WithModuleName` to specify the database's name or identity.
|
||||
Construct a `DbConnection` by calling `DbConnection.Builder()`, chaining configuration methods, and finally calling `.Build()`. At a minimum, you must specify `WithUri` to provide the URI of the SpacetimeDB instance, and `WithDatabaseName` to specify the database's name or identity.
|
||||
|
||||
| Name | Description |
|
||||
| ------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
||||
|---------------------------------------------------------|--------------------------------------------------------------------------------------|
|
||||
| [WithUri method](#method-withuri) | Set the URI of the SpacetimeDB instance hosting the remote database. |
|
||||
| [WithModuleName method](#method-withmodulename) | Set the name or identity of the remote database. |
|
||||
| [WithDatabaseName method](#method-withdatabasename) | Set the name or identity of the remote database. |
|
||||
| [WithConfirmedReads method](#method-withconfirmedreads) | Enable or disable confirmed reads. |
|
||||
| [OnConnect callback](#callback-onconnect) | Register a callback to run when the connection is successfully established. |
|
||||
| [OnConnectError callback](#callback-onconnecterror) | Register a callback to run if the connection is rejected or the host is unreachable. |
|
||||
@@ -103,12 +103,12 @@ class DbConnectionBuilder<DbConnection>
|
||||
|
||||
Configure the URI of the SpacetimeDB instance or cluster which hosts the remote module and database.
|
||||
|
||||
#### Method `WithModuleName`
|
||||
#### Method `WithDatabaseName`
|
||||
|
||||
```csharp
|
||||
class DbConnectionBuilder
|
||||
{
|
||||
public DbConnectionBuilder<DbConnection> WithModuleName(string nameOrIdentity);
|
||||
public DbConnectionBuilder<DbConnection> WithDatabaseName(string nameOrIdentity);
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
+5
-5
@@ -115,12 +115,12 @@ class DbConnection {
|
||||
}
|
||||
```
|
||||
|
||||
Construct a `DbConnection` by calling `DbConnection.builder()` and chaining configuration methods, then calling `.build()`. You must at least specify `withUri`, to supply the URI of the SpacetimeDB to which you published your module, and `withModuleName`, to supply the human-readable SpacetimeDB domain name or the raw `Identity` which identifies the database.
|
||||
Construct a `DbConnection` by calling `DbConnection.builder()` and chaining configuration methods, then calling `.build()`. You must at least specify `withUri`, to supply the URI of the SpacetimeDB to which you published your module, and `withDatabaseName`, to supply the human-readable SpacetimeDB domain name or the raw `Identity` which identifies the database.
|
||||
|
||||
| Name | Description |
|
||||
| --------------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
||||
|-----------------------------------------------------------|--------------------------------------------------------------------------------------|
|
||||
| [`withUri` method](#method-withuri) | Set the URI of the SpacetimeDB instance which hosts the remote database. |
|
||||
| [`withModuleName` method](#method-withmodulename) | Set the name or `Identity` of the remote database. |
|
||||
| [`withDatabaseName` method](#method-withdatabasename) | Set the name or `Identity` of the remote database. |
|
||||
| [`withConfirmedReads` method](#method-withconfirmedreads) | Enable or disable confirmed reads. |
|
||||
| [`onConnect` callback](#callback-onconnect) | Register a callback to run when the connection is successfully established. |
|
||||
| [`onConnectError` callback](#callback-onconnecterror) | Register a callback to run if the connection is rejected or the host is unreachable. |
|
||||
@@ -138,11 +138,11 @@ class DbConnectionBuilder {
|
||||
|
||||
Configure the URI of the SpacetimeDB instance or cluster which hosts the remote database.
|
||||
|
||||
#### Method `withModuleName`
|
||||
#### Method `withDatabaseName`
|
||||
|
||||
```typescript
|
||||
class DbConnectionBuilder {
|
||||
public withModuleName(name_or_identity: string): DbConnectionBuilder;
|
||||
public withDatabaseName(name_or_identity: string): DbConnectionBuilder;
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
@@ -71,12 +71,12 @@ class UDbConnection
|
||||
};
|
||||
```
|
||||
|
||||
Construct a `UDbConnection` by calling `UDbConnection::Builder()`, chaining configuration methods, and finally calling `.Build()`. At a minimum, you must specify `WithUri` to provide the URI of the SpacetimeDB instance, and `WithModuleName` to specify the database's name or identity.
|
||||
Construct a `UDbConnection` by calling `UDbConnection::Builder()`, chaining configuration methods, and finally calling `.Build()`. At a minimum, you must specify `WithUri` to provide the URI of the SpacetimeDB instance, and `WithDatabaseName` to specify the database's name or identity.
|
||||
|
||||
| Name | Description |
|
||||
| --------------------------------------------------- | ------------------------------------------------------------------------------------ |
|
||||
|-----------------------------------------------------|--------------------------------------------------------------------------------------|
|
||||
| [WithUri method](#method-withuri) | Set the URI of the SpacetimeDB instance hosting the remote database. |
|
||||
| [WithModuleName method](#method-withmodulename) | Set the name or identity of the remote database. |
|
||||
| [WithDatabaseName method](#method-withdatabasename) | Set the name or identity of the remote database. |
|
||||
| [WithToken method](#method-withtoken) | Supply a token to authenticate with the remote database. |
|
||||
| [WithCompression method](#method-withcompression) | Set the compression method for WebSocket communication. |
|
||||
| [OnConnect callback](#callback-onconnect) | Register a callback to run when the connection is successfully established. |
|
||||
@@ -96,13 +96,13 @@ class UDbConnectionBuilder
|
||||
|
||||
Configure the URI of the SpacetimeDB instance or cluster which hosts the remote module and database.
|
||||
|
||||
#### Method `WithModuleName`
|
||||
#### Method `WithDatabaseName`
|
||||
|
||||
```cpp
|
||||
class UDbConnectionBuilder
|
||||
{
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithModuleName(const FString& InName);
|
||||
UDbConnectionBuilder* WithDatabaseName(const FString& InName);
|
||||
};
|
||||
```
|
||||
|
||||
@@ -707,7 +707,7 @@ void AMyActor::BeginPlay()
|
||||
// Build and connect
|
||||
Conn = UDbConnection::Builder()
|
||||
->WithUri(TEXT("127.0.0.1:3000"))
|
||||
->WithModuleName(TEXT("my-module"))
|
||||
->WithDatabaseName(TEXT("my-module"))
|
||||
->OnConnect(ConnectDelegate)
|
||||
->OnDisconnect(DisconnectDelegate)
|
||||
->Build();
|
||||
|
||||
+1
-1
@@ -487,7 +487,7 @@ conn.subscriptionBuilder().subscribe([
|
||||
const builder = useMemo(() =>
|
||||
DbConnection.builder()
|
||||
.withUri(SPACETIMEDB_URI)
|
||||
.withModuleName(MODULE_NAME)
|
||||
.withDatabaseName(MODULE_NAME)
|
||||
.withToken(localStorage.getItem('auth_token') || undefined)
|
||||
.onConnect(onConnect)
|
||||
.onConnectError(onConnectError),
|
||||
|
||||
Vendored
+5
-5
@@ -1057,7 +1057,7 @@ mod module_bindings;
|
||||
The core type for managing a connection is `module_bindings::DbConnection`. You configure and establish a connection using a builder pattern.
|
||||
|
||||
- **Builder:** Start with `DbConnection::builder()`.
|
||||
- **URI & Name:** Specify the SpacetimeDB instance URI (`.with_uri("http://localhost:3000")`) and the database name or identity (`.with_module_name("my_database")`).
|
||||
- **URI & Name:** Specify the SpacetimeDB instance URI (`.with_uri("http://localhost:3000")`) and the database name or identity (`.with_database_name("my_database")`).
|
||||
- **Authentication:** Provide an identity token using `.with_token(Option<String>)`. If `None` or omitted for the first connection, the server issues a new identity and token (retrieved via the `on_connect` callback).
|
||||
- **Callbacks:** Register callbacks for connection lifecycle events:
|
||||
- `.on_connect(|conn, identity, token| { ... })`: Runs on successful connection. Often used to store the `token` for future connections.
|
||||
@@ -1080,7 +1080,7 @@ fn connect_to_db() -> DbConnection {
|
||||
|
||||
DbConnection::builder()
|
||||
.with_uri(HOST)
|
||||
.with_module_name(DB_NAME)
|
||||
.with_database_name(DB_NAME)
|
||||
.with_token(creds_store().load().ok()) // Load token if exists
|
||||
.on_connect(|conn, identity, auth_token| {
|
||||
println!("Connected. Identity: {}", identity.to_hex());
|
||||
@@ -1951,7 +1951,7 @@ Include the generated `.cs` files in your C# project or Unity Assets folder.
|
||||
The core type for managing a connection is `SpacetimeDB.Types.DbConnection` (this type name comes from the generated bindings). You configure and establish a connection using a builder pattern.
|
||||
|
||||
- **Builder:** Start with `DbConnection.Builder()`.
|
||||
- **URI & Name:** Specify the SpacetimeDB instance URI (`.WithUri("http://localhost:3000")`) and the database name or identity (`.WithModuleName("my_database")`).
|
||||
- **URI & Name:** Specify the SpacetimeDB instance URI (`.WithUri("http://localhost:3000")`) and the database name or identity (`.WithDatabaseName("my_database")`).
|
||||
- **Authentication:** Provide an identity token using `.WithToken(string?)`. The SDK provides a helper `AuthToken.Token` which loads a token from a local file (initialized via `AuthToken.Init(".credentials_filename")`). If `null` or omitted for the first connection, the server issues a new identity and token (retrieved via the `OnConnect` callback).
|
||||
- **Callbacks:** Register callbacks (as delegates or lambda expressions) for connection lifecycle events:
|
||||
- `.OnConnect((conn, identity, token) => { ... })`: Runs on successful connection. Often used to save the `token` using `AuthToken.SaveToken(token)`.
|
||||
@@ -1977,7 +1977,7 @@ public class ClientManager // Example class
|
||||
|
||||
connection = DbConnection.Builder()
|
||||
.WithUri(HOST)
|
||||
.WithModuleName(DB_NAME)
|
||||
.WithDatabaseName(DB_NAME)
|
||||
.WithToken(AuthToken.Token) // Load token if exists
|
||||
.OnConnect(HandleConnect)
|
||||
.OnConnectError(HandleConnectError)
|
||||
@@ -2590,7 +2590,7 @@ class ChatClient {
|
||||
|
||||
const connectionInstance = DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(token)
|
||||
.onConnect(this.handleConnect)
|
||||
.onDisconnect(this.handleDisconnect)
|
||||
|
||||
@@ -46,7 +46,7 @@ fn connect_to_db() -> DbConnection {
|
||||
.on_connect_error(on_connect_error)
|
||||
.on_disconnect(on_disconnected)
|
||||
.with_token(creds_store().load().expect("Error loading credentials"))
|
||||
.with_module_name(db_name)
|
||||
.with_database_name(db_name)
|
||||
.with_uri(host)
|
||||
.build()
|
||||
.expect("Failed to connect")
|
||||
|
||||
@@ -23,7 +23,7 @@ DbConnection ConnectToDB()
|
||||
conn = DbConnection
|
||||
.Builder()
|
||||
.WithUri(HOST)
|
||||
.WithModuleName(DBNAME)
|
||||
.WithDatabaseName(DBNAME)
|
||||
.OnConnect(OnConnected)
|
||||
.OnConnectError(
|
||||
(err) =>
|
||||
|
||||
@@ -16,7 +16,7 @@ DbConnection ConnectToDB()
|
||||
DbConnection? conn = null;
|
||||
conn = DbConnection.Builder()
|
||||
.WithUri(HOST)
|
||||
.WithModuleName(DBNAME)
|
||||
.WithDatabaseName(DBNAME)
|
||||
.OnConnect(OnConnected)
|
||||
.OnConnectError((err) =>
|
||||
{
|
||||
@@ -221,4 +221,4 @@ while (!applied || waiting > 0)
|
||||
}
|
||||
}
|
||||
Log.Info("Success");
|
||||
Environment.Exit(0);
|
||||
Environment.Exit(0);
|
||||
|
||||
@@ -16,7 +16,7 @@ DbConnection ConnectToDB()
|
||||
DbConnection? conn = null;
|
||||
conn = DbConnection.Builder()
|
||||
.WithUri(HOST)
|
||||
.WithModuleName(DBNAME)
|
||||
.WithDatabaseName(DBNAME)
|
||||
.OnConnect(OnConnected)
|
||||
.OnConnectError((err) =>
|
||||
{
|
||||
@@ -148,4 +148,4 @@ while (!applied || waiting > 0)
|
||||
}
|
||||
}
|
||||
Log.Info("Success");
|
||||
Environment.Exit(0);
|
||||
Environment.Exit(0);
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace SpacetimeDB
|
||||
}
|
||||
if (nameOrAddress == null)
|
||||
{
|
||||
throw new InvalidOperationException("Building DbConnection with a null nameOrAddress. Call WithModuleName() first.");
|
||||
throw new InvalidOperationException("Building DbConnection with a null nameOrAddress. Call WithDatabaseName() first.");
|
||||
}
|
||||
conn.Connect(token, uri, nameOrAddress, compression ?? Compression.Brotli, light, confirmedReads);
|
||||
#if UNITY_5_3_OR_NEWER
|
||||
@@ -49,7 +49,7 @@ namespace SpacetimeDB
|
||||
return this;
|
||||
}
|
||||
|
||||
public DbConnectionBuilder<DbConnection> WithModuleName(string nameOrAddress)
|
||||
public DbConnectionBuilder<DbConnection> WithDatabaseName(string nameOrAddress)
|
||||
{
|
||||
this.nameOrAddress = nameOrAddress;
|
||||
return this;
|
||||
|
||||
@@ -434,7 +434,7 @@ SampleUserInsert("k5DMlKmWjfbSl7qmZQOok7HDSwsAJopRSJjdlUsNogs=", null, true)
|
||||
var client =
|
||||
DbConnection.Builder()
|
||||
.WithUri("wss://spacetimedb.com")
|
||||
.WithModuleName("example")
|
||||
.WithDatabaseName("example")
|
||||
.OnConnect((conn, identity, token) => events.Add("OnConnect", new { identity, token }))
|
||||
.Build();
|
||||
|
||||
|
||||
@@ -833,7 +833,7 @@ impl CallReducerFlagsMap {
|
||||
pub struct DbConnectionBuilder<M: SpacetimeModule> {
|
||||
uri: Option<Uri>,
|
||||
|
||||
module_name: Option<String>,
|
||||
database_name: Option<String>,
|
||||
|
||||
token: Option<String>,
|
||||
|
||||
@@ -883,7 +883,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,
|
||||
@@ -892,7 +892,7 @@ impl<M: SpacetimeModule> DbConnectionBuilder<M> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Open a WebSocket connection to the remote module,
|
||||
/// Open a WebSocket connection to the remote database,
|
||||
/// with all configuration and callbacks registered in the builder `self`.
|
||||
///
|
||||
/// This method panics if `self` lacks a required configuration,
|
||||
@@ -902,7 +902,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:
|
||||
@@ -934,7 +934,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(),
|
||||
connection_id_override,
|
||||
self.params,
|
||||
@@ -982,7 +982,7 @@ but you must call one of them, or else the connection will never progress.
|
||||
Ok(ctx_imp)
|
||||
}
|
||||
|
||||
/// Set the URI of the SpacetimeDB host which is running the remote module.
|
||||
/// Set the URI of the SpacetimeDB host which is running the remote database.
|
||||
///
|
||||
/// The URI must have either no scheme or one of the schemes `http`, `https`, `ws` or `wss`.
|
||||
pub fn with_uri<E: std::fmt::Debug>(mut self, uri: impl TryInto<Uri, Error = E>) -> Self {
|
||||
@@ -991,9 +991,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<String>) -> Self {
|
||||
self.module_name = Some(name_or_identity.into());
|
||||
/// Set the name or identity of the remote database to connect to.
|
||||
pub fn with_database_name(mut self, name_or_identity: impl Into<String>) -> Self {
|
||||
self.database_name = Some(name_or_identity.into());
|
||||
self
|
||||
}
|
||||
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -81,7 +81,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);
|
||||
|
||||
@@ -395,7 +395,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);
|
||||
@@ -1764,7 +1764,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()
|
||||
@@ -1798,7 +1798,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()
|
||||
@@ -1817,7 +1817,7 @@ fn exec_reconnect_different_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 |_, _, _| {
|
||||
@@ -1845,7 +1845,7 @@ fn exec_reconnect_different_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, _, _| {
|
||||
|
||||
@@ -56,7 +56,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);
|
||||
|
||||
+2
-2
@@ -45,7 +45,7 @@ void AChatClientActor::BeginPlay()
|
||||
// Build the connection using the fluent builder API
|
||||
Conn = UDbConnection::Builder()
|
||||
->WithUri(Host) // Host address to connect to
|
||||
->WithModuleName(DbName) // Database/module name
|
||||
->WithDatabaseName(DbName) // Database/module name
|
||||
->WithToken(SavedToken) // Optional authentication token
|
||||
->WithCompression(ESpacetimeDBCompression::Gzip) // Enable gzip compression
|
||||
->OnConnect(ConnectDelegate) // Bind connect handler
|
||||
@@ -450,4 +450,4 @@ void AChatClientActor::LogAndDisplayMessage(const FString& Message, const FColor
|
||||
{
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, Color, Message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -400,9 +400,9 @@ UDbConnectionBuilder* UDbConnectionBuilder::WithUri(const FString& InUri)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithUriBase(InUri));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithModuleName(const FString& InName)
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithDatabaseName(const FString& InName)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithModuleNameBase(InName));
|
||||
return Cast<UDbConnectionBuilder>(WithDatabaseNameBase(InName));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithToken(const FString& InToken)
|
||||
{
|
||||
|
||||
+1
-1
@@ -751,7 +751,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithUri(const FString& InUri);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithModuleName(const FString& InName);
|
||||
UDbConnectionBuilder* WithDatabaseName(const FString& InName);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithToken(const FString& InToken);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
|
||||
+2
-2
@@ -24,11 +24,11 @@ UDbConnectionBuilderBase* UDbConnectionBuilderBase::WithUriBase(const FString& I
|
||||
}
|
||||
|
||||
|
||||
UDbConnectionBuilderBase* UDbConnectionBuilderBase::WithModuleNameBase(const FString& InName)
|
||||
UDbConnectionBuilderBase* UDbConnectionBuilderBase::WithDatabaseNameBase(const FString& InName)
|
||||
{
|
||||
if (InName.IsEmpty())
|
||||
{
|
||||
UE_LOG(LogSpacetimeDb_Connection, Warning, TEXT("WithModuleNameBase called with empty module name, not allowd"));
|
||||
UE_LOG(LogSpacetimeDb_Connection, Warning, TEXT("WithDatabaseNameBase called with empty module name, not allowd"));
|
||||
}
|
||||
ModuleName = InName;
|
||||
return this;
|
||||
|
||||
+1
-1
@@ -17,7 +17,7 @@ public:
|
||||
UDbConnectionBuilderBase* WithUriBase(const FString& InUri);
|
||||
|
||||
/** Set the remote module/database name. */
|
||||
UDbConnectionBuilderBase* WithModuleNameBase(const FString& InName);
|
||||
UDbConnectionBuilderBase* WithDatabaseNameBase(const FString& InName);
|
||||
|
||||
/** Provide an authentication token if available. */
|
||||
UDbConnectionBuilderBase* WithTokenBase(const FString& InToken);
|
||||
|
||||
+2
-2
@@ -12535,9 +12535,9 @@ UDbConnectionBuilder* UDbConnectionBuilder::WithUri(const FString& InUri)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithUriBase(InUri));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithModuleName(const FString& InName)
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithDatabaseName(const FString& InName)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithModuleNameBase(InName));
|
||||
return Cast<UDbConnectionBuilder>(WithDatabaseNameBase(InName));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithToken(const FString& InToken)
|
||||
{
|
||||
|
||||
+2
-2
@@ -117,7 +117,7 @@ UDbConnection* ConnectWithThen(TSharedPtr<FTestCounter> Counter,
|
||||
|
||||
UDbConnectionBuilder* Builder = UDbConnection::Builder()
|
||||
->WithUri(TEXT("localhost:3000"))
|
||||
->WithModuleName(DbName)
|
||||
->WithDatabaseName(DbName)
|
||||
->OnConnect(ConnectDelegate)
|
||||
->OnDisconnect(DisconnectDelegate)
|
||||
->OnConnectError(ErrorDelegate);
|
||||
@@ -380,4 +380,4 @@ bool ReportTestResult(FAutomationTestBase& Test, const FString& TestName, TShare
|
||||
}
|
||||
|
||||
return !bHasFailure;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -10822,7 +10822,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithUri(const FString& InUri);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithModuleName(const FString& InName);
|
||||
UDbConnectionBuilder* WithDatabaseName(const FString& InName);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithToken(const FString& InToken);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
|
||||
+2
-2
@@ -603,9 +603,9 @@ UDbConnectionBuilder* UDbConnectionBuilder::WithUri(const FString& InUri)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithUriBase(InUri));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithModuleName(const FString& InName)
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithDatabaseName(const FString& InName)
|
||||
{
|
||||
return Cast<UDbConnectionBuilder>(WithModuleNameBase(InName));
|
||||
return Cast<UDbConnectionBuilder>(WithDatabaseNameBase(InName));
|
||||
}
|
||||
UDbConnectionBuilder* UDbConnectionBuilder::WithToken(const FString& InToken)
|
||||
{
|
||||
|
||||
+2
-2
@@ -117,7 +117,7 @@ UDbConnection* ConnectWithThen(TSharedPtr<FTestCounter> Counter,
|
||||
|
||||
UDbConnectionBuilder* Builder = UDbConnection::Builder()
|
||||
->WithUri(TEXT("localhost:3000"))
|
||||
->WithModuleName(DbName)
|
||||
->WithDatabaseName(DbName)
|
||||
->OnConnect(ConnectDelegate)
|
||||
->OnDisconnect(DisconnectDelegate)
|
||||
->OnConnectError(ErrorDelegate);
|
||||
@@ -380,4 +380,4 @@ bool ReportTestResult(FAutomationTestBase& Test, const FString& TestName, TShare
|
||||
}
|
||||
|
||||
return !bHasFailure;
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -1172,7 +1172,7 @@ public:
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithUri(const FString& InUri);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithModuleName(const FString& InName);
|
||||
UDbConnectionBuilder* WithDatabaseName(const FString& InName);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
UDbConnectionBuilder* WithToken(const FString& InToken);
|
||||
UFUNCTION(BlueprintCallable, Category = "SpacetimeDB")
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() {
|
||||
|
||||
// Connect to the database
|
||||
let conn = DbConnection::builder()
|
||||
.with_module_name(db_name)
|
||||
.with_database_name(db_name)
|
||||
.with_uri(host)
|
||||
.on_connect(|_, _, _| {
|
||||
println!("Connected to SpacetimeDB");
|
||||
|
||||
@@ -17,7 +17,7 @@ void Main()
|
||||
// Build and connect to the database
|
||||
var conn = DbConnection.Builder()
|
||||
.WithUri(HOST)
|
||||
.WithModuleName(DB_NAME)
|
||||
.WithDatabaseName(DB_NAME)
|
||||
.WithToken(AuthToken.Token)
|
||||
.OnConnect(OnConnected)
|
||||
.OnConnectError(OnConnectError)
|
||||
|
||||
@@ -14,7 +14,7 @@ fn main() {
|
||||
|
||||
// Connect to the database
|
||||
let conn = DbConnection::builder()
|
||||
.with_module_name(db_name)
|
||||
.with_database_name(db_name)
|
||||
.with_uri(host)
|
||||
.on_connect(|_, _, _| {
|
||||
println!("Connected to SpacetimeDB");
|
||||
|
||||
@@ -77,7 +77,7 @@
|
||||
|
||||
const conn = DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(localStorage.getItem('auth_token') || undefined)
|
||||
.onConnect((conn, identity, token) => {
|
||||
localStorage.setItem('auth_token', token);
|
||||
|
||||
@@ -20,7 +20,7 @@ async function main(): Promise<void> {
|
||||
// Build and establish connection
|
||||
DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(token)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
|
||||
@@ -45,7 +45,7 @@ DbConnection ConnectToDB()
|
||||
DbConnection? conn = null;
|
||||
conn = DbConnection.Builder()
|
||||
.WithUri(HOST)
|
||||
.WithModuleName(DB_NAME)
|
||||
.WithDatabaseName(DB_NAME)
|
||||
.WithToken(AuthToken.Token)
|
||||
.OnConnect(OnConnected)
|
||||
.OnConnectError(OnConnectError)
|
||||
|
||||
@@ -47,7 +47,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!
|
||||
|
||||
@@ -9,7 +9,7 @@ describe('App Integration Test', () => {
|
||||
it('connects to the DB, allows name change and message sending', async () => {
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri('ws://localhost:3000')
|
||||
.withModuleName('quickstart-chat')
|
||||
.withDatabaseName('quickstart-chat')
|
||||
.withToken(localStorage.getItem('auth_token') || '');
|
||||
render(
|
||||
<SpacetimeDBProvider connectionBuilder={connectionBuilder}>
|
||||
|
||||
@@ -30,7 +30,7 @@ const onConnectError = (_ctx: ErrorContext, err: Error) => {
|
||||
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(localStorage.getItem('auth_token') || undefined)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
|
||||
@@ -26,7 +26,7 @@ const onConnectError = (_ctx: ErrorContext, err: Error) => {
|
||||
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(localStorage.getItem('auth_token') || undefined)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
|
||||
@@ -25,7 +25,7 @@ const onConnectError = (_ctx: ErrorContext, err: Error) => {
|
||||
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(localStorage.getItem('auth_token') || undefined)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
|
||||
@@ -25,7 +25,7 @@ const onConnectError = (_ctx: ErrorContext, err: Error) => {
|
||||
|
||||
const connectionBuilder = DbConnection.builder()
|
||||
.withUri(HOST)
|
||||
.withModuleName(DB_NAME)
|
||||
.withDatabaseName(DB_NAME)
|
||||
.withToken(localStorage.getItem('auth_token') || undefined)
|
||||
.onConnect(onConnect)
|
||||
.onDisconnect(onDisconnect)
|
||||
|
||||
Reference in New Issue
Block a user