Data Manipulation
SurrealDB supports a number of methods for interacting with the database and performing CRUD operations.
| Method | Description |
|---|---|
db.Select() | Selects all records in a table, or a specific record, from the database |
db.Create() | Creates a record in the database |
db.Insert() | Inserts one or multiple records in the database |
db.InsertRelation() | Inserts one or multiple relations in the database |
db.Update() | Updates all records in a table, or a specific record, in the database |
db.Upsert() | Creates or updates a set of records in a table, or a specific record, in the database |
db.Merge() | Modifies all records in a table, or a specific record, in the database |
db.Patch() | Applies JSON Patch changes to all records, or a specific record, in the database |
db.Delete() | Deletes all records in a table, or a specific record, from the database |
.Select<T>()
Selects all records in a table, or a specific record, from the database.
Arguments
| Arguments | Description |
|---|---|
thing
|
The table name or a RecordId to select.
|
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.Create<T>()
Creates a record in the database.
Arguments
| Arguments | Description |
|---|---|
thing
|
The table name or a RecordId to create.
|
data
| The document / record data to insert. |
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.Insert<T>()
Inserts one or multiple records in the database.
Arguments
| Arguments | Description |
|---|---|
table
| Optionally pass along a table to insert into. |
data
| Either a single document/record or an array of documents/records to insert |
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.InsertRelation<T>()
Inserts one or multiple relations in the database.
Arguments
| Arguments | Description |
|---|---|
table
| Optionally pass along a table to insert into. |
data
| Either a single document/record or an array of documents/records to insert |
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.Update<T>()
Updates all records in a table, or a specific record, in the database.
Note
Arguments
| Arguments | Description |
|---|---|
thing
|
The table name or the specific RecordId to update.
|
data
| The document / record data to update. |
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.Upsert<T>()
Creates or updates a specific record.
Note
Arguments
| Arguments | Description |
|---|---|
data
| The document / record data to insert. |
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.Merge<T>()
Modifies all records in a table, or a specific record.
Note
Arguments
| Arguments | Description |
|---|---|
thing
|
The table name or the specific RecordId to merge.
|
data
| The data with which to modify the records. |
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.Patch<T>()
Applies JSON Patch changes to all records, or a specific record, in the database.
Note
Arguments
| Arguments | Description |
|---|---|
thing
|
The table name or the specific RecordId to patch.
|
data
| The JSON Patch data with which to patch the records. |
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |
Example usage
.Delete()
Deletes all records in a table, or a specific record, from the database.
Arguments
| Arguments | Description |
|---|---|
thing
|
The table name or a RecordId to delete.
|
cancellationToken
| The cancellationToken enables graceful cancellation of asynchronous operations. |