The methods below are used to interact with the database and perform CRUD operations. You can also use the query method to run SurrealQL statements against the database.
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 |
.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);