### Install Project Dependencies Source: https://docs.ditto.live/sdk/latest/quickstarts/react-native Commands to install necessary project dependencies using various package managers. ```shell yarn install ``` ```shell npm install ``` ```shell pnpm install ``` -------------------------------- ### Install .NET MAUI Workloads Source: https://docs.ditto.live/sdk/latest/quickstarts/dotnet-maui Commands to install and restore the necessary .NET MAUI workloads required for building Ditto applications. ```shell sudo dotnet workload install maui sudo dotnet workload restore ``` -------------------------------- ### Install Dependencies (Shell) Source: https://docs.ditto.live/sdk/latest/quickstarts/javascript-web Installs the necessary Node.js dependencies for the JavaScript web application. This command should be run from the 'javascript-web' directory within the project. ```shell npm install ``` -------------------------------- ### Initialize and Run Flutter Application Source: https://docs.ditto.live/sdk/latest/quickstarts/flutter Commands to navigate to the project directory, install dependencies defined in pubspec.yaml, and launch the application on a target device. ```shell cd flutter_app flutter pub get flutter run ``` -------------------------------- ### Run Java Server Application Source: https://docs.ditto.live/sdk/v5-java-server/quickstarts/java-server Command to start the Java Spring application using the Gradle wrapper. ```shell ./gradlew bootRun ``` -------------------------------- ### Run JavaScript Web Application (Shell) Source: https://docs.ditto.live/sdk/latest/quickstarts/javascript-web Starts the JavaScript web application. This command compiles and runs the application, making it accessible in your browser. Error output is redirected to /dev/null. ```shell npm start 2>/dev/null ``` -------------------------------- ### Server Connection Setup (C#) Source: https://docs.ditto.live/sdk/latest/ditto-config Initializes a server connection for Ditto using C#, specifying the endpoint URL and database ID. This setup includes configuring an authentication expiration handler to ensure continuous connectivity by re-authenticating when the token expires. The synchronization process is then started. ```csharp // Your HTTP Cloud URL Endpoint var endpoint = "REPLACE_ME_WITH_YOUR_URL"; var id = "REPLACE_ME_WITH_YOUR_DATABASE_ID"; var config = new DittoConfig( ``` -------------------------------- ### Clone and Navigate Repository Source: https://docs.ditto.live/sdk/latest/quickstarts/cpp-console Commands to clone the Ditto quickstart repository from GitHub and navigate into the project directory. ```shell git clone https://github.com/getditto/quickstart cd quickstart ``` -------------------------------- ### Server Connection Setup (Swift) Source: https://docs.ditto.live/sdk/latest/ditto-config Establishes a server connection for Ditto, configuring the database ID and server URL. It includes setting up an authentication expiration handler to re-authenticate when the token is nearing expiration, using either the development provider or a custom one. The sync process is then started. ```swift // Your HTTP Cloud URL Endpoint let config = DittoConfig( databaseID: "REPLACE_ME_WITH_YOUR_DATABASE_ID", // This was "appID" in v4 connect: .server(url: URL(string: "REPLACE_ME_WITH_YOUR_URL")), // This was "Custom Auth URL" in v4 ) let ditto = try await Ditto.open(config: config) // Set up authentication expiration handler (required for server connections) ditto.auth?.expirationHandler = { [weak self] ditto, secondsRemaining in // Authenticate when token is expiring ditto.auth?.login( // Your development token, replace with your actual token token: "REPLACE_ME_WITH_YOUR_DEVELOPMENT_TOKEN", // Use .development or your actual provider name provider: .development ) { clientInfo, error in if let error = error { print("Authentication failed: (error)") } else { print("Authentication successful") } } } try ditto.sync.start() ``` -------------------------------- ### Clone Ditto Quickstart Repository Source: https://docs.ditto.live/sdk/latest/quickstarts/dotnet-console Clones the Ditto quickstart repository from GitHub using Git. This is the first step to setting up the application. ```shell git clone https://github.com/getditto/quickstart ``` -------------------------------- ### Build and Run Rust Project Source: https://docs.ditto.live/sdk/latest/install-guides/rust Builds and runs the Rust project using Cargo. This command compiles the code and executes the resulting binary. It also handles the initial download and installation of the specified Rust toolchain if it's not already present. ```none $ cargo run info: syncing channel updates ... Finished dev [unoptimized + debuginfo] target(s) in 0.05s Running `target/debug/my_project_name` Hello, world! ``` -------------------------------- ### Clone Ditto Quickstart Repository (Shell) Source: https://docs.ditto.live/sdk/latest/quickstarts/flutter Clones the Ditto Quickstart repository from GitHub. Use the 'flutter-web-preview' branch for web development. This is the first step in setting up the project. ```shell git clone https://github.com/getditto/quickstart ``` ```shell git clone --branch flutter-web-preview https://github.com/getditto/quickstart.git ``` -------------------------------- ### Floating Action Button to Trigger Data Insertion (Dart) Source: https://docs.ditto.live/sdk/latest/install-guides/flutter An example of a Flutter FloatingActionButton that, when pressed, calls the `insertData` function to add a new item to the Ditto store. ```dart FloatingActionButton( onPressed: insertData, child: Icon(Icons.add), ) ``` -------------------------------- ### Start Development Server Source: https://docs.ditto.live/sdk/latest/install-guides/react-native Commands to start the development environment using various package managers. Choose the command corresponding to your preferred tool. ```bash yarn start ``` ```bash npm start ``` ```bash pnpm start ``` -------------------------------- ### Initialize Ditto Singleton in Application Class Source: https://docs.ditto.live/sdk/latest/install-guides/kotlin Shows how to initialize the Ditto instance as a singleton within the Android Application's onCreate method. It includes configuring identity, transport settings, and starting the synchronization process. ```kotlin try { val androidDependencies = DefaultAndroidDittoDependencies(applicationContext) val identity = DittoIdentity.OnlinePlayground( dependencies = androidDependencies, appId = "REPLACE_ME_WITH_YOUR_APP_ID", token = "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN", customAuthUrl = "REPLACE_ME_WITH_YOUR_AUTH_URL", enableDittoCloudSync = false ) ditto = Ditto(androidDependencies, identity) ditto?.updateTransportConfig { config -> config.connect.websocketUrls.add("REPLACE_ME_WITH_YOUR_WEBSOCKET_URL") } ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false") ditto.startSync() } catch (e: DittoError) { Log.e("Ditto error", e.message!!) } ``` -------------------------------- ### Configure Ditto Credentials Source: https://docs.ditto.live/sdk/latest/quickstarts/cpp-console Commands to initialize the environment configuration file and set the required Ditto connection parameters. ```shell cp .env.sample .env DITTO_APP_ID="REPLACE_ME_WITH_YOUR_APP_ID" DITTO_PLAYGROUND_TOKEN="REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN" DITTO_AUTH_URL="REPLACE_ME_WITH_YOUR_AUTH_URL" DITTO_WEBSOCKET_URL="REPLACE_ME_WITH_YOUR_WEBSOCKET_URL" ``` -------------------------------- ### Build and Run Application Source: https://docs.ditto.live/sdk/latest/quickstarts/cpp-console Commands to compile the C++ application using Make and execute the resulting binary. ```shell cd .. make build ./build/taskscpp ``` -------------------------------- ### Verify Rust Installation Source: https://docs.ditto.live/sdk/latest/install-guides/rust Checks if the Rust compiler (rustc) and package manager (cargo) are installed and accessible in the current shell environment. Essential for confirming a successful Rust setup. ```bash rustc --version cargo --version ``` -------------------------------- ### Initialize Ditto with Custom Configuration Source: https://docs.ditto.live/sdk/latest/ditto-config Demonstrates how to initialize a Ditto instance by modifying a default configuration or creating a new one. These examples show how to set the database ID and server connection URL across various supported platforms. ```Swift let defaultConfig = DittoConfig.default defaultConfig.databaseID = "38d4b612-e6ea-42f2-ae3e-f4cba92c918d" defaultConfig.connect = .server(url: URL(string: "https://my-server.ditto.live")!) let ditto = try await Ditto.open(config: defaultConfig) ``` ```JavaScript const defaultConfig = DittoConfig.default; const customConfig = new DittoConfig( "38d4b612-e6ea-42f2-ae3e-f4cba92c918d", { type: 'server', url: 'https://my-server.ditto.live' }, defaultConfig.persistenceDirectory ); const ditto = await Ditto.open(customConfig); ``` ```Kotlin val config = DittoAndroidConfig( context, databaseId = "38d4b612-e6ea-42f2-ae3e-f4cba92c918d", connect = DittoConfigConnect.Server( url = URI.create("https://my-server.ditto.live") ) ) val ditto = Ditto.open(config) ``` ```Java DittoAndroidConfig config = new DittoAndroidConfig( context, "38d4b612-e6ea-42f2-ae3e-f4cba92c918d", new DittoConfigConnect.Server( URI.create("https://my-server.ditto.live") ) ); Ditto ditto = Ditto.open(config); ``` ```C# var defaultConfig = DittoConfig.Default; var customConfig = new DittoConfig( databaseId: "38d4b612-e6ea-42f2-ae3e-f4cba92c918d", connect: new DittoConfigConnect.Server( new Uri("https://my-server.ditto.live") ), persistenceDirectory: defaultConfig.PersistenceDirectory ); var ditto = await Ditto.OpenAsync(customConfig); ``` ```C++ auto customConfig = DittoConfig::default_config() .set_database_id("38d4b612-e6ea-42f2-ae3e-f4cba92c918d") .set_connect(DittoConfig::Connect::server( "https://my-server.ditto.live" )); auto ditto = Ditto::open(customConfig); ``` ```Rust let custom_config = DittoConfig::new( "38d4b612-e6ea-42f2-ae3e-f4cba92c918d", DittoConfigConnect::Server { url: "https://my-server.ditto.live".parse().unwrap(), }, ); let ditto = Ditto::open_sync(custom_config)?; ``` ```Go config := ditto.DefaultDittoConfig(). WithDatabaseID("38d4b612-e6ea-42f2-ae3e-f4cba92c918d"). WithConnect(&ditto.DittoConfigConnectServer{URL: "https://my-server.ditto.live"}) ``` -------------------------------- ### Initialize and Open Ditto SDK (Dart) Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Initializes the Ditto SDK and opens a connection using provided credentials. It configures transport settings, disables DQL strict mode, and starts data synchronization. Ensure to replace placeholder values with your actual credentials. ```dart await Ditto.init(); final identity = OnlinePlaygroundIdentity( appId: "REPLACE_ME_WITH_YOUR_APP_ID", token: "REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN", customAuthUrl: "REPLACE_ME_WITH_YOUR_AUTH_URL", enableDittoCloudSync: false // This is required to be set to false to use the correct URLs ); final ditto = await Ditto.open(identity); ditto.updateTransportConfig((config) { // Set the Ditto Websocket URL config.connect.webSocketUrls.add("wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL"); }); // Disable DQL strict mode so that collection definitions are not required in DQL queries await ditto.store.execute("ALTER SYSTEM SET DQL_STRICT_MODE = false"); ditto.startSync(); ``` -------------------------------- ### Navigate to Project Directory Source: https://docs.ditto.live/sdk/latest/quickstarts/dotnet-console Navigates into the cloned quickstart project directory. This command is used after cloning the repository. ```shell cd quickstart ``` -------------------------------- ### Download and Unpack Ditto SDK Source: https://docs.ditto.live/sdk/latest/quickstarts/cpp-console Commands to download the Ditto SDK archive for specific architectures and extract the necessary library files. ```shell cd cpp-tui/taskscpp/sdk # For x86_64 curl -O https://software.ditto.live/cpp-linux-x86_64/Ditto/4.12.0/dist/Ditto.tar.gz && tar xvfz Ditto.tar.gz # For aarch64 curl -O https://software.ditto.live/cpp-linux-aarch64/Ditto/4.12.0/dist/Ditto.tar.gz && tar xvfz Ditto.tar.gz ``` -------------------------------- ### Add Ditto and Permission Handler Dependencies Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Installs the 'ditto_live' and 'permission_handler' packages using the Flutter package manager. These are essential for utilizing Ditto's real-time synchronization and managing device permissions. ```shell flutter pub add ditto_live flutter pub add permission_handler ``` -------------------------------- ### Initialize and Configure Ditto Client in Go Source: https://docs.ditto.live/sdk/latest/install-guides/go Demonstrates how to import the package, configure the connection with database credentials, and start the synchronization process. ```go import "github.com/getditto/ditto-go-sdk/v5/ditto" const endpoint = "REPLACE_ME_WITH_YOUR_URL" const id = "REPLACE_ME_WITH_YOUR_DATABASE_ID" const token = "REPLACE_ME_WITH_YOUR_DEVELOPMENT_TOKEN" config := ditto.DefaultDittoConfig(). WithDatabaseID(id). WithConnect(&ditto.DittoConfigConnectServer{URL: endpoint}) dit, err := ditto.Open(config) if err != nil { log.Fatalf("error: failed to open Ditto: %v", err) } defer dit.Close() // Set up authentication expiration handler (required for server connections) dit.Auth().SetExpirationHandler( func(d *ditto.Ditto, timeUntilExpiration time.Duration) { _, err := d.Auth().Login(token, ditto.DevelopmentAuthenticationProvider()) if err != nil { log.Errorf("Authentication failed: %v", err) } else { log.Printf("Authentication succeeded") } }) if err := dit.Sync().Start(); err != nil { log.Errorf("error: failed to start sync: %v", err) } ``` -------------------------------- ### Clone and Navigate Repository Source: https://docs.ditto.live/sdk/latest/quickstarts/react-native Commands to download the Ditto quickstart repository from GitHub and navigate into the specific React Native project directory. ```shell git clone https://github.com/getditto/quickstart cd quickstart/react-native ``` -------------------------------- ### Import Ditto SDK (Dart) Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Imports the Ditto SDK library into your Dart file, making its functionalities available for use in your application. ```dart import 'package:ditto_live/ditto_live.dart'; ``` -------------------------------- ### DQL Inline Comment Example Source: https://docs.ditto.live/dql/ids-paths-strings-keywords Shows the syntax for single-line comments in DQL. Inline comments start with a double dash (--). ```sql -- This is an inline comment ``` -------------------------------- ### Configure Ditto Environment Variables Source: https://docs.ditto.live/sdk/v5-java-server/quickstarts/java-server Instructions for setting up the .env file with required Ditto credentials including Database ID, Development Token, and connection URLs. ```shell cp .env.sample .env ``` ```java DITTO_DATABASE_ID=YOUR_DB_ID DITTO_DEVELOPMENT_TOKEN=YOUR_DEV_TOKEN DITTO_AUTH_URL=https://YOUR_AUTH_URL DITTO_WEBSOCKET_URL=wss://YOUR_AUTH_URL ``` -------------------------------- ### Copy and Configure .env File Source: https://docs.ditto.live/sdk/latest/quickstarts/dotnet-console Copies the sample environment file to .env and updates it with Ditto credentials like App ID, Playground Token, Auth URL, and Websocket URL. ```shell cp .env.sample .env DITTO_APP_ID="REPLACE_ME_WITH_YOUR_APP_ID" DITTO_PLAYGROUND_TOKEN="REPLACE_ME_WITH_YOUR_PLAYGROUND_TOKEN" DITTO_AUTH_URL="REPLACE_ME_WITH_YOUR_AUTH_URL" DITTO_WEBSOCKET_URL="REPLACE_ME_WITH_YOUR_WEBSOCKET_URL" ``` -------------------------------- ### Manage Data Synchronization in Ditto Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Shows how to enable synchronization on a device and register a subscription to keep specific collection data in sync with the Ditto cloud. ```dart ditto.startSync(); void syncData() { ditto.sync.registerSubscription("SELECT * FROM items"); } ``` -------------------------------- ### Configure and Start Sync with Scopes (Java) Source: https://docs.ditto.live/sdk/v5-java-server/sync/sync-scopes Provides a Java code example for setting user collection sync scopes and starting the Ditto sync process. It demonstrates using a HashMap to define scopes and executing the ALTER SYSTEM command. Crucially, this must be called before startSync() to prevent unintended data syncing. ```java Map syncScopes = new HashMap<>(); newCar.put("local_mesh_orders", "SmallPeersOnly"); ditto.getStore().execute( "ALTER SYSTEM SET USER_COLLECTION_SYNC_SCOPES = :syncScopes", Collections.singletonMap("syncScopes", syncScopes)); try { ditto.startSync(); } catch(DittoError e) { // handle error } ``` -------------------------------- ### Ditto Persistence Directory Configuration Examples (Multi-language) Source: https://docs.ditto.live/sdk/latest/ditto-config Provides examples of configuring the Ditto persistence directory using absolute paths, relative paths, and the default nil/undefined option across Swift, JavaScript, Kotlin, Java, and C#. This showcases how to manage data storage locations for different platforms. ```swift // Absolute path let config1 = DittoConfig( databaseID: "f232511c-256b-4b69-8d28-90283bf715d2", connect: .smallPeersOnly(), persistenceDirectory: URL(string: "/Users/me/DittoData")! ) // Relative path let config2 = DittoConfig( databaseID: "f232511c-256b-4b69-8d28-90283bf715d2", connect: .smallPeersOnly(), persistenceDirectory: URL(string: "MyApp/Data")! ) // Default (nil) - NEW: includes database ID let config3 = DittoConfig( databaseID: "f232511c-256b-4b69-8d28-90283bf715d2", connect: .smallPeersOnly(), persistenceDirectory: nil // Will use "ditto-f232511c-256b-4b69-8d28-90283bf715d2" as default directory ) ``` ```javascript // Absolute path const config1 = new DittoConfig( "f232511c-256b-4b69-8d28-90283bf715d2", { type: 'smallPeersOnly' }, "/Users/me/DittoData" ); // Relative path const config2 = new DittoConfig( "f232511c-256b-4b69-8d28-90283bf715d2", { type: 'smallPeersOnly' }, "MyApp/Data" ); // Default (undefined) - NEW: includes database ID const config3 = new DittoConfig( "f232511c-256b-4b69-8d28-90283bf715d2", { type: 'smallPeersOnly' } // Will use "ditto-f232511c-256b-4b69-8d28-90283bf715d2" as default directory ); ``` ```kotlin // Absolute path val config1 = DittoAndroidConfig( context, databaseId = "f232511c-256b-4b69-8d28-90283bf715d2", connect = DittoConfigConnect.SmallPeersOnly(), persistenceDirectory = "/data/data/com.myapp/DittoData" ) // Relative path val config2 = DittoAndroidConfig( context, databaseId = "f232511c-256b-4b69-8d28-90283bf715d2", connect = DittoConfigConnect.SmallPeersOnly(), persistenceDirectory = "MyApp/Data" ) // Default (null) - NEW: includes database ID val config3 = DittoAndroidConfig( context, databaseId = "f232511c-256b-4b69-8d28-90283bf715d2", connect = DittoConfigConnect.SmallPeersOnly() // Will use "ditto-f232511c-256b-4b69-8d28-90283bf715d2" as default directory ) ``` ```java // Absolute path DittoAndroidConfig config1 = new DittoAndroidConfig( context, "f232511c-256b-4b69-8d28-90283bf715d2", new DittoConfigConnect.SmallPeersOnly(), "/data/data/com.myapp/DittoData" ); // Relative path DittoAndroidConfig config2 = new DittoAndroidConfig( context, "f232511c-256b-4b69-8d28-90283bf715d2", new DittoConfigConnect.SmallPeersOnly(), "MyApp/Data" ); // Default (null) - NEW: includes database ID DittoAndroidConfig config3 = new DittoAndroidConfig( context, "f232511c-256b-4b69-8d28-90283bf715d2", new DittoConfigConnect.SmallPeersOnly() // Will use "ditto-f232511c-256b-4b69-8d28-90283bf715d2" as default directory ); ``` ```csharp // Absolute path var config1 = new DittoConfig( databaseId: "f232511c-256b-4b69-8d28-90283bf715d2", connect: new DittoConfigConnect.SmallPeersOnly(), persistenceDirectory: "/Users/me/DittoData" ); // Relative path var config2 = new DittoConfig( databaseId: "f232511c-256b-4b69-8d28-90283bf715d2", connect: new DittoConfigConnect.SmallPeersOnly(), persistenceDirectory: "MyApp/Data" ); // Default (null) - NEW: includes database ID var config3 = new DittoConfig( databaseId: "f232511c-256b-4b69-8d28-90283bf715d2", connect: new DittoConfigConnect.SmallPeersOnly() // Will use "ditto-f232511c-256b-4b69-8d28-90283bf715d2" as default directory ); ``` -------------------------------- ### Observe Data Store Changes in Flutter Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Demonstrates how to register an observer for a specific SQL query, integrate it into a widget's lifecycle, and properly dispose of it to prevent memory leaks. ```dart void observeData() { final observer = ditto.store.registerObserver( "SELECT * FROM items", onChange: (event) { print("data changed"); }, ); } @override void initState() { super.initState(); observeData(); } @override void dispose() { _observer.cancel(); super.dispose(); } ``` -------------------------------- ### Clone Repository Instructions (JavaScript) Source: https://docs.ditto.live/sdk/latest/quickstarts/javascript-web A React component that provides instructions for cloning the Ditto quickstart repository using the terminal. It includes the git clone command and navigating into the project directory. ```javascript export const QuickstartCloneTheRepoBody = () =>
  1. Open the terminal
  2. Clone the repository from GitHub.
                        
                            git clone https://github.com/getditto/quickstart
                        
                    
  3. Navigate to the project directory:
                        
                            cd quickstart
                        
                    
; ``` -------------------------------- ### Configure Foreground Service Notification (Android) Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Defines metadata for the foreground service notification displayed to the user. Ensure the 'small_app_icon' drawable is monochrome white. This configuration is part of the AndroidManifest.xml. ```xml ``` -------------------------------- ### Serialize Document for Insertion: Swift Source: https://docs.ditto.live/dql/legacy-to-dql-adoption Provides an example of serializing a Swift dictionary into JSON data before inserting it into the database using DQL. This is required as DQL does not support built-in serialization like Codable. ```swift let doc = ["_id": UUID().uuidString, "inStock": 0.0, "name": "fries"] let jsonData = try JSONEncoder().encode(doc) let jsonString = String(data: jsonData, encoding: .utf8) await ditto.store.execute( query: "INSERT INTO items DOCUMENTS (:jsonString) ON ID CONFLICT DO UPDATE", arguments: ["jsonString": jsonString] ) ``` -------------------------------- ### Configure Ditto for Web Environments Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Provides instructions for initializing Ditto on the web by specifying custom CDN URLs for WebAssembly assets and configuring transport settings to disable peer-to-peer sync. ```dart await Ditto.init( wasmUrl: 'https://your-cdn.com/ditto-assets/ditto.wasm', wasmShimUrl: 'https://your-cdn.com/ditto-assets/', ); final ditto = await Ditto.init( wasmUrl: 'https://your-cdn.com/ditto-assets/ditto.wasm', wasmShimUrl: 'https://your-cdn.com/ditto-assets/', ); final connect = Connect(webSocketUrls: {"wss://REPLACE_ME_WITH_YOUR_WEBSOCKET_URL"}); if (!kIsWeb) { final peerToPeer = PeerToPeer.all(); } ditto.transportConfig = TransportConfig(peerToPeer: peerToPeer, connect: connect); ditto.startSync(); ``` -------------------------------- ### Create DQL Indexes and Analyze Query Plans Source: https://docs.ditto.live/sdk/latest/release-notes/flutter Demonstrates how to optimize query performance by creating indexes on specific fields and using the EXPLAIN statement to verify that the query engine utilizes union scans for OR conditions. ```sql CREATE INDEX movies_runtime ON movies (runtime) CREATE INDEX movies_year ON movies (_id.year) EXPLAIN SELECT * FROM movies WHERE runtime > 200 OR _id.year = 2000 ``` ```json { "plan": { "#operator": "sequence", "children": [ { "#operator": "unionScan", "children": [ { "#operator": "indexScan", "collection": "movies", "datasource": "default", "desc": { "index": "movies_runtime", "spans": [ { "index_key": { "direction": "asc", "include_missing": true, "key": ["runtime"] }, "range": { "low": { "included": false, "value": 200 } } } ] } }, { "#operator": "indexScan", "collection": "movies", "datasource": "default", "desc": { "index": "movies_year", "spans": [ { "index_key": { "direction": "asc", "include_missing": true, "key": ["_id", "year"] }, "range": { "high": { "included": true, "value": 2000 }, "low": { "included": true, "value": 2000 } } } ] } } ] } ] } } ``` -------------------------------- ### Insert Data into Ditto Store (Dart) Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Demonstrates how to insert a new document into a collection named 'items' within the Ditto store using an SQL-like query. This function can be triggered by user interactions. ```dart Future insertData() async { final item = {'name': 'Sample Item', 'value': 100}; await ditto.store.execute( "INSERT INTO items VALUES (:item)", arguments: {"item": item}, ); } ``` -------------------------------- ### Build and Run MAUI Application Source: https://docs.ditto.live/sdk/latest/quickstarts/dotnet-maui Platform-specific commands to build and execute the Ditto MAUI tasks application for Android, iOS, Mac Catalyst, and Windows. ```shell cd dotnet-maui/DittoMauiTasksApp # Android dotnet build -t:Run -f net9.0-android # iOS dotnet build -t:Run -f net9.0-ios # Mac Catalyst dotnet build -t:Run -f net9.0-maccatalyst # Windows dotnet build -t:Run -f net9.0-windows10.0.19041.0 ``` -------------------------------- ### Create DQL Indexes and Execute Union Scan Query Source: https://docs.ditto.live/sdk/latest/release-notes/js Demonstrates how to define indexes on specific fields and execute a query using an OR condition that triggers a union scan. The EXPLAIN command is used to verify that the query optimizer is utilizing the created indexes. ```sql CREATE INDEX movies_runtime ON movies (runtime) CREATE INDEX movies_year ON movies (_id.year) EXPLAIN SELECT * FROM movies WHERE runtime > 200 OR _id.year = 2000 ``` -------------------------------- ### Request Device Permissions (Dart) Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Requests necessary Bluetooth and Wi-Fi permissions for Android and iOS platforms using the 'permission_handler' package. It utilizes Ditto.currentPlatform to ensure compatibility across different environments. ```dart import "package:ditto_live/ditto_live.dart"; import "package:permission_handler/permission_handler.dart"; // ... final platform = Ditto.currentPlatform; if (platform case SupportedPlatform.android || SupportedPlatform.iOS) { await [ Permission.bluetoothConnect, Permission.bluetoothAdvertise, Permission.nearbyWifiDevices, Permission.bluetoothScan ].request(); } ``` -------------------------------- ### macOS Entitlements for Ditto Network Access Source: https://docs.ditto.live/sdk/latest/install-guides/flutter Grants network client and server entitlements in 'DebugProfile.entitlements' and 'Release.entitlements' for macOS. These are crucial for Ditto to establish connections to Ditto Cloud and perform peer-to-peer synchronization. ```xml com.apple.security.network.client com.apple.security.network.server ```