Skip to content

Commit 322940f

Browse files
committed
Document next() method
1 parent 3f524e9 commit 322940f

File tree

2 files changed

+18
-5
lines changed

2 files changed

+18
-5
lines changed

Sources/SwiftSQL/SQLStatement.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,19 @@ public final class SQLStatement {
6666

6767
#warning("TODO: add example")
6868

69-
/// Executes the statement and returns `true` if the next row is available.
70-
/// Returns `false` if the statement is finished executing and no more data
69+
/// Executes the statement and returns the row (`SQLRow`) if it is available.
70+
/// Returns nil if the statement is finished executing and no more data
7171
/// is available. Throws an error if an error is encountered.
72+
///
73+
///
74+
/// let statement = try db.statement("SELECT Name, Level FROM Users ORDER BY Level ASC")
75+
///
76+
/// var objects = [User]()
77+
/// while let row = try statement.next() {
78+
/// let user = User(name: row[0], level: row[1])
79+
/// objects.append(user)
80+
/// }
81+
///
7282
public func next() throws -> SQLRow? {
7383
guard try isOK(sqlite3_step(ref)) == SQLITE_ROW else {
7484
return nil

Tests/SwiftSQLTests/SQLStatementTests.swift

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,9 @@ final class SQLStatementTests: XCTestCase {
225225
XCTAssertEqual(row[1], "Alex")
226226
}
227227

228-
// MARK: Query
228+
// MARK: Next
229229

230-
func testQuery() throws {
230+
func testNext() throws {
231231
// GIVEN
232232
try db.createTables()
233233
try db.populateStore()
@@ -246,7 +246,10 @@ final class SQLStatementTests: XCTestCase {
246246
}
247247

248248
// THEN
249-
XCTAssertEqual(objects, [User(name: "Alice", level: 80), User(name: "Bob", level: 90)])
249+
XCTAssertEqual(objects, [
250+
User(name: "Alice", level: 80),
251+
User(name: "Bob", level: 90)
252+
])
250253
}
251254
}
252255

0 commit comments

Comments
 (0)