• Start

Methods

update

The update() method for the SurrealDB Swift SDK updates matching records, or a specific record.

Updates matching records of a model's table, or a single record by id.

Method Syntax
try await client.update(Model.self, content: content,
    where: predicate)

Arguments

Description

model

The model type to update, e.g.

Person.self

.

content

The content to write to matching records.

where

A predicate selecting which records to update.

recordID

A SurrealRecordID to update a single record.

// Update matching records
let updated = try await client.update(
    Person.self,
    content: Person(id: nil, name: "Ada", age: 31),
    where: Person.Fields.name == "Ada"
)

// Update a specific record
let id = SurrealRecordID(table: "person", id: .string("ada"))
let record: Person? = try await client.update(
    recordID: id,
    content: Person(id: nil, name: "Ada", age: 31)
)

Was this page helpful?