# upsert

The upsert() method for the SurrealDB Swift SDK creates or updates matching records.

Creates matching records if they do not exist, or updates them if they do.

```swift title="Method Syntax"
try await client.upsert(Model.self, content: content, where: predicate)
```

## Arguments

<table>
    <thead>
        <tr>
            <th colspan="2" scope="col">Arguments</th>
            <th colspan="2" scope="col">Description</th>
        </tr>
    </thead>
    <tbody>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>model</code>
                <label label="required" />
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The model type to upsert, e.g. <code>Person.self</code>.
            </td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>content</code>
                <label label="required" />
            </td>
            <td colspan="2" scope="row" data-label="Description">
                The content to write to matching records.
            </td>
        </tr>
        <tr>
            <td colspan="2" scope="row" data-label="Arguments">
                <code>where</code>
                <label label="optional" />
            </td>
            <td colspan="2" scope="row" data-label="Description">
                A [predicate](/docs/reference/swift/concepts/predicates.md) selecting which records to upsert.
            </td>
        </tr>
    </tbody>
</table>

## Example usage

```swift
let upserted = try await client.upsert(
    Person.self,
    content: Person(id: nil, name: "Ada", age: 31),
    where: Person.Fields.name == "Ada"
)
```
