The methods below run SurrealQL statements against the database, call a SurrealQL function, and keep variables on the connection that later queries can use. To read and write records with a method for each operation, see data manipulation.
Method | Description |
|---|---|
db.Query() | Runs a set of SurrealQL statements against the database |
db.RawQuery() | Runs a set of SurrealQL statements against the database, based on a raw SurrealQL query |
db.Run() | Runs a SurrealQL function |
db.Set(key, value) | Assigns a value as a parameter for this connection |
db.Unset(key) | Removes a parameter for this connection |
.Query()
Runs a set of SurrealQL statements against the database.
await db.Query(sql)Arguments
Arguments | Description |
|---|---|
sql | Specifies the SurrealQL statements. |
cancellationToken | The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
// Execute query with params
const string table = "person";
var result = await db.Query(
$"CREATE person; SELECT * FROM type::table({table});"
);
// Get the first result from the first query
var created = result.GetValue<Person>(0);
// Get all of the results from the second query
var people = result.GetValue<List<Person>>(1); .RawQuery()
Runs a set of SurrealQL statements against the database, based on a raw SurrealQL query.
await db.RawQuery(sql, params)Arguments
Arguments | Description |
|---|---|
sql | Specifies the SurrealQL statements. |
params | Assigns variables which can be used in the query. |
cancellationToken | The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
// Assign the variable on the connection
var @params = new Dictionary<string, object> { { "table",
"person" } };
var result = await db.RawQuery(
"CREATE person; SELECT * FROM type::table($table);",
@params
);
// Get the first result from the first query
var created = result.GetValue<Person>(0);
// Get all of the results from the second query
var people = result.GetValue<List<Person>>(1); .Run()
Runs a SurrealQL function.
await db.Run(name, version, args)Arguments
Arguments | Description |
|---|---|
name | The name of the SurrealQL function. |
version | The version of the SurrealQL function. |
args | The arguments used by the SurrealQL function. |
cancellationToken | The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
DateTime now = await db.Run<DateTime>("time::now");
string result = await db.Run<string>("string::repeat", ["test", 3]); .Set()
Assigns a value as a parameter for this connection.
await db.Set(key, val)Arguments
Arguments | Description |
|---|---|
key | Specifies the name of the variable. |
value | Assigns the value to the variable name. |
cancellationToken | The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
// Assign the variable on the connection
await db.Set("name", new Name { FirstName = "Tobie",
LastName = "Morgan Hitchcock" });
// Use the variable in a subsequent query
await db.Query($"CREATE person SET name = $name");
// Use the variable in a subsequent query
await db.Query(
$"SELECT * FROM person WHERE name.first_name = $name.first_name"
); .Unset()
Removes a parameter for this connection.
await db.Unset(key)Arguments
Arguments | Description |
|---|---|
key | Specifies the SurrealQL statements. |
cancellationToken | The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
await db.Unset("name");