UpsertPromise<T, I, J>
The UpsertPromise class provides a chainable interface for configuring UPSERT operations (insert if not exists, replace if exists). It extends Promise, allowing you to await it directly or chain configuration methods.
Warning
Returned by: SurrealQueryable.upsert()
Source: query/upsert.ts
Type Parameters
T- The result typeI- The input type for record dataJ- Boolean indicating if result is JSON (default:false)
Configuration Methods
.content()
Set the complete content for the record (insert or replace).
Parameters
| Parameter | Type | Description |
|---|---|---|
data | Values<I> | Complete record data (excluding id field). |
Returns
UpsertPromise<T, I, J> - Chainable promise
Example
.merge()
Merge data into the record (insert if not exists, merge if exists).
Parameters
| Parameter | Type | Description |
|---|---|---|
data | Partial<Values<I>> | Partial data to merge. |
Returns
UpsertPromise<T, I, J> - Chainable promise
Example
.replace()
Replace specific fields.
Parameters
| Parameter | Type | Description |
|---|---|---|
data | Values<I> | Fields to replace. |
Returns
UpsertPromise<T, I, J> - Chainable promise
.patch()
Apply JSON Patch operations.
Parameters
| Parameter | Type | Description |
|---|---|---|
operations | PatchOperation[] | JSON Patch operations. |
Returns
UpsertPromise<T, I, J> - Chainable promise
.where()
Add a WHERE clause for conditional upsert.
Parameters
| Parameter | Type | Description |
|---|---|---|
condition | ExprLike | The condition expression (string or Expression object). |
Returns
UpsertPromise<T, I, J> - Chainable promise
.output()
Specify what to return.
Parameters
| Parameter | Type | Description |
|---|---|---|
fields | Output | "NONE", "BEFORE", "AFTER", "DIFF", or field list. |
Returns
UpsertPromise<T, I, J> - Chainable promise
.timeout()
Set operation timeout.
Returns
UpsertPromise<T, I, J> - Chainable promise
.version(), .json(), .stream()
See other query builders for these common methods.
Complete Examples
Basic Upsert
Upsert with Merge
Bulk Upsert
Track Changes
Conditional Upsert
UPSERT vs CREATE vs UPDATE
Use Cases
Session Management
Cache Pattern
Counter Pattern
Chaining Pattern
See Also
SurrealQueryable.upsert() - Method that returns UpsertPromise
CreatePromise - Create only
UpdatePromise - Update only
Query Overview - All query builder classes