mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-30 04:28:44 +00:00
Documentation
This commit is contained in:
1 parent
1c264c690a
commit
4c2a1e9d92
2 files changed
+12
No files matched your search
@@ -158,6 +158,7 @@ func failOnError<Result>(@noescape block: (Void) throws -> Result) -> Result {
|
||||
|
||||
extension Database {
|
||||
|
||||
// let rows = db.fetchRows("SELECT ...", bindings: ...)
|
||||
public func fetchRows(sql: String, bindings: Bindings? = nil) -> AnySequence<Row> {
|
||||
return failOnError {
|
||||
let statement = try selectStatement(sql, bindings: bindings)
|
||||
@@ -165,10 +166,12 @@ extension Database {
|
||||
}
|
||||
}
|
||||
|
||||
// let rows = db.fetchAllRows("SELECT ...", bindings: ...)
|
||||
public func fetchAllRows(sql: String, bindings: Bindings? = nil) -> [Row] {
|
||||
return Array(fetchRows(sql, bindings: bindings))
|
||||
}
|
||||
|
||||
// let row = db.fetchOneRows("SELECT ...", bindings: ...)
|
||||
public func fetchOneRow(sql: String, bindings: Bindings? = nil) -> Row? {
|
||||
return fetchRows(sql, bindings: bindings).generate().next()
|
||||
}
|
||||
@@ -176,6 +179,7 @@ extension Database {
|
||||
|
||||
extension Database {
|
||||
|
||||
// let names = db.fetch(String.self, "SELECT name ...", bindings: ...)
|
||||
public func fetch<DatabaseValue: DatabaseValueType>(type: DatabaseValue.Type, _ sql: String, bindings: Bindings? = nil) -> AnySequence<DatabaseValue?> {
|
||||
return failOnError {
|
||||
let statement = try selectStatement(sql, bindings: bindings)
|
||||
@@ -183,10 +187,12 @@ extension Database {
|
||||
}
|
||||
}
|
||||
|
||||
// let names = db.fetchAll(String.self, "SELECT name ...", bindings: ...)
|
||||
public func fetchAll<DatabaseValue: DatabaseValueType>(type: DatabaseValue.Type, _ sql: String, bindings: Bindings? = nil) -> [DatabaseValue?] {
|
||||
return Array(fetch(type, sql, bindings: bindings))
|
||||
}
|
||||
|
||||
// let name = db.fetchOne(String.self, "SELECT name ...", bindings: ...)
|
||||
public func fetchOne<DatabaseValue: DatabaseValueType>(type: DatabaseValue.Type, _ sql: String, bindings: Bindings? = nil) -> DatabaseValue? {
|
||||
if let first = fetch(type, sql, bindings: bindings).generate().next() {
|
||||
// one row containing an optional value
|
||||
|
||||
@@ -38,6 +38,7 @@ public final class SelectStatement : Statement {
|
||||
|
||||
extension SelectStatement {
|
||||
|
||||
// let rows = statement.fetchRows()
|
||||
public func fetchRows() -> AnySequence<Row> {
|
||||
return AnySequence { () -> AnyGenerator<Row> in
|
||||
var logSQL = self.database.configuration.verbose
|
||||
@@ -77,10 +78,12 @@ extension SelectStatement {
|
||||
}
|
||||
}
|
||||
|
||||
// let rows = statement.fetchAllRows()
|
||||
public func fetchAllRows() -> [Row] {
|
||||
return Array(fetchRows())
|
||||
}
|
||||
|
||||
// let row = statement.fetchOneRow()
|
||||
public func fetchOneRow() -> Row? {
|
||||
return fetchRows().generate().next()
|
||||
}
|
||||
@@ -88,6 +91,7 @@ extension SelectStatement {
|
||||
|
||||
extension SelectStatement {
|
||||
|
||||
// let names = statement.fetch(String.self)
|
||||
public func fetch<DatabaseValue: DatabaseValueType>(type: DatabaseValue.Type) -> AnySequence<DatabaseValue?> {
|
||||
let rowSequence = fetchRows()
|
||||
return AnySequence { () -> AnyGenerator<DatabaseValue?> in
|
||||
@@ -102,10 +106,12 @@ extension SelectStatement {
|
||||
}
|
||||
}
|
||||
|
||||
// let names = statement.fetchAll(String.self)
|
||||
public func fetchAll<DatabaseValue: DatabaseValueType>(type: DatabaseValue.Type) -> [DatabaseValue?] {
|
||||
return Array(fetch(type))
|
||||
}
|
||||
|
||||
// let name = statement.fetchOne(String.self)
|
||||
public func fetchOne<DatabaseValue: DatabaseValueType>(type: DatabaseValue.Type) -> DatabaseValue? {
|
||||
if let optionalValue = fetch(type).generate().next() {
|
||||
// one row containing an optional value
|
||||
|
||||
Reference in new issue
Block a user