diff --git a/DESIGN.md b/DESIGN.md index dcc0e2b76..91e7ea5a8 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -68,17 +68,17 @@ Well, GRDB provides three fetching methods for each fetchable type: ```swift // Row -Row.fetch(db, "SELECT ...", arguments: ...) // AnySequence +Row.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence Row.fetchAll(db, "SELECT ...", arguments: ...) // [Row] Row.fetchOne(db, "SELECT ...", arguments: ...) // Row? // DatabaseValueConvertible -String.fetch(db, "SELECT ...", arguments: ...) // AnySequence +String.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence String.fetchAll(db, "SELECT ...", arguments: ...) // [String?] String.fetchOne(db, "SELECT ...", arguments: ...) // String? // Record (via RowConvertible) -Person.fetch(db, "SELECT ...", arguments: ...) // AnySequence +Person.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence Person.fetchAll(db, "SELECT ...", arguments: ...) // [Person] Person.fetchOne(db, "SELECT ...", arguments: ...) // Person? ``` diff --git a/GRDB/Core/Protocols/DatabaseValueConvertible.swift b/GRDB/Core/Protocols/DatabaseValueConvertible.swift index 319fcabc3..c26c91842 100644 --- a/GRDB/Core/Protocols/DatabaseValueConvertible.swift +++ b/GRDB/Core/Protocols/DatabaseValueConvertible.swift @@ -7,12 +7,12 @@ values. The protocol comes with built-in methods that allow to fetch lazy sequences, arrays, or single instances: - String.fetch(db, "SELECT name FROM ...", arguments:...) // AnySequence + String.fetch(db, "SELECT name FROM ...", arguments:...) // DatabaseSequence String.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String?] String.fetchOne(db, "SELECT name FROM ...", arguments:...) // String? let statement = db.selectStatement("SELECT name FROM ...") - String.fetch(statement, arguments:...) // AnySequence + String.fetch(statement, arguments:...) // DatabaseSequence String.fetchAll(statement, arguments:...) // [String?] String.fetchOne(statement, arguments:...) // String? @@ -41,12 +41,12 @@ values. The protocol comes with built-in methods that allow to fetch lazy sequences, arrays, or single instances: - String.fetch(db, "SELECT name FROM ...", arguments:...) // AnySequence + String.fetch(db, "SELECT name FROM ...", arguments:...) // DatabaseSequence String.fetchAll(db, "SELECT name FROM ...", arguments:...) // [String?] String.fetchOne(db, "SELECT name FROM ...", arguments:...) // String? let statement = db.selectStatement("SELECT name FROM ...") - String.fetch(statement, arguments:...) // AnySequence + String.fetch(statement, arguments:...) // DatabaseSequence String.fetchAll(statement, arguments:...) // [String?] String.fetchOne(statement, arguments:...) // String? @@ -61,7 +61,7 @@ public extension DatabaseValueConvertible { Fetches a lazy sequence of DatabaseValueConvertible values. let statement = db.selectStatement("SELECT name FROM ...") - let names = String.fetch(statement) // AnySequence + let names = String.fetch(statement) // DatabaseSequence The returned sequence can be consumed several times, but it may yield different results, should database changes have occurred between two @@ -79,7 +79,7 @@ public extension DatabaseValueConvertible { - parameter arguments: Optional statement arguments. - returns: A lazy sequence of values. */ - public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> AnySequence { + public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence { return statement.fetch(arguments: arguments) { Self.fromDatabaseValue(statement.databaseValue(atIndex: 0)) } @@ -89,7 +89,7 @@ public extension DatabaseValueConvertible { // Fetches a lazy sequence of DatabaseValueConvertible values. // // let statement = db.selectStatement("SELECT name FROM ...") -// let names = String.fetch(statement) // AnySequence +// let names = String.fetch(statement) // DatabaseSequence // // The returned sequence can be consumed several times, but it may yield // different results, should database changes have occurred between two @@ -107,7 +107,7 @@ public extension DatabaseValueConvertible { // - parameter arguments: Optional statement arguments. // - returns: A lazy sequence of values. // */ -// public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> AnySequence { +// public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence { // return AnySequence { // statement.generate(arguments: arguments) { // statement.databaseValue(atIndex: 0).value() @@ -152,7 +152,7 @@ public extension DatabaseValueConvertible { /** Fetches a lazy sequence of DatabaseValueConvertible values. - let names = String.fetch(db, "SELECT name FROM ...") // AnySequence + let names = String.fetch(db, "SELECT name FROM ...") // DatabaseSequence The returned sequence can be consumed several times, but it may yield different results, should database changes have occurred between two @@ -171,14 +171,14 @@ public extension DatabaseValueConvertible { - parameter arguments: Optional statement arguments. - returns: A lazy sequence of values. */ - public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence { + public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence { return fetch(db.selectStatement(sql), arguments: arguments) } // /** // Fetches a lazy sequence of DatabaseValueConvertible values. // -// let names = String.fetch(db, "SELECT name FROM ...") // AnySequence +// let names = String.fetch(db, "SELECT name FROM ...") // DatabaseSequence // // The returned sequence can be consumed several times, but it may yield // different results, should database changes have occurred between two @@ -197,7 +197,7 @@ public extension DatabaseValueConvertible { // - parameter arguments: Optional statement arguments. // - returns: A lazy sequence of values. // */ -// public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence { +// public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence { // return self.fetch(db.selectStatement(sql), arguments: arguments) // } @@ -236,7 +236,7 @@ public extension DatabaseValueConvertible where Self: MetalType { Fetches a lazy sequence of DatabaseValueConvertible values. let statement = db.selectStatement("SELECT name FROM ...") - let names = String.fetch(statement) // AnySequence + let names = String.fetch(statement) // DatabaseSequence The returned sequence can be consumed several times, but it may yield different results, should database changes have occurred between two @@ -254,7 +254,7 @@ public extension DatabaseValueConvertible where Self: MetalType { - parameter arguments: Optional statement arguments. - returns: A lazy sequence of values. */ - public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> AnySequence { + public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence { return statement.fetch(arguments: arguments) { let sqliteStatement = statement.sqliteStatement if sqlite3_column_type(sqliteStatement, 0) == SQLITE_NULL { @@ -302,7 +302,7 @@ public extension DatabaseValueConvertible where Self: MetalType { /** Fetches a lazy sequence of DatabaseValueConvertible values. - let names = String.fetch(db, "SELECT name FROM ...") // AnySequence + let names = String.fetch(db, "SELECT name FROM ...") // DatabaseSequence The returned sequence can be consumed several times, but it may yield different results, should database changes have occurred between two @@ -321,7 +321,7 @@ public extension DatabaseValueConvertible where Self: MetalType { - parameter arguments: Optional statement arguments. - returns: A lazy sequence of values. */ - public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence { + public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence { return fetch(db.selectStatement(sql), arguments: arguments) } diff --git a/GRDB/Core/Protocols/RowConvertible.swift b/GRDB/Core/Protocols/RowConvertible.swift index c75b39b1b..881b62982 100644 --- a/GRDB/Core/Protocols/RowConvertible.swift +++ b/GRDB/Core/Protocols/RowConvertible.swift @@ -7,12 +7,12 @@ Types that adopt RowConvertible can be initialized from a database Row. The protocol comes with built-in methods that allow to fetch lazy sequences, arrays, or single instances: - Person.fetch(db, "SELECT ...", arguments:...) // AnySequence + Person.fetch(db, "SELECT ...", arguments:...) // DatabaseSequence Person.fetchAll(db, "SELECT ...", arguments:...) // [Person] Person.fetchOne(db, "SELECT ...", arguments:...) // Person? let statement = db.selectStatement("SELECT ...") - Person.fetch(statement, arguments:...) // AnySequence + Person.fetch(statement, arguments:...) // DatabaseSequence Person.fetchAll(statement, arguments:...) // [Person] Person.fetchOne(statement, arguments:...) // Person? @@ -42,7 +42,7 @@ extension RowConvertible { Fetches a lazy sequence. let statement = db.selectStatement("SELECT * FROM persons") - let persons = Person.fetch(statement) // AnySequence + let persons = Person.fetch(statement) // DatabaseSequence The returned sequence can be consumed several times, but it may yield different results, should database changes have occurred between two @@ -60,9 +60,10 @@ extension RowConvertible { - parameter arguments: Optional statement arguments. - returns: A lazy sequence. */ - public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> AnySequence { + public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence { + // Metal rows can be reused. And reusing them yields better performance. + let row = Row(metalStatement: statement) return statement.fetch(arguments: arguments) { - let row = Row(metalStatement: statement) let value = Self.init(row: row) value.awakeFromFetch(row) return value @@ -72,7 +73,7 @@ extension RowConvertible { // Fetches a lazy sequence. // // let statement = db.selectStatement("SELECT * FROM persons") -// let persons = Person.fetch(statement) // AnySequence +// let persons = Person.fetch(statement) // DatabaseSequence // // The returned sequence can be consumed several times, but it may yield // different results, should database changes have occurred between two @@ -90,7 +91,7 @@ extension RowConvertible { // - parameter arguments: Optional statement arguments. // - returns: A lazy sequence. // */ -// public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> AnySequence { +// public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence { // return AnySequence { // statement.generate(arguments: arguments) { // let row = Row(statement: statement) @@ -138,7 +139,7 @@ extension RowConvertible { /** Fetches a lazy sequence. - let persons = Person.fetch(db, "SELECT * FROM persons") // AnySequence + let persons = Person.fetch(db, "SELECT * FROM persons") // DatabaseSequence The returned sequence can be consumed several times, but it may yield different results, should database changes have occurred between two @@ -157,14 +158,14 @@ extension RowConvertible { - parameter arguments: Optional statement arguments. - returns: A lazy sequence. */ - public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence { + public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence { return fetch(db.selectStatement(sql), arguments: arguments) } // /** // Fetches a lazy sequence. // -// let persons = Person.fetch(db, "SELECT * FROM persons") // AnySequence +// let persons = Person.fetch(db, "SELECT * FROM persons") // DatabaseSequence // // The returned sequence can be consumed several times, but it may yield // different results, should database changes have occurred between two @@ -183,7 +184,7 @@ extension RowConvertible { // - parameter arguments: Optional statement arguments. // - returns: A lazy sequence. // */ -// public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence { +// public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence { // return fetch(db.selectStatement(sql), arguments: arguments) // } diff --git a/GRDB/Core/Row.swift b/GRDB/Core/Row.swift index 44abd078d..c1b3d0f95 100644 --- a/GRDB/Core/Row.swift +++ b/GRDB/Core/Row.swift @@ -1,8 +1,12 @@ /** -A row is the result of a database query. +A database row. */ -public struct Row: CollectionType { - +public class Row: CollectionType { + // IMPLEMENTATION NOTE: + // + // Row is a class so that we can reuse a single instance when iterating a + // SelectStatement. This avoids a lot of Swift boilerplate, and improves + // performances. // MARK: - Building rows @@ -16,6 +20,7 @@ public struct Row: CollectionType { for (key, value) in dictionary { databaseDictionary[key] = value?.databaseValue ?? .Null } + self.sqliteStatement = nil self.impl = DictionaryRowImpl(databaseDictionary: databaseDictionary) } @@ -100,7 +105,7 @@ public struct Row: CollectionType { } public func value>(atIndex index: Int) -> Value? { - let sqliteStatement = impl.sqliteStatement + let sqliteStatement = self.sqliteStatement // accessing it through impl takes 69% of the time spent here, and only 16% through self. guard sqliteStatement != nil else { return Value.fromDatabaseValue(impl.databaseValue(atIndex: index)) } @@ -118,7 +123,7 @@ public struct Row: CollectionType { } public func value>(atIndex index: Int) -> Value { - let sqliteStatement = impl.sqliteStatement + let sqliteStatement = self.sqliteStatement guard sqliteStatement != nil else { return Value.fromDatabaseValue(impl.databaseValue(atIndex: index))! } @@ -310,10 +315,10 @@ public struct Row: CollectionType { - parameter arguments: Optional statement arguments. - returns: A lazy sequence of rows. */ - public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> AnySequence { - return statement.fetch(arguments: arguments) { - Row(metalStatement: statement) - } + public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence { + // Metal rows can be reused. And reusing them yields better performance. + let row = Row(metalStatement: statement) + return statement.fetch(arguments: arguments) { row } } // /** @@ -338,7 +343,7 @@ public struct Row: CollectionType { // - parameter arguments: Optional statement arguments. // - returns: A lazy sequence of rows. // */ -// public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> AnySequence { +// public static func fetch(statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence { // return AnySequence { // statement.generate(arguments: arguments) { // Row(statement: statement) @@ -406,7 +411,7 @@ public struct Row: CollectionType { - parameter arguments: Optional statement arguments. - returns: A lazy sequence of rows. */ - public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence { + public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence { return fetch(db.selectStatement(sql), arguments: arguments) } @@ -432,7 +437,7 @@ public struct Row: CollectionType { // - parameter arguments: Optional statement arguments. // - returns: A lazy sequence of rows. // */ -// public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> AnySequence { +// public static func fetch(db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence { // return fetch(db.selectStatement(sql), arguments: arguments) // } @@ -468,6 +473,7 @@ public struct Row: CollectionType { // MARK: - Not Public let impl: RowImpl + let sqliteStatement: SQLiteStatement // IMPLEMENTATION NOTE: Making sqliteStatement a row property instead of a RowImpl property makes the extraction of MetalType values faster. /** Builds a row from the *current state* of the SQLite statement. @@ -477,14 +483,17 @@ public struct Row: CollectionType { corrupting the row. */ init(detachedStatement statement: SelectStatement) { + self.sqliteStatement = nil self.impl = DetachedRowImpl(statement: statement) } init(metalStatement statement: SelectStatement) { + self.sqliteStatement = statement.sqliteStatement self.impl = MetalRowImpl(statement: statement) } init(impl: RowImpl) { + self.sqliteStatement = nil self.impl = impl } @@ -494,7 +503,6 @@ public struct Row: CollectionType { /// See Row.init(databaseDictionary:) private struct DictionaryRowImpl : RowImpl { let databaseDictionary: [String: DatabaseValue] - var sqliteStatement: SQLiteStatement { return nil } init (databaseDictionary: [String: DatabaseValue]) { self.databaseDictionary = databaseDictionary @@ -534,7 +542,6 @@ public struct Row: CollectionType { private struct DetachedRowImpl : RowImpl { let databaseValues: [DatabaseValue] let columnNames: [String] - var sqliteStatement: SQLiteStatement { return nil } init(statement: SelectStatement) { self.databaseValues = (0.. DatabaseValue func columnName(atIndex index: Int) -> String func indexForColumn(named name: String) -> Int? // This method MUST be case-insensitive. diff --git a/GRDB/Core/SelectStatement.swift b/GRDB/Core/SelectStatement.swift index b5b754f2e..17ee1e325 100644 --- a/GRDB/Core/SelectStatement.swift +++ b/GRDB/Core/SelectStatement.swift @@ -26,46 +26,16 @@ public final class SelectStatement : Statement { // MARK: - Not public /** - Returns the DatabaseValue at given index. - - It is the *only* method which loads data straight from SQLite. - - We preserve the *raw storage class* of database values, and do not use the - SQLite built-in casting between types. - - This is *by design*, because a GRDB user generally consumes database values - long after the opportunity to use SQLite casting has passed, which is during - the statement consumption. - - // Rows is an Array: all rows are loaded, which means that statement has - // been fully iterated and consumed, and any SQLite casting opportunity - // has passed. - let rows = Row.fetchAll(db, "SELECT ...") - - for row in rows { - let itemCount: Int? = row.value(atIndex:0) // GRDB conversion to Int - let hasItems: Bool? = row.value(atIndex:0) // GRDB conversion to Bool - } + TODO */ func databaseValue(atIndex index: Int) -> DatabaseValue { return DatabaseValue(sqliteStatement: sqliteStatement, index: index) } /** - Builds a generator from a SelectStatement. - - let statement = db.selectStatement("SELECT ...") - - // AnyGenerator - let rowGenerator = statement.generate() { Row(statement: statement) } - - - parameter arguments: Optional statement arguments. - - parameter transform: A function that maps the statement to the desired - sequence element. SQLite statements are stateful: at the moment the - *read* function is called, the statement has just read a row. - - returns: A lazy sequence. + TODO */ - func fetch(arguments arguments: StatementArguments?, read: () -> T) -> AnySequence { + func fetch(arguments arguments: StatementArguments?, map: () -> T) -> DatabaseSequence { if let arguments = arguments { self.arguments = arguments } @@ -77,24 +47,48 @@ public final class SelectStatement : Statement { // Check that sequence is built on a valid database. // See DatabaseQueue.inSafeDatabase(). database.assertValid() + + return DatabaseSequence(statement: self, map: map) + } +} - return AnySequence { () -> AnyGenerator in - - // Restart - self.reset() - - return anyGenerator { () -> T? in - - let code = sqlite3_step(self.sqliteStatement) - switch code { - case SQLITE_DONE: - return nil - case SQLITE_ROW: - return read() - default: - fatalError(DatabaseError(code: code, message: self.database.lastErrorMessage, sql: self.sql, arguments: self.arguments).description) - } - } +/** +TODO +*/ +public struct DatabaseSequence: SequenceType { + let statement: SelectStatement + let map: () -> T + public func generate() -> DatabaseGenerator { + // DatabaseSequence can be restarted: + statement.reset() + + return DatabaseGenerator(statement: statement, map: map) + } +} + +/** +TODO +*/ +public struct DatabaseGenerator: GeneratorType { + let statement: SelectStatement + let sqliteStatement: SQLiteStatement + let map: () -> T + + init(statement: SelectStatement, map: () -> T) { + self.statement = statement + self.sqliteStatement = statement.sqliteStatement + self.map = map + } + + public func next() -> T? { + let code = sqlite3_step(sqliteStatement) + switch code { + case SQLITE_DONE: + return nil + case SQLITE_ROW: + return map() + default: + fatalError(DatabaseError(code: code, message: statement.database.lastErrorMessage, sql: statement.sql, arguments: statement.arguments).description) } } } diff --git a/GRDB/Foundation/NSDate.swift b/GRDB/Foundation/NSDate.swift index d763700b0..d8f7bb217 100644 --- a/GRDB/Foundation/NSDate.swift +++ b/GRDB/Foundation/NSDate.swift @@ -20,7 +20,7 @@ Usage: let date = row.value(named: "date") as NSDate? // Direct fetch: - NSDate.fetch(db, "SELECT ...", arguments: ...) // AnySequence + NSDate.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence NSDate.fetchAll(db, "SELECT ...", arguments: ...) // [NSDate?] NSDate.fetchOne(db, "SELECT ...", arguments: ...) // NSDate? diff --git a/GRDB/Record/Record.swift b/GRDB/Record/Record.swift index cbadb4b5f..ac441f993 100644 --- a/GRDB/Record/Record.swift +++ b/GRDB/Record/Record.swift @@ -51,7 +51,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabaseStorable { // IMPLEMENTATION NOTE // // Swift requires a required initializer so that we can fetch Records - // in SelectStatement.fetch(type: Record.Type, arguments: StatementArguments? = nil) -> AnySequence + // in SelectStatement.fetch(type: Record.Type, arguments: StatementArguments? = nil) -> DatabaseSequence // // This required initializer *can not* be the simple init(), because it // would prevent subclasses to provide handy initializers made of diff --git a/README.md b/README.md index 5fb528ba4..a17d8629a 100644 --- a/README.md +++ b/README.md @@ -53,7 +53,7 @@ let redWinesCount = dbQueue.inDatabase { db in // Int dbQueue.inDatabase { db in let wines = Wine.fetchAll(db, "SELECT ...") // [Wine] - for wine in Wine.fetch(db, "SELECT ...") { // AnySequence + for wine in Wine.fetch(db, "SELECT ...") { // DatabaseSequence ... } } @@ -209,19 +209,19 @@ You can fetch **Rows**, **Values**, and **Records**: ```swift dbQueue.inDatabase { db in - Row.fetch(db, "SELECT ...", arguments: ...) // AnySequence - Row.fetchAll(db, "SELECT ...", arguments: ...) // [Row] - Row.fetchOne(db, "SELECT ...", arguments: ...) // Row? - - String.fetch(db, "SELECT ...", arguments: ...) // AnySequence - String.fetchAll(db, "SELECT ...", arguments: ...) // [String?] - String.fetchOne(db, "SELECT ...", arguments: ...) // String? - - Person.fetch(db, "SELECT ...", arguments: ...) // AnySequence - Person.fetchAll(db, "SELECT ...", arguments: ...) // [Person] - Person.fetchOne(db, "SELECT ...", arguments: ...) // Person? - Person.fetchOne(db, primaryKey: 12) // Person? - Person.fetchOne(db, key: ["name": "Arthur"]) // Person? + Row.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence + Row.fetchAll(db, "SELECT ...", arguments: ...) // [Row] + Row.fetchOne(db, "SELECT ...", arguments: ...) // Row? + + String.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence + String.fetchAll(db, "SELECT ...", arguments: ...) // [String?] + String.fetchOne(db, "SELECT ...", arguments: ...) // String? + + Person.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence + Person.fetchAll(db, "SELECT ...", arguments: ...) // [Person] + Person.fetchOne(db, "SELECT ...", arguments: ...) // Person? + Person.fetchOne(db, primaryKey: 12) // Person? + Person.fetchOne(db, key: ["name": "Arthur"]) // Person? } ``` @@ -238,7 +238,7 @@ Fetch **lazy sequences** of rows, **arrays**, or a **single** row: ```swift dbQueue.inDatabase { db in - Row.fetch(db, "SELECT ...", arguments: ...) // AnySequence + Row.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence Row.fetchAll(db, "SELECT ...", arguments: ...) // [Row] Row.fetchOne(db, "SELECT ...", arguments: ...) // Row? } @@ -335,7 +335,7 @@ Like rows, values can be fetched as **lazy sequences**, **arrays**, or **single* ```swift dbQueue.inDatabase { db in - Int.fetch(db, "SELECT ...", arguments: ...) // AnySequence + Int.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence Int.fetchAll(db, "SELECT ...", arguments: ...) // [Int?] Int.fetchOne(db, "SELECT ...", arguments: ...) // Int? } @@ -429,7 +429,7 @@ Extract NSDate from the database: let row = Row.fetchOne(db, "SELECT birthDate, ...")! let date = row.value(named: "birthDate") as NSDate? -NSDate.fetch(db, "SELECT ...") // AnySequence +NSDate.fetch(db, "SELECT ...") // DatabaseSequence NSDate.fetchAll(db, "SELECT ...") // [NSDate?] NSDate.fetchOne(db, "SELECT ...") // NSDate? ``` @@ -483,7 +483,7 @@ let dbComponents = row.value(named: "birthDate")! as DatabaseDateComponents dbComponents.format // .YMD (the actual format found in the database) dbComponents.dateComponents // NSDateComponents -DatabaseDateComponents.fetch(db, "SELECT ...") // AnySequence +DatabaseDateComponents.fetch(db, "SELECT ...") // DatabaseSequence DatabaseDateComponents.fetchAll(db, "SELECT ...") // [DatabaseDateComponents?] DatabaseDateComponents.fetchOne(db, "SELECT ...") // DatabaseDateComponents? ``` @@ -554,7 +554,7 @@ for rows in Row.fetch(db, "SELECT * FROM wines") { } // Direct fetch: -Color.fetch(db, "SELECT ...", arguments: ...) // AnySequence +Color.fetch(db, "SELECT ...", arguments: ...) // DatabaseSequence Color.fetchAll(db, "SELECT ...", arguments: ...) // [Color?] Color.fetchOne(db, "SELECT ...", arguments: ...) // Color? ``` @@ -639,7 +639,7 @@ for rows in Row.fetch(db, "SELECT ...") { } // Direct fetch: -DatabaseTimestamp.fetch(db, "SELECT ...") // AnySequence +DatabaseTimestamp.fetch(db, "SELECT ...") // DatabaseSequence DatabaseTimestamp.fetchAll(db, "SELECT ...") // [DatabaseTimestamp?] DatabaseTimestamp.fetchOne(db, "SELECT ...") // DatabaseTimestamp? ``` @@ -719,15 +719,15 @@ dbQueue.inDatabase { db in let statement = db.selectStatement("SELECT ...") - Row.fetch(statement, arguments: ...) // AnySequence + Row.fetch(statement, arguments: ...) // DatabaseSequence Row.fetchAll(statement, arguments: ...) // [Row] Row.fetchOne(statement, arguments: ...) // Row? - Int.fetch(statement, arguments: ...) // AnySequence + Int.fetch(statement, arguments: ...) // DatabaseSequence Int.fetchAll(statement, arguments: ...) // [Int?] Int.fetchOne(statement, arguments: ...) // Int? - Person.fetch(statement, arguments: ...) // AnySequence + Person.fetch(statement, arguments: ...) // DatabaseSequence Person.fetchAll(statement, arguments: ...) // [Person] Person.fetchOne(statement, arguments: ...) // Person? } @@ -947,7 +947,7 @@ Now you can fetch **lazy sequences** of records, **arrays**, or **single** insta ```swift dbQueue.inDatabase { db in - Person.fetch(db, "SELECT ...", arguments:...) // AnySequence + Person.fetch(db, "SELECT ...", arguments:...) // DatabaseSequence Person.fetchAll(db, "SELECT ...", arguments:...) // [Person] Person.fetchOne(db, "SELECT ...", arguments:...) // Person? }