### SurrealDB Start Command with Flags Source: https://surrealdb.com/docs/surrealdb/cli/env Example of starting the SurrealDB server using command-line flags for user, password, network access, and function denial. ```bash surreal start --user root --pass root --allow-net --deny-funcs "crypto::md5, http::post, http::delete" ``` -------------------------------- ### Create Records with SurrealQL Source: https://surrealdb.com/docs/surrealdb/introduction/start Demonstrates how to insert data into a SurrealDB table. Includes examples for creating records with auto-generated IDs, explicit custom IDs, and using subqueries to link related data. ```SurrealQL CREATE category SET name = 'Technology', created_at = time::now(); ``` ```SurrealQL CREATE person:john SET name = 'John Doe', age = 30, admin = true, signup_at = time::now(); ``` ```SurrealQL CREATE article SET title = 'SurrealDB is awesome', category = (SELECT id FROM category WHERE name = 'Technology'); ``` -------------------------------- ### Start SurrealDB with Authentication Source: https://surrealdb.com/docs/surrealdb/cli/start Provides an example of starting a SurrealDB instance with user authentication enabled. The provided user credentials will define the initial root user with OWNER privileges. ```bash surreal start --user root -password root ``` -------------------------------- ### Start SurrealDB with Surrealism support Source: https://surrealdb.com/docs/surrealdb/extensions/tutorial Commands to initialize the SurrealDB server and connect via CLI with the necessary experimental flags and bucket allowlists. ```bash SURREAL_CAPS_ALLOW_EXPERIMENTAL=files,surrealism SURREAL_BUCKET_FOLDER_ALLOWLIST="/Users/my_name/my_rust_code/" surreal start --user root --pass secret SURREAL_CAPS_ALLOW_EXPERIMENTAL=files,surrealism SURREAL_BUCKET_FOLDER_ALLOWLIST="/Users/my_name/my_rust_code/" surreal sql --user root --pass secret ``` -------------------------------- ### Install SurrealDB Helm Chart Source: https://surrealdb.com/docs/surrealdb/deployment/kubernetes Installs the SurrealDB Helm chart, configuring it to use the TiKV backend and disabling authentication initially to allow for credential setup. The 'surrealdb.path' is set to the TIKV_URL, and 'surrealdb.unauthenticated' is set to true. ```bash helm install --set surrealdb.path=$TIKV_URL --set surrealdb.unauthenticated=true --set image.tag=latest surrealdb-tikv surrealdb/surrealdb ``` -------------------------------- ### Start SurrealDB with Specific Capabilities Enabled Source: https://surrealdb.com/docs/surrealdb/cli/start Demonstrates starting SurrealDB with fine-grained control over capabilities, starting from a deny-all policy and explicitly allowing specific network access and functions. This enhances security by limiting the server's potential actions. ```bash surreal start --deny-all --allow-funcs "array, string, crypto::argon2, http::get" --allow-net api.example.com:443 ``` -------------------------------- ### SurrealDB Start Command with Environment Variables (PowerShell) Source: https://surrealdb.com/docs/surrealdb/cli/env Illustrates starting the SurrealDB server using environment variables for network capabilities and function denial in a PowerShell environment. ```powershell $env:SURREAL_CAPS_ALLOW_NET $env:SURREAL_CAPS_DENY_FUNC="crypto::md5, http::post, http::delete" surreal start --user root --pass root ``` -------------------------------- ### SurrealDB Allow All Capabilities Example (Bash) Source: https://surrealdb.com/docs/surrealdb/cli/env Shows how to manage the SURREAL_CAPS_ALLOW_ALL environment variable to control network access and scripting capabilities in SurrealDB, with examples for default, false, and true settings. ```bash # Set to default false surreal start # Same, but implicitly shown SURREAL_CAPS_ALLOW_ALL=false surreal start # Set to true SURREAL_CAPS_ALLOW_ALL=true surreal start # Set to true (using flag) surreal start --allow-all ``` -------------------------------- ### SurrealDB Start Command with Environment Variables (Bash) Source: https://surrealdb.com/docs/surrealdb/cli/env Demonstrates starting the SurrealDB server using environment variables for network capabilities and function denial in a Bash environment. ```bash SURREAL_CAPS_ALLOW_NET= SURREAL_CAPS_DENY_FUNC="crypto::md5, http::post, http::delete" surreal start --user root --pass root ``` -------------------------------- ### Start SurrealDB with RocksDB storage Source: https://surrealdb.com/docs/surrealdb/installation/running/rocksdb Initializes a single-node SurrealDB instance using the RocksDB storage engine for on-disk persistence. ```bash surreal start rocksdb://mydatabase.db ``` -------------------------------- ### Start SurrealDB with Memory Datastore Configuration Source: https://surrealdb.com/docs/surrealdb/cli/start Demonstrates starting SurrealDB with a memory-based datastore, including options for versioning, retention, append-only logging (AOL), and snapshotting. These configurations control data durability and recovery mechanisms. ```bash surreal start --user root --pass secret "surrealkv://path/to/db?versioned=true&sync=every&retention=30d" surreal start --user root --pass secret "mem://tmp/data?versioned=true&aol=sync&snapshot=60s&sync=5s" surreal start --user root --pass secret "mem://?versioned=true" ``` -------------------------------- ### Configure SurrealDB Instance with Specific User and Function Restrictions Source: https://surrealdb.com/docs/surrealdb/cli/start An example of starting a SurrealDB instance with a single root user, allowing internet access but denying specific functions like crypto::md5, http::post, and http::delete. ```shell surreal start --user root --pass secret --allow-net --deny-funcs "crypto::md5, http::post, http::delete" ``` -------------------------------- ### Start SurrealDB with RocksDB Datastore Configuration Source: https://surrealdb.com/docs/surrealdb/cli/start Illustrates starting SurrealDB with RocksDB as the persistent storage engine. This configuration is suitable for applications requiring robust key-value storage. ```bash surreal start -u root -p secret rocksdb://mydb ``` -------------------------------- ### Start SurrealDB with RocksDB Storage and Debug Logging Source: https://surrealdb.com/docs/surrealdb/cli/start This command starts a SurrealDB instance using RocksDB as the storage engine and enables debug logging for more verbose output. ```shell surreal start --log debug rocksdb:mydatabase.db ``` -------------------------------- ### Create Record Example (cURL) Source: https://surrealdb.com/docs/surrealdb/integration/http Example using cURL to create a new record in the 'person' table. It demonstrates setting authentication, namespace, database, content type, and sending JSON data for the new record. ```bash curl -X POST -u "root:secret" -H "Surreal-NS: main" -H "Surreal-DB: main" -H "Accept: application/json" -d '{ id: person:one, name: "Billy" }' http://localhost:8000/key/person ``` -------------------------------- ### Verify SurrealDB Installation via CLI Source: https://surrealdb.com/docs/surrealdb/installation/macos Executes the help command to verify that the SurrealDB binary is correctly installed and available in the system path. The command outputs usage information, available subcommands, and version details. ```bash surreal help ``` -------------------------------- ### Start SurrealDB with Custom Bind Address, Logging Level, and Scripting Support Source: https://surrealdb.com/docs/surrealdb/cli/start This configuration starts a SurrealDB instance on a custom network address (0.0.0.0:2218), sets the logging level to 'warn' for less verbose output, and enables JavaScript function execution. ```shell surreal start --bind 0.0.0.0:2218 --log warn --allow-scripting ``` -------------------------------- ### Start SurrealDB Server with Debug Logging Source: https://surrealdb.com/docs/surrealdb/security/troubleshooting Command to start the SurrealDB server with debug-level logging enabled. This is crucial for capturing detailed error information during authentication failures. ```shell surreal start --log debug ``` -------------------------------- ### Bind server to a specific port Source: https://surrealdb.com/docs/surrealdb/installation/running/rocksdb Starts the SurrealDB server on a custom network address and port using the --bind flag. ```bash surreal start --user root --pass secret --bind 0.0.0.0:8080 rocksdb://path/to/mydatabase ``` -------------------------------- ### Start SurrealDB Instance with CLI Source: https://surrealdb.com/docs/surrealdb/cli Starts a SurrealDB instance using the CLI. By default, it runs in-memory and serves at 127.0.0.1:8000 with root credentials 'root' and 'secret'. ```bash surreal start --user root --pass secret ``` -------------------------------- ### Start SurrealDB instance with GraphQL support Source: https://surrealdb.com/docs/surrealdb/querying/graphql/surrealist Starts a local SurrealDB instance with debugging enabled and root credentials. This command is required to enable the GraphQL module before connecting via Surrealist. ```shell surreal start --log debug --user root --password secret ``` -------------------------------- ### Manage Surrealism Modules via CLI Source: https://surrealdb.com/docs/surrealdb/extensions/examples Provides command-line interface examples for interacting with Surrealism modules. These commands allow users to inspect function signatures and execute functions directly from a module file. ```bash # See function signature surreal module sig can_drive demo.surli # Run function with argument surreal module run can_drive --arg 17 demo.surli ``` -------------------------------- ### Initialize Mission Data and Operational Logs Source: https://surrealdb.com/docs/surrealdb/reference-guide/sample-industry-schemas Demonstrates how to instantiate operations, assign units, create tasks, and record time-stamped logs within the system. ```SurrealQL CREATE operation:alpha SET name = "Operation Alpha", commander = person:one, start_time = time::now(); CREATE unit:squad1 SET operation = operation:alpha, name = "squad-1", type = "infantry", status = "deployed", members = [person:one, person:two]; CREATE unit:drone1 SET operation = operation:alpha, name = "drone-1", type = "drone", status = "ready", members = [person:three, person:four]; CREATE task SET operation = operation:alpha, name = "Secure Ridge", objective = "Clear hilltop sector", assigned_to = [unit:squad1], priority = "high"; CREATE log:[unit:squad1, time::now()] SET message = "Entered zone", status = "moving", lonlat = (44.2, 6.3); CREATE log:[unit:squad1, time::now() + 3m] SET message = "Engaged hostiles", status = "engaged", visibility = "clear"; CREATE log:[unit:drone1, time::now()] SET message = "Recon sweep complete", status = "waiting", lonlat = (44.3, 6.2); ``` -------------------------------- ### Deleting Data with DELETE in SurrealDB Source: https://surrealdb.com/docs/surrealdb/introduction/start Details the process of removing records from SurrealDB using the DELETE statement. It covers deleting records by ID or by specific conditions, and includes an example using the RETURN clause to retrieve records before deletion. ```SurrealQL -- Delete a specific record by ID and return it before deletion DELETE person:john RETURN BEFORE WHERE id = 'person:john'; ``` -------------------------------- ### Start SurrealDB Server and Connect via CLI Source: https://surrealdb.com/docs/surrealdb/cli/start Demonstrates how to initialize an in-memory SurrealDB instance using the CLI and subsequently connect to it using the SQL client interface with authentication credentials. ```bash surreal start memory --user my_username --pass my_password ``` ```bash surreal sql --endpoint http://127.0.0.1:8000 --namespace my_namespace --database my_database --username my_username --password my_password ``` -------------------------------- ### Modifying Data with UPDATE and UPSERT in SurrealDB Source: https://surrealdb.com/docs/surrealdb/introduction/start Explains how to update existing records using the UPDATE statement and create or update records using the UPSERT statement in SurrealDB. Examples show updating specific records or multiple records based on conditions. ```SurrealQL -- Example of updating records matching a condition UPDATE person SET age = age + 1 WHERE id = 'person:tobie'; -- Example of UPSERT statement UPSERT INTO person (id, name, age) VALUES ('person:new', 'New Person', 25); ``` -------------------------------- ### Start SurrealDB with SurrealKV Datastore Configuration Source: https://surrealdb.com/docs/surrealdb/cli/start Shows how to initiate a SurrealDB instance using SurrealKV as the storage engine. It covers standard SurrealKV usage and a specific prefix for enabling versioned historical querying. ```bash surreal start -u root -p secret surrealkv://mydb surreal start -u root -p secret surrealkv+versioned://mydb ``` -------------------------------- ### Populate Project Data and Relationships Source: https://surrealdb.com/docs/surrealdb/reference-guide/sample-industry-schemas Demonstrates creating project records, scheduling activities, and establishing graph relationships between tasks and projects. ```SurrealQL CREATE project:one; CREATE activity:one SET name = "Project kickoff", start = time::now(), end = time::now() + 2d, progress = 1.0, project = project:one; CREATE activity:two SET name = "Pour concrete", start = time::now() + 90d, end = time::now() + 100d, progress = 0.0, project = project:one; CREATE activity:three SET name = "Dry concrete", start = time::now() + 100d, end = time::now() + 107d, progress = 0.0, project = project:two; CREATE activity:four SET name = "Build on top of concrete", start = time::now() + 107d, end = time::now() + 150d, progress = 0.0, project = project:two; RELATE activity:two->depends_on->activity:one; RELATE activity:three->depends_on->activity:two; RELATE activity:four->depends_on->activity:three; RELATE [activity:one,activity:two,activity:three, activity:four]->activity_of->project:one; CREATE milestone:one SET project = project:one, activities = [activity:one], name = "Project start"; CREATE milestone:two SET project = project:one, activities = [activity:two, activity:three, activity:four], name = "Initial construction"; ``` -------------------------------- ### Install SurrealDB Helm Chart Source: https://surrealdb.com/docs/surrealdb/deployment/google Installs the SurrealDB Helm chart with TiKV integration enabled, authentication disabled for initial setup, and ingress enabled. It uses the latest SurrealDB Docker image. ```bash helm repo add surrealdb https://helm.surrealdb.com helm repo update helm install \ --set surrealdb.path=$TIKV_URL \ --set surrealdb.auth=false \ --set ingress.enabled=true \ --set image.tag=latest \ surrealdb-tikv surrealdb/surrealdb ``` -------------------------------- ### Install SurrealDB Helm Chart Source: https://surrealdb.com/docs/surrealdb/deployment/azure Deploys the SurrealDB Helm chart with TiKV backend integration and authentication disabled for initial setup. ```bash helm repo add surrealdb https://helm.surrealdb.com helm repo update helm install \ --set surrealdb.path=$TIKV_URL \ --set surrealdb.auth=false \ --set ingress.enabled=false \ --set service.type=LoadBalancer \ --set service.port=80 \ --set service.targetPort=8000 \ --set image.tag=latest \ surrealdb-tikv surrealdb/surrealdb ``` -------------------------------- ### Upgrade SurrealDB with Elevated Permissions (CLI) Source: https://surrealdb.com/docs/surrealdb/cli/upgrade When SurrealDB is installed globally, elevated permissions are often required to perform the upgrade. This example uses 'sudo' for Unix-based systems. Administrator privileges are needed on Windows. ```bash sudo surreal upgrade ``` -------------------------------- ### Querying Data with SELECT in SurrealDB Source: https://surrealdb.com/docs/surrealdb/introduction/start Demonstrates how to retrieve data from SurrealDB using the SELECT statement. It covers selecting all records, records from multiple tables, specific records by ID, and advanced filtering, fetching, and structuring of data. ```SurrealQL -- Select all records from a table SELECT * FROM article; -- Select records from multiple tables SELECT * FROM category, person; -- Selecting specific records SELECT * FROM person:john; -- Advanced query with filtering, fetching, specific fields, and record links SELECT title, author.name.full as author_name FROM article WHERE author.age < 30;" ``` -------------------------------- ### Create SCADA Sensor Data and Trigger Alerts in SurrealDB Source: https://surrealdb.com/docs/surrealdb/reference-guide/sample-industry-schemas Demonstrates creating a 'sensor' record and a 'reading' record with external weather data. It then simulates pressure drops by creating multiple 'reading' records, which triggers the 'alert_from_create' event, and finally shows how to query the generated alerts. ```surrealql -- Create a sensor CREATE sensor:one SET type = ["temperature", "pressure"], location = (50.0, 50.0); -- And a reading for the sensor CREATE reading:[sensor:one, time::now()] SET pressure = 600, -- JSON object sourced from somewhere else, `weather` field is a schemaless object so can be any object format weather = { "temperature": 17.4, "humidity": 52.0, "wind_speed": 12.8 }; -- Some readings with good values FOR $_ IN 0..10 { -- Sleep to keep timestamp in IDs unique, consider a ULID instead if timestamps may not be unique sleep(10ns); CREATE reading:[sensor:one, time::now()] SET pressure = 600; }; -- Pressure has suddenly dropped CREATE reading:[sensor:one, time::now()] SET pressure = 500; -- See the alert SELECT * FROM alert; -- Or use a LIVE SELECT for alerts: https://surrealdb.com/docs/surrealql/statements/live LIVE SELECT * FROM alert; ``` -------------------------------- ### Join Tables in SurrealDB (MongoDB Reference) Source: https://surrealdb.com/docs/surrealdb/models/document Shows how to perform a join operation between two collections in MongoDB using $lookup and its equivalent in SurrealQL, selecting related data. This example joins 'review' with 'person' to get reviewer details. ```MongoDB db.review.aggregate([{ "$lookup": { "from": "person", "localField": "person", "foreignField": "_id", "as": "person_detail" } }]) ``` ```SurrealQL SELECT *, person.name as reviewer FROM review ``` -------------------------------- ### Denying Network Access in SurrealDB Source: https://surrealdb.com/docs/surrealdb/security/capabilities Demonstrates how SurrealDB rejects queries attempting to access network resources when capabilities are not explicitly allowed. This example shows a rejected HTTP GET request and the corresponding server log message, highlighting the security mechanism in place. ```SurrealQL http::get("https://www.surrealdb.com"); ``` ```Log WARN surrealdb_core::ctx::context: Capabilities denied outgoing network connection attempt, target: 'www.surrealdb.com:443' ``` -------------------------------- ### Install Specific SurrealDB Version using Install Script (macOS) Source: https://surrealdb.com/docs/surrealdb/installation/macos Installs a specific version of SurrealDB by passing a version argument to the install script. This allows for controlled deployments or testing of particular releases. ```bash curl -sSf https://install.surrealdb.com | sh -s -- -v ``` -------------------------------- ### Initialize and Query SurrealDB with JavaScript SDK Source: https://surrealdb.com/docs/surrealdb/querying Demonstrates how to import the SurrealDB client, establish a connection to a local instance, and execute a multi-statement query. The example includes TypeScript type definitions for the returned records. ```typescript import { Surreal } from 'surrealdb'; const db = new Surreal('http://localhost:8000'); await db.connect('root', 'root'); type Person = { id: string; name: string; }; // Assign the variable on the connection const result = await db.query<[Person[], Person[]]>( 'CREATE person SET name = "John"; SELECT * FROM type::table($tb);', { tb: 'person' } ); // Get all of the results from the second query const people = result[1].result; ``` -------------------------------- ### Install SurrealDB using Install Script (macOS) Source: https://surrealdb.com/docs/surrealdb/installation/macos Installs the latest version of SurrealDB using a secure script that downloads the executable for your platform and CPU type. It attempts to install to `/usr/local/bin` or a user-specified directory. ```bash curl -sSf https://install.surrealdb.com | sh ``` -------------------------------- ### Configure root user credentials Source: https://surrealdb.com/docs/surrealdb/installation/running/rocksdb Initializes the server with a root-level user and password. These credentials are persisted to the database storage. ```bash surreal start --user root --pass secret rocksdb://mydatabase.db ``` -------------------------------- ### Install or update SurrealDB on Linux Source: https://surrealdb.com/docs/surrealdb/installation/linux Uses the official SurrealDB installation script to download and install the latest version of the database server and CLI tool. The script typically targets /usr/local/bin for the installation path. ```bash curl -sSf https://install.surrealdb.com | sh ``` -------------------------------- ### SurrealDB HTTP & REST API Setup Source: https://surrealdb.com/docs/surrealdb/integration/http Instructions on how to set up a SurrealDB server for HTTP & REST API access, including default addresses and authentication options. ```APIDOC ## Setup The `surreal start` command without any arguments is all that is needed to start a server at the default `http://localhost:8000` address. Many examples below assume the flags `--user root` and `--pass secret` to create a root user with the name `root` and password `secret`. The `--unauthenticated` flag can be used when experimenting to turn off authentication, effectively allowing root access by any and all connections. The local database serving functionality on the Surrealist UI can also be used to start a server. ``` -------------------------------- ### Install a specific version of SurrealDB Source: https://surrealdb.com/docs/surrealdb/installation/linux Allows for the installation of a specific release version by passing the version argument to the installation script using the -v or --version flag. ```bash curl -sSf https://install.surrealdb.com | sh -s -- -v ``` -------------------------------- ### Start SurrealDB Server via Docker or CLI Source: https://surrealdb.com/docs/surrealdb/reference-guide/performance-best-practices Commands to initiate the SurrealDB server with specified log levels and storage engines. Using the rocksdb engine is recommended for persistent data storage. ```bash docker run --rm --pull always -p 8000:8000 surrealdb/surrealdb:latest start --log info rocksdb://path/to/mydatabase ``` ```bash surreal start --log info rocksdb://path/to/mydatabase ``` -------------------------------- ### Install SurrealDB via PowerShell Source: https://surrealdb.com/docs/surrealdb/installation/windows This command uses the official SurrealDB install script to download and install the latest version of the database server and CLI tool to the Windows system. ```PowerShell iwr https://windows.surrealdb.com -useb | iex ``` -------------------------------- ### Install SurrealDB using Homebrew (macOS) Source: https://surrealdb.com/docs/surrealdb/installation/macos Installs SurrealDB on macOS using the Homebrew package manager. This is a quick method that installs both the command-line tools and the server as a single executable. ```bash brew install surrealdb/tap/surreal ``` -------------------------------- ### Install SurrealDB Nightly via PowerShell Source: https://surrealdb.com/docs/surrealdb/installation/nightly Uses an Invoke-Expression command to download and execute the Windows-specific installation script for the nightly build. This installs the binary into the standard Program Files directory. ```powershell iex "& { $(irm https://windows.surrealdb.com) } -Nightly" ``` -------------------------------- ### Create Project and Risk Records in SurrealDB Source: https://surrealdb.com/docs/surrealdb/reference-guide/sample-industry-schemas Demonstrates creating a 'project' record and then adding multiple 'risk' records associated with that project. Each risk record includes details like description, category, likelihood, impact, and start/end dates, showcasing the temporal nature of risk assessment. ```surrealql CREATE project:one; CREATE risk SET project = project:one, description = "Migratory elk", category = "regulatory", likelihood = 0.9, start = d'2025-10-01', end = d'2025-12-15', maximum_impact = 1000000; CREATE risk SET project = project:one, description = "Wildfires", category = "technical", likelihood = 0.5, start = d'2025-06-01', end =d'2025-10-15', maximum_impact = 10000000; SELECT * FROM project; ``` -------------------------------- ### Install and Update SurrealDB via Scoop Source: https://surrealdb.com/docs/surrealdb/installation/windows Commands to install or update the SurrealDB executable using the Scoop package manager on Windows. ```powershell scoop install surrealdb scoop update surrealdb ``` -------------------------------- ### Install and Update SurrealDB via Chocolatey Source: https://surrealdb.com/docs/surrealdb/installation/windows Commands to install or update the SurrealDB executable using the Chocolatey package manager on Windows. ```powershell choco install surreal choco update surreal ``` -------------------------------- ### Create Astronomical Observation Records Source: https://surrealdb.com/docs/surrealdb/reference-guide/sample-industry-schemas Demonstrates the instantiation of telescope and target records, followed by the creation of a relationship record representing an observation session with specific metadata. ```SurrealQL CREATE telescope:one SET name = "The one telescope", location = (-68.44, -29.14), aperture_mm = 200; CREATE target:venus SET type = "planet", name = "Venus"; CREATE person:one; RELATE telescope:one->observed->target:venus SET observer = person:one, observed_at = time::now(), observed_until = time::now() + 1h, filter = "R", seeing = 0.7, sky_conditions = "clear", data_url = "https://astro.example.org/data/venus-2025.fits"; ``` -------------------------------- ### Update SurrealDB via CLI Source: https://surrealdb.com/docs/surrealdb/installation/windows This command checks for and installs the latest stable version of SurrealDB, ensuring the local installation remains up to date. ```Shell surreal upgrade ``` -------------------------------- ### Install SurrealDB Nightly via Shell Script Source: https://surrealdb.com/docs/surrealdb/installation/nightly Uses a secure curl-based install script to download and install the latest nightly build for macOS and Linux systems. The script automatically detects the platform and CPU architecture to place the binary in the appropriate directory. ```bash curl --proto '=https' --tlsv1.2 -sSf https://install.surrealdb.com | sh -s -- --nightly ``` -------------------------------- ### Execute SQL Query with Basic Auth (v1.x) Source: https://surrealdb.com/docs/surrealdb/integration/http Illustrates executing a SQL query using basic authentication with username and password. This example uses shorthand headers for namespace and database, and passes the query and parameter via the request body and URL. ```curl curl -X POST -u "root:secret" -H "ns: main" -H "db: main" -H "Accept: application/json" \ -d 'SELECT * FROM person WHERE age > $age' http://localhost:8000/sql?age=18 ``` -------------------------------- ### Upsert Example Source: https://surrealdb.com/docs/surrealdb/integration/rpc Example of how to use the upsert method to insert or update a record in SurrealDB. ```APIDOC ## POST /api/upsert ### Description This endpoint demonstrates the 'upsert' method for inserting or updating records. ### Method POST ### Endpoint /api ### Parameters #### Request Body - **id** (integer) - Required - Unique identifier for the request. - **method** (string) - Required - The method to be called, in this case, 'upsert'. - **params** (array) - Required - An array containing the parameters for the upsert operation. The first element is the record ID, and the second is the record data. - **recordId** (string) - Required - The ID of the record to upsert. - **recordData** (object) - Required - The data for the record. - **name** (string) - Optional - The name of the person. - **job** (string) - Optional - The job title of the person. ### Request Example ```json { "id": 1, "method": "upsert", "params": [ "person:12s0j0bbm3ngrd5c9bx53", { "name": "John Doe", "job": "Software developer" } ] } ``` ### Response #### Success Response (200) - **id** (integer) - The identifier for the request. - **result** (object) - The result of the operation. - **id** (string) - The ID of the upserted record. - **name** (string) - The name of the person. - **job** (string) - The job title of the person. #### Response Example ```json { "id": 1, "result": { "id": "person:12s0j0bbm3ngrd5c9bx53", "name": "John Doe", "job": "Software developer" } } ``` ``` -------------------------------- ### Example SurrealQL Queries in CLI Source: https://surrealdb.com/docs/surrealdb/cli Demonstrates basic SurrealQL queries executed within the interactive SurrealDB CLI shell, including creating records and selecting data based on a condition. ```surrealql main/main> CREATE person SET age = 20; main/main> CREATE person SET age = 30; main/main> SELECT * FROM person WHERE age > 25; ``` -------------------------------- ### Register users with signup Source: https://surrealdb.com/docs/surrealdb/integration/rpc Registers a new user using a defined record access method. Requires namespace, database, and access method parameters. ```json { "id": 1, "method": "signup", "params": [ { "NS": "surrealdb", "DB": "docs", "AC": "commenter", "username": "johndoe", "password": "SuperStrongPassword!" } ] } ``` -------------------------------- ### Initiate Live Query Source: https://surrealdb.com/docs/surrealdb/integration/rpc Starts a live query for a specified table, returning a UUID. Notifications for changes are sent to the connection. ```json { "id": 1, "method": "live", "params": [ "person" ] } ``` -------------------------------- ### Install TiDB Operator CRDS Source: https://surrealdb.com/docs/surrealdb/deployment/kubernetes Installs the Custom Resource Definitions (CRDS) required for the TiDB Operator. This is a prerequisite for deploying the operator itself. ```bash kubectl create -f https://raw.githubusercontent.com/pingcap/tidb-operator/v1.4.5/manifests/crd.yaml ```