mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
#147: Rename DatabaseCursor.step() into next
This commit is contained in:
1 parent
20a7c550fe
commit
b0db219aeb
6 files changed
+15
-12
No files matched your search
@@ -163,7 +163,7 @@ public extension DatabaseValueConvertible {
|
||||
/// - returns: An optional value.
|
||||
public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Self? {
|
||||
let cursor = try! DatabaseValue.fetchCursor(statement, arguments: arguments, adapter: adapter)
|
||||
return try! cursor.step().flatMap { Self.fromDatabaseValue($0) }
|
||||
return try! cursor.next().flatMap { Self.fromDatabaseValue($0) }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -573,7 +573,7 @@ extension Row {
|
||||
/// - returns: An optional row.
|
||||
public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Row? {
|
||||
let cursor = try! fetchCursor(statement, arguments: arguments, adapter: adapter)
|
||||
return try! cursor.step().flatMap { $0.copy() }
|
||||
return try! cursor.next().flatMap { $0.copy() }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -311,10 +311,10 @@ public final class DatabaseCursor<Element> {
|
||||
/// exists. Once nil has been returned, all subsequent calls return nil.
|
||||
///
|
||||
/// let cursor = try Row.fetchCursor(db, "SELECT ...")
|
||||
/// while let row = try cursor.step() {
|
||||
/// while let row = try cursor.next() {
|
||||
/// print(row)
|
||||
/// }
|
||||
public func step() throws -> Element? {
|
||||
public func next() throws -> Element? {
|
||||
if done {
|
||||
return nil
|
||||
}
|
||||
@@ -337,7 +337,7 @@ extension DatabaseCursor {
|
||||
public func enumerated() -> DatabaseCursor<(Int, Element)> {
|
||||
var i = 0
|
||||
return DatabaseCursor<(Int, Element)>(statement: statementRef.takeUnretainedValue()) {
|
||||
guard let element = try self.step() else { return nil }
|
||||
guard let element = try self.next() else { return nil }
|
||||
defer { i = i + 1 }
|
||||
return (i, element)
|
||||
}
|
||||
@@ -346,7 +346,7 @@ extension DatabaseCursor {
|
||||
/// TODO
|
||||
public func filter(_ isIncluded: (Element) throws -> Bool) throws -> [Element] {
|
||||
var result: [Element] = []
|
||||
while let element = try step() {
|
||||
while let element = try next() {
|
||||
if try isIncluded(element) {
|
||||
result.append(element)
|
||||
}
|
||||
@@ -356,7 +356,7 @@ extension DatabaseCursor {
|
||||
|
||||
/// TODO
|
||||
public func forEach(_ body: (Element) throws -> Void) throws {
|
||||
while let element = try step() {
|
||||
while let element = try next() {
|
||||
try body(element)
|
||||
}
|
||||
}
|
||||
@@ -364,7 +364,7 @@ extension DatabaseCursor {
|
||||
/// TODO
|
||||
public func map<T>(_ transform: (Element) throws -> T) throws -> [T] {
|
||||
var result: [T] = []
|
||||
while let element = try step() {
|
||||
while let element = try next() {
|
||||
try result.append(transform(element))
|
||||
}
|
||||
return result
|
||||
@@ -373,7 +373,7 @@ extension DatabaseCursor {
|
||||
/// TODO
|
||||
public func reduce<Result>(_ initialResult: Result, _ nextPartialResult: (Result, Element) throws -> Result) throws -> Result {
|
||||
var result = initialResult
|
||||
while let element = try step() {
|
||||
while let element = try next() {
|
||||
result = try nextPartialResult(result, element)
|
||||
}
|
||||
return result
|
||||
@@ -392,7 +392,7 @@ public final class DatabaseIterator<Element>: IteratorProtocol {
|
||||
/// Advances to the next element and returns it, or `nil` if no next element
|
||||
/// exists. Once nil has been returned, all subsequent calls return nil.
|
||||
public func next() -> Element? {
|
||||
return try! cursor?.step()
|
||||
return try! cursor?.next()
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -139,7 +139,7 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
}
|
||||
return Self.init(sqliteStatement: sqliteStatement, index: columnIndex)
|
||||
}
|
||||
return try! cursor.step() ?? nil
|
||||
return try! cursor.next() ?? nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-1
@@ -133,7 +133,7 @@
|
||||
|
||||
static func api(_ db: Database) -> UnsafePointer<fts5_api>? {
|
||||
do {
|
||||
return try Data.fetchCursor(db, "SELECT fts5()").step().flatMap { data in
|
||||
return try Data.fetchCursor(db, "SELECT fts5()").next().flatMap { data in
|
||||
guard data.count == MemoryLayout<UnsafePointer<fts5_api>>.size else {
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -1,3 +1,6 @@
|
||||
- DatabaseCursor: consider making Persistable.exists() throwable
|
||||
- DatabaseCursor/FetchedRecordsController: handle fetch errors
|
||||
- DatabaseCursor/FetchedRecordsController: along throwable fetchAlongside closure
|
||||
- [ ] Swift 3.0.2 (Xcode 8.2): "Type inference will properly unwrap optionals when used with generics and implicitly-unwrapped optionals." Maybe this fixes `row.value(named: "foo") as? Int`?
|
||||
- [ ] Refactor Database notion of transaction/savepoints into a single type. Support INSERT OR ROLLBACK.
|
||||
- Since some statements may implicitly rollback transactions, we can not rely on explicit rollback statements to infer the transaction state. We can only rely on sqlite3_rollback_hook, assuming it is called even for implicit rollbacks (test with an INSERT OR ROLLBACK statement).
|
||||
|
||||
Reference in new issue
Block a user