-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDatabaseRowSequenceSQLite.swift
More file actions
55 lines (48 loc) · 1.53 KB
/
DatabaseRowSequenceSQLite.swift
File metadata and controls
55 lines (48 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
//
// DatabaseRowSequenceSQLite.swift
// feather-database-sqlite
//
// Created by Tibor Bödecs on 2026. 01. 10.
//
import FeatherDatabase
import SQLiteNIO
/// A query result backed by SQLite rows.
///
/// Use this type to iterate or collect SQLite query results.
public struct DatabaseRowSequenceSQLite: DatabaseRowSequence {
public typealias Row = DatabaseRowSQLite
let elements: [Row]
/// An async iterator over SQLite rows.
///
/// This iterator traverses the in-memory row list.
public struct Iterator: AsyncIteratorProtocol {
var index = 0
let elements: [Row]
/// Return the next row in the sequence.
///
/// This returns `nil` after the last row.
/// - Returns: The next `SQLiteRow`, or `nil` when finished.
public mutating func next() async -> Row? {
guard index < elements.count else {
return nil
}
defer { index += 1 }
return elements[index]
}
}
/// Create an async iterator over the result rows.
///
/// Use this to iterate the result as an `AsyncSequence`.
/// - Returns: An iterator over the result rows.
public func makeAsyncIterator() -> Iterator {
Iterator(elements: elements)
}
/// Collect all rows into an array.
///
/// This returns the rows held by the result.
/// - Throws: An error if collection fails.
/// - Returns: An array of `SQLiteRow` values.
public func collect() async throws -> [Row] {
elements
}
}