---
title: "Data manipulation"
description: "Read and write records with select(), create(), update(), upsert() and delete(), by model type with a predicate or by SurrealRecordID, in the Swift SDK."
canonical_url: "https://surrealdb.com/docs/reference/swift/concepts/data-manipulation"
sdk: "Swift SDK"
surrealdb_version: "4.x"
last_modified: "2026-11-24T05:29:47Z"
---

> Full SurrealDB documentation index: https://surrealdb.com/docs/llms.txt

# Data manipulation

Read and write records with select(), create(), update(), upsert() and delete(), by model type with a predicate or by SurrealRecordID, in the Swift SDK.

The Swift SDK has a method for each CRUD operation. Each one takes a [model](/docs/reference/swift/concepts/models.md) type, and the filtering methods accept a [predicate](/docs/reference/swift/concepts/predicates.md) in the `where:` argument. Where a method has a record-targeted overload, it takes a [`SurrealRecordID`](/docs/reference/swift/concepts/value-types.md#surrealrecordid) to act on a single record.

<table>
	<thead>
		<tr>
			<th scope="col">Method</th>
			<th scope="col">Description</th>
		</tr>
	</thead>
	<tbody>
		<tr>
			<td scope="row" data-label="Method"><a href="#select"> <code> client.select(model) </code></a></td>
			<td scope="row" data-label="Description">Selects all records in a table, or a specific record</td>
		</tr>
		<tr>
			<td scope="row" data-label="Method"><a href="#create"> <code> client.create(model) </code></a></td>
			<td scope="row" data-label="Description">Creates a record in the database</td>
		</tr>
		<tr>
			<td scope="row" data-label="Method"><a href="#update"> <code> client.update(model) </code></a></td>
			<td scope="row" data-label="Description">Updates matching records, or a specific record</td>
		</tr>
		<tr>
			<td scope="row" data-label="Method"><a href="#upsert"> <code> client.upsert(model) </code></a></td>
			<td scope="row" data-label="Description">Creates or updates matching records</td>
		</tr>
		<tr>
			<td scope="row" data-label="Method"><a href="#delete"> <code> client.delete(model) </code></a></td>
			<td scope="row" data-label="Description">Deletes matching records, or a specific record</td>
		</tr>
	</tbody>
</table>

## `.select()` {#select}

Selects all records of a model's table, a filtered subset, or a single record by id.

```swift title="Method Syntax"
try await client.select(Model.self, where: predicate, limit: limit, start: start)
```

### Arguments

| Argument | Description |
| --- | --- |
| `model` (required) | The model type to select, for example `Person.self`. |
| `where` (optional) | A predicate restricting which records are returned. |
| `limit` / `start` (optional) | Paginate the results by limiting the count and offsetting the start. |
| `recordID` (optional) | Select a single record by its `SurrealRecordID` instead of a table. |

### Example usage

```swift
// Select all records
let people = try await client.select(Person.self)

// Select a filtered, paginated subset
let adults = try await client.select(
    Person.self,
    where: Person.Fields.age >= 18,
    limit: 20,
    start: 0
)

// Select a single record by id
let id = SurrealRecordID(table: "person", id: .string("ada"))
let person: Person? = try await client.select(recordID: id, as: Person.self)
```

## `.create()` {#create}

Creates a record in the database, either with an auto-generated id or a specific id.

```swift title="Method Syntax"
try await client.create(content)
```

### Arguments

| Argument | Description |
| --- | --- |
| `content` (required) | The model instance to create. The table is derived from the model. |
| `recordID` (optional) | A `SurrealRecordID` to create the record with a specific id. |

### Example usage

```swift
// Create with an auto-generated id
let created: [Person] = try await client.create(Person(id: nil, name: "Ada", age: 30))

// Create with a specific id
let id = SurrealRecordID(table: "person", id: .string("ada"))
let record: Person? = try await client.create(
    recordID: id,
    content: Person(id: nil, name: "Ada", age: 30)
)
```

## `.update()` {#update}

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

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

### Arguments

| Argument | Description |
| --- | --- |
| `model` (required) | The model type to update, for example `Person.self`. |
| `content` (required) | The content to write to matching records. |
| `where` (optional) | A predicate selecting which records to update. |
| `recordID` (optional) | A `SurrealRecordID` to update a single record. |

### Example usage

```swift
// 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)
)
```

## `.upsert()` {#upsert}

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

| Argument | Description |
| --- | --- |
| `model` (required) | The model type to upsert, for example `Person.self`. |
| `content` (required) | The content to write to matching records. |
| `where` (optional) | A predicate selecting which records to upsert. |

### Example usage

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

## `.delete()` {#delete}

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

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

### Arguments

| Argument | Description |
| --- | --- |
| `model` (required) | The model type to delete from, for example `Person.self`. |
| `where` (optional) | A predicate selecting which records to delete. |
| `recordID` (optional) | A `SurrealRecordID` to delete a single record. |

### Example usage

```swift
// Delete matching records
let deleted = try await client.delete(
    Person.self,
    where: Person.Fields.age < 18
)

// Delete a specific record
let id = SurrealRecordID(table: "person", id: .string("ada"))
let record: Person? = try await client.delete(recordID: id, as: Person.self)
```
