Set parameters
Within your application, you can define parameters that can be used to store and retrieve data from SurrealDB. Parameters are used to store data in a structured format, and can be used to store data in a key-value pair format.
Parameters allow you to define global (database-wide) parameters that are available to every client.
.Set()
Assigns a value as a parameter for this connection.
Method Syntax
await db.Set(key, val)
Arguments
| Arguments | Description |
|---|
key required | Specifies the name of the variable. |
value required | Assigns the value to the variable name. |
cancellationToken optional | The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
await db.Set("name", new Name { FirstName = "Tobie", LastName = "Morgan Hitchcock" });
await db.Query($"CREATE person SET name = $name");
await db.Query($"SELECT * FROM person WHERE name.first_name = $name.first_name");
.Unset()
Removes a parameter for this connection.
Method Syntax
await db.Unset(key)
Arguments
| Arguments | Description |
|---|
key required | Specifies the SurrealQL statements. |
cancellationToken optional | The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
await db.Unset("name");