extension Row { // MARK: - Fetching From QueryInterfaceRequest /// Returns an array of rows fetched from a fetch request. /// /// let request = Player.all() /// let rows = try Row.fetchAll(db, request) /// /// - parameters: /// - db: A database connection. /// - request: A FetchRequest. /// - returns: An array of rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. @inlinable public static func fetchAll(_ db: Database, _ request: QueryInterfaceRequest) throws -> [Row] { // TODO: prefetch if needed let (statement, adapter) = try request.prepare(db, forSingleResult: false) return try fetchAll(statement, adapter: adapter) } /// Returns a single row fetched from a fetch request. /// /// let request = Player.filter(key: 1) /// let row = try Row.fetchOne(db, request) /// /// - parameters: /// - db: A database connection. /// - request: A FetchRequest. /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. @inlinable public static func fetchOne(_ db: Database, _ request: QueryInterfaceRequest) throws -> Row? { // TODO: prefetch if needed let (statement, adapter) = try request.prepare(db, forSingleResult: true) return try fetchOne(statement, adapter: adapter) } } extension QueryInterfaceRequest where RowDecoder: Row { // MARK: Fetching Rows /// An array of fetched rows. /// /// let request: QueryInterfaceRequest = ... /// let rows = try request.fetchAll(db) /// /// - parameter db: A database connection. /// - returns: An array of fetched rows. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. @inlinable public func fetchAll(_ db: Database) throws -> [Row] { return try Row.fetchAll(db, self) } /// The first fetched row. /// /// let request: QueryInterfaceRequest = ... /// let row = try request.fetchOne(db) /// /// - parameter db: A database connection. /// - returns: An optional row. /// - throws: A DatabaseError is thrown whenever an SQLite error occurs. @inlinable public func fetchOne(_ db: Database) throws -> Row? { return try Row.fetchOne(db, self) } }