mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
swift-DEVELOPMENT-SNAPSHOT-2016-05-31-a
This commit is contained in:
1 parent
7c4ff7677d
commit
aa6097dff8
16 files changed
+22
-131
No files matched your search
@@ -358,7 +358,6 @@ extension Database {
|
||||
/// - parameter sql: An SQL query.
|
||||
/// - returns: A SelectStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
@warn_unused_result
|
||||
public func makeSelectStatement(_ sql: String) throws -> SelectStatement {
|
||||
return try SelectStatement(database: self, sql: sql)
|
||||
}
|
||||
@@ -375,7 +374,6 @@ extension Database {
|
||||
/// - parameter sql: An SQL query.
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
@warn_unused_result
|
||||
public func cachedSelectStatement(_ sql: String) throws -> SelectStatement {
|
||||
if let statement = selectStatementCache[sql] {
|
||||
return statement
|
||||
@@ -395,7 +393,6 @@ extension Database {
|
||||
/// - parameter sql: An SQL query.
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
@warn_unused_result
|
||||
public func makeUpdateStatement(_ sql: String) throws -> UpdateStatement {
|
||||
return try UpdateStatement(database: self, sql: sql)
|
||||
}
|
||||
@@ -412,7 +409,6 @@ extension Database {
|
||||
/// - parameter sql: An SQL query.
|
||||
/// - returns: An UpdateStatement.
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
@warn_unused_result
|
||||
public func cachedUpdateStatement(_ sql: String) throws -> UpdateStatement {
|
||||
if let statement = updateStatementCache[sql] {
|
||||
return statement
|
||||
|
||||
@@ -82,7 +82,6 @@ public struct DatabaseValue {
|
||||
/// DatabaseValueConvertible.fromDatabaseValue() method.
|
||||
///
|
||||
/// - returns: An optional *Value*.
|
||||
@warn_unused_result
|
||||
public func value<Value: DatabaseValueConvertible>() -> Value? {
|
||||
if let value = Value.fromDatabaseValue(self) {
|
||||
return value
|
||||
@@ -99,7 +98,6 @@ public struct DatabaseValue {
|
||||
/// can not be converted to `Value`.
|
||||
///
|
||||
/// - returns: A *Value*.
|
||||
@warn_unused_result
|
||||
public func value<Value: DatabaseValueConvertible>() -> Value {
|
||||
guard let value = Value.fromDatabaseValue(self) as Value? else {
|
||||
fatalError("could not convert \(self) to \(Value.self).")
|
||||
|
||||
@@ -62,7 +62,6 @@ public extension DatabaseValueConvertible {
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: A sequence.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence<Self> {
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
return statement.fetchSequence(arguments: arguments) {
|
||||
@@ -79,7 +78,6 @@ public extension DatabaseValueConvertible {
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return Array(fetch(statement, arguments: arguments))
|
||||
}
|
||||
@@ -96,7 +94,6 @@ public extension DatabaseValueConvertible {
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional value.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> Self? {
|
||||
let sequence = statement.fetchSequence(arguments: arguments) {
|
||||
fromDatabaseValue(DatabaseValue(sqliteStatement: statement.sqliteStatement, index: 0))
|
||||
@@ -131,7 +128,6 @@ public extension DatabaseValueConvertible {
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: A sequence.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Self> {
|
||||
return fetch(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
@@ -145,7 +141,6 @@ public extension DatabaseValueConvertible {
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return fetchAll(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
@@ -162,7 +157,6 @@ public extension DatabaseValueConvertible {
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional value.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return fetchOne(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
@@ -206,7 +200,6 @@ public extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: A sequence of optional values.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence<Wrapped?> {
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
return statement.fetchSequence(arguments: arguments) {
|
||||
@@ -223,7 +216,6 @@ public extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array of optional values.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> [Wrapped?] {
|
||||
return Array(fetch(statement, arguments: arguments))
|
||||
}
|
||||
@@ -252,7 +244,6 @@ public extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: A sequence of optional values.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Wrapped?> {
|
||||
return fetch(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
@@ -266,7 +257,6 @@ public extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// - sql: An SQL query.
|
||||
/// - parameter arguments: Optional statement arguments.
|
||||
/// - returns: An array of optional values.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Wrapped?] {
|
||||
return fetchAll(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
|
||||
@@ -32,7 +32,6 @@ public final class Row {
|
||||
/// Fetched rows are reused during the iteration of a query, for performance
|
||||
/// reasons: make sure to make a copy of it whenever you want to keep a
|
||||
/// specific one: `row.copy()`.
|
||||
@warn_unused_result
|
||||
public func copy() -> Row {
|
||||
return impl.copy(self)
|
||||
}
|
||||
@@ -125,7 +124,6 @@ extension Row {
|
||||
///
|
||||
/// Indexes span from 0 for the leftmost column to (row.count - 1) for the
|
||||
/// righmost column.
|
||||
@warn_unused_result
|
||||
public func value(atIndex index: Int) -> DatabaseValueConvertible? {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range")
|
||||
return impl.databaseValue(atUncheckedIndex: index).value()
|
||||
@@ -139,7 +137,6 @@ extension Row {
|
||||
/// If the SQLite value is NULL, the result is nil. Otherwise the SQLite
|
||||
/// value is converted to the requested type `Value`. Should this conversion
|
||||
/// fail, a fatal error is raised.
|
||||
@warn_unused_result
|
||||
public func value<Value: DatabaseValueConvertible>(atIndex index: Int) -> Value? {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range")
|
||||
return impl.databaseValue(atUncheckedIndex: index).value()
|
||||
@@ -157,7 +154,6 @@ extension Row {
|
||||
/// This method exists as an optimization opportunity for types that adopt
|
||||
/// StatementColumnConvertible. It *may* trigger SQLite built-in conversions
|
||||
/// (see https://www.sqlite.org/datatype3.html).
|
||||
@warn_unused_result
|
||||
public func value<Value: protocol<DatabaseValueConvertible, StatementColumnConvertible>>(atIndex index: Int) -> Value? {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range")
|
||||
guard let sqliteStatement = sqliteStatement else {
|
||||
@@ -173,7 +169,6 @@ extension Row {
|
||||
///
|
||||
/// This method crashes if the fetched SQLite value is NULL, or if the
|
||||
/// SQLite value can not be converted to `Value`.
|
||||
@warn_unused_result
|
||||
public func value<Value: DatabaseValueConvertible>(atIndex index: Int) -> Value {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range")
|
||||
return impl.databaseValue(atUncheckedIndex: index).value()
|
||||
@@ -190,7 +185,6 @@ extension Row {
|
||||
/// This method exists as an optimization opportunity for types that adopt
|
||||
/// StatementColumnConvertible. It *may* trigger SQLite built-in conversions
|
||||
/// (see https://www.sqlite.org/datatype3.html).
|
||||
@warn_unused_result
|
||||
public func value<Value: protocol<DatabaseValueConvertible, StatementColumnConvertible>>(atIndex index: Int) -> Value {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range")
|
||||
guard let sqliteStatement = sqliteStatement else {
|
||||
@@ -206,7 +200,6 @@ extension Row {
|
||||
/// the same name, the leftmost column is considered.
|
||||
///
|
||||
/// The result is nil if the row does not contain the column.
|
||||
@warn_unused_result
|
||||
public func value(named columnName: String) -> DatabaseValueConvertible? {
|
||||
// IMPLEMENTATION NOTE
|
||||
// This method has a single know use case: checking if the value is nil,
|
||||
@@ -229,7 +222,6 @@ extension Row {
|
||||
/// If the column is missing or if the SQLite value is NULL, the result is
|
||||
/// nil. Otherwise the SQLite value is converted to the requested type
|
||||
/// `Value`. Should this conversion fail, a fatal error is raised.
|
||||
@warn_unused_result
|
||||
public func value<Value: DatabaseValueConvertible>(named columnName: String) -> Value? {
|
||||
guard let index = impl.index(ofColumn: columnName) else {
|
||||
return nil
|
||||
@@ -249,7 +241,6 @@ extension Row {
|
||||
/// This method exists as an optimization opportunity for types that adopt
|
||||
/// StatementColumnConvertible. It *may* trigger SQLite built-in conversions
|
||||
/// (see https://www.sqlite.org/datatype3.html).
|
||||
@warn_unused_result
|
||||
public func value<Value: protocol<DatabaseValueConvertible, StatementColumnConvertible>>(named columnName: String) -> Value? {
|
||||
guard let index = impl.index(ofColumn: columnName) else {
|
||||
return nil
|
||||
@@ -269,7 +260,6 @@ extension Row {
|
||||
///
|
||||
/// This method crashes if the fetched SQLite value is NULL, or if the
|
||||
/// SQLite value can not be converted to `Value`.
|
||||
@warn_unused_result
|
||||
public func value<Value: DatabaseValueConvertible>(named columnName: String) -> Value {
|
||||
guard let index = impl.index(ofColumn: columnName) else {
|
||||
fatalError("no such column: \(columnName)")
|
||||
@@ -290,7 +280,6 @@ extension Row {
|
||||
/// This method exists as an optimization opportunity for types that adopt
|
||||
/// StatementColumnConvertible. It *may* trigger SQLite built-in conversions
|
||||
/// (see https://www.sqlite.org/datatype3.html).
|
||||
@warn_unused_result
|
||||
public func value<Value: protocol<DatabaseValueConvertible, StatementColumnConvertible>>(named columnName: String) -> Value {
|
||||
guard let index = impl.index(ofColumn: columnName) else {
|
||||
fatalError("no such column: \(columnName)")
|
||||
@@ -311,7 +300,6 @@ extension Row {
|
||||
///
|
||||
/// The returned data does not owns its bytes: it must not be used longer
|
||||
/// than the row's lifetime.
|
||||
@warn_unused_result
|
||||
public func dataNoCopy(atIndex index: Int) -> NSData? {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range")
|
||||
return impl.dataNoCopy(atUncheckedIndex: index)
|
||||
@@ -328,7 +316,6 @@ extension Row {
|
||||
///
|
||||
/// The returned data does not owns its bytes: it must not be used longer
|
||||
/// than the row's lifetime.
|
||||
@warn_unused_result
|
||||
public func dataNoCopy(named columnName: String) -> NSData? {
|
||||
guard let index = impl.index(ofColumn: columnName) else {
|
||||
return nil
|
||||
@@ -353,7 +340,6 @@ extension Row {
|
||||
///
|
||||
/// Indexes span from 0 for the leftmost column to (row.count - 1) for the
|
||||
/// righmost column.
|
||||
@warn_unused_result
|
||||
public func databaseValue(atIndex index: Int) -> DatabaseValue {
|
||||
GRDBPrecondition(index >= 0 && index < count, "row index out of range")
|
||||
return impl.databaseValue(atUncheckedIndex: index)
|
||||
@@ -365,7 +351,6 @@ extension Row {
|
||||
/// the same name, the leftmost column is considered.
|
||||
///
|
||||
/// The result is nil if the row does not contain the column.
|
||||
@warn_unused_result
|
||||
public func databaseValue(named columnName: String) -> DatabaseValue? {
|
||||
guard let index = impl.index(ofColumn: columnName) else {
|
||||
return nil
|
||||
@@ -378,7 +363,6 @@ extension Row {
|
||||
|
||||
// MARK: - Helpers
|
||||
|
||||
@warn_unused_result
|
||||
private static func statementColumnConvertible<Value: StatementColumnConvertible>(atUncheckedIndex index: Int, in sqliteStatement: SQLiteStatement) -> Value? {
|
||||
guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else {
|
||||
return nil
|
||||
@@ -386,7 +370,6 @@ extension Row {
|
||||
return Value.init(sqliteStatement: sqliteStatement, index: Int32(index))
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
private static func statementColumnConvertible<Value: StatementColumnConvertible>(atUncheckedIndex index: Int, in sqliteStatement: SQLiteStatement) -> Value {
|
||||
guard sqlite3_column_type(sqliteStatement, Int32(index)) != SQLITE_NULL else {
|
||||
fatalError("could not convert NULL to \(Value.self).")
|
||||
@@ -442,7 +425,6 @@ extension Row {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A sequence of rows.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> DatabaseSequence<Row> {
|
||||
// Metal rows can be reused. And reusing them yields better performance.
|
||||
let row = try! Row(statement: statement).adaptedRow(adapter: adapter, statement: statement)
|
||||
@@ -461,7 +443,6 @@ extension Row {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of rows.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> [Row] {
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
let columnNames = statement.columnNames
|
||||
@@ -489,7 +470,6 @@ extension Row {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional row.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Row? {
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
let columnNames = statement.columnNames
|
||||
@@ -540,7 +520,6 @@ extension Row {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A sequence of rows.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> DatabaseSequence<Row> {
|
||||
return fetch(try! db.makeSelectStatement(sql), arguments: arguments, adapter: adapter)
|
||||
}
|
||||
@@ -555,7 +534,6 @@ extension Row {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of rows.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> [Row] {
|
||||
return fetchAll(try! db.makeSelectStatement(sql), arguments: arguments, adapter: adapter)
|
||||
}
|
||||
@@ -570,7 +548,6 @@ extension Row {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional row.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Row? {
|
||||
return fetchOne(try! db.makeSelectStatement(sql), arguments: arguments, adapter: adapter)
|
||||
}
|
||||
|
||||
@@ -172,7 +172,6 @@ public class Statement {
|
||||
|
||||
// Returns a validated array of as many DatabaseValue as there are
|
||||
// parameters in the statement.
|
||||
@warn_unused_result
|
||||
private func validatedBindings(_ arguments: StatementArguments) throws -> [DatabaseValue] {
|
||||
// An array of (key, value) pairs.
|
||||
//
|
||||
@@ -313,7 +312,6 @@ public final class SelectStatement : Statement {
|
||||
}
|
||||
|
||||
/// Creates a DatabaseSequence
|
||||
@warn_unused_result
|
||||
func fetchSequence<Element>(arguments: StatementArguments?, element: () -> Element) -> DatabaseSequence<Element> {
|
||||
// Force arguments validity. See UpdateStatement.execute(), and Database.execute()
|
||||
try! prepare(withArguments: arguments)
|
||||
@@ -366,7 +364,6 @@ public struct DatabaseSequence<Element>: Sequence {
|
||||
}
|
||||
|
||||
/// Return a *iterator* over the elements of this *sequence*.
|
||||
@warn_unused_result
|
||||
public func makeIterator() -> DatabaseIterator<Element> {
|
||||
return try! makeIteratorImpl()
|
||||
}
|
||||
@@ -395,7 +392,6 @@ public final class DatabaseIterator<Element>: IteratorProtocol {
|
||||
statementRef?.release()
|
||||
}
|
||||
|
||||
@warn_unused_result
|
||||
public func next() -> Element? {
|
||||
guard let element = element else {
|
||||
return nil
|
||||
|
||||
@@ -67,7 +67,6 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: A sequence of values.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> DatabaseSequence<Self> {
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
return statement.fetchSequence(arguments: arguments) {
|
||||
@@ -87,7 +86,6 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array of values.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return Array(fetch(statement, arguments: arguments))
|
||||
}
|
||||
@@ -101,7 +99,6 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// - statement: The statement to run.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional value.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil) -> Self? {
|
||||
let sqliteStatement = statement.sqliteStatement
|
||||
let sequence = statement.fetchSequence(arguments: arguments) {
|
||||
@@ -139,7 +136,6 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: A sequence of values.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> DatabaseSequence<Self> {
|
||||
return fetch(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
@@ -153,7 +149,6 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An array of values.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> [Self] {
|
||||
return fetchAll(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
@@ -167,7 +162,6 @@ public extension DatabaseValueConvertible where Self: StatementColumnConvertible
|
||||
/// - sql: An SQL query.
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - returns: An optional value.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil) -> Self? {
|
||||
return fetchOne(try! db.makeSelectStatement(sql), arguments: arguments)
|
||||
}
|
||||
|
||||
@@ -61,7 +61,6 @@ extension DatabaseValueConvertible {
|
||||
///
|
||||
/// If the database is modified while the sequence is iterating, the
|
||||
/// remaining elements are undefined.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ request: FetchRequest) -> DatabaseSequence<Self> {
|
||||
return try! fetch(request.selectStatement(db))
|
||||
}
|
||||
@@ -73,7 +72,6 @@ extension DatabaseValueConvertible {
|
||||
/// let names = String.fetchAll(db, request) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ request: FetchRequest) -> [Self] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
@@ -88,7 +86,6 @@ extension DatabaseValueConvertible {
|
||||
/// let name = String.fetchOne(db, request) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ request: FetchRequest) -> Self? {
|
||||
return try! fetchOne(request.selectStatement(db))
|
||||
}
|
||||
@@ -116,7 +113,6 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
///
|
||||
/// If the database is modified while the sequence is iterating, the
|
||||
/// remaining elements are undefined.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ request: FetchRequest) -> DatabaseSequence<Wrapped?> {
|
||||
return try! fetch(request.selectStatement(db))
|
||||
}
|
||||
@@ -128,7 +124,6 @@ extension Optional where Wrapped: DatabaseValueConvertible {
|
||||
/// let names = Optional<String>.fetchAll(db, request) // [String?]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ request: FetchRequest) -> [Wrapped?] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
@@ -156,7 +151,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
///
|
||||
/// If the database is modified while the sequence is iterating, the
|
||||
/// remaining elements are undefined.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ request: FetchRequest) -> DatabaseSequence<Self> {
|
||||
return try! fetch(request.selectStatement(db))
|
||||
}
|
||||
@@ -168,7 +162,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// let names = String.fetchAll(db, request) // [String]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ request: FetchRequest) -> [Self] {
|
||||
return try! fetchAll(request.selectStatement(db))
|
||||
}
|
||||
@@ -183,7 +176,6 @@ extension DatabaseValueConvertible where Self: StatementColumnConvertible {
|
||||
/// let name = String.fetchOne(db, request) // String?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ request: FetchRequest) -> Self? {
|
||||
return try! fetchOne(request.selectStatement(db))
|
||||
}
|
||||
@@ -211,7 +203,6 @@ extension RowConvertible {
|
||||
///
|
||||
/// If the database is modified while the sequence is iterating, the
|
||||
/// remaining elements are undefined.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ request: FetchRequest) -> DatabaseSequence<Self> {
|
||||
let statement = try! request.selectStatement(db)
|
||||
let adapter = try! request.adapter(statement)
|
||||
@@ -225,7 +216,6 @@ extension RowConvertible {
|
||||
/// let identities = Identity.fetchAll(db, request) // [Identity]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ request: FetchRequest) -> [Self] {
|
||||
let statement = try! request.selectStatement(db)
|
||||
let adapter = try! request.adapter(statement)
|
||||
@@ -239,7 +229,6 @@ extension RowConvertible {
|
||||
/// let identity = Identity.fetchOne(db, request) // Identity?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ request: FetchRequest) -> Self? {
|
||||
let statement = try! request.selectStatement(db)
|
||||
let adapter = try! request.adapter(statement)
|
||||
@@ -267,7 +256,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
///
|
||||
/// If the database is modified while the sequence is iterating, the
|
||||
/// remaining elements are undefined.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database) -> DatabaseSequence<Self> {
|
||||
return all().fetch(db)
|
||||
}
|
||||
@@ -277,7 +265,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// let persons = Person.fetchAll(db) // [Person]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database) -> [Self] {
|
||||
return all().fetchAll(db)
|
||||
}
|
||||
@@ -287,7 +274,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// let person = Person.fetchOne(db) // Person?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database) -> Self? {
|
||||
return all().fetchOne(db)
|
||||
}
|
||||
@@ -327,7 +313,6 @@ extension Row {
|
||||
///
|
||||
/// If the database is modified while the sequence is iterating, the
|
||||
/// remaining elements of the sequence are undefined.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ request: FetchRequest) -> DatabaseSequence<Row> {
|
||||
let statement = try! request.selectStatement(db)
|
||||
let adapter = try! request.adapter(statement)
|
||||
@@ -342,7 +327,6 @@ extension Row {
|
||||
/// let rows = Row.fetchAll(db, request)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ request: FetchRequest) -> [Row] {
|
||||
let statement = try! request.selectStatement(db)
|
||||
let adapter = try! request.adapter(statement)
|
||||
@@ -357,7 +341,6 @@ extension Row {
|
||||
/// let row = Row.fetchOne(db, request)
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ request: FetchRequest) -> Row? {
|
||||
let statement = try! request.selectStatement(db)
|
||||
let adapter = try! request.adapter(statement)
|
||||
|
||||
@@ -22,7 +22,6 @@ extension QueryInterfaceRequest : FetchRequest {
|
||||
/// Returns a prepared statement that is ready to be executed.
|
||||
///
|
||||
/// - throws: A DatabaseError whenever SQLite could not parse the sql query.
|
||||
@warn_unused_result
|
||||
public func selectStatement(_ db: Database) throws -> SelectStatement {
|
||||
// TODO: split statement generation from arguments building
|
||||
var bindings: [DatabaseValueConvertible?] = []
|
||||
@@ -60,7 +59,6 @@ extension QueryInterfaceRequest where T: RowConvertible {
|
||||
///
|
||||
/// If the database is modified while the sequence is iterating, the
|
||||
/// remaining elements are undefined.
|
||||
@warn_unused_result
|
||||
public func fetch(_ db: Database) -> DatabaseSequence<T> {
|
||||
return try! T.fetch(selectStatement(db))
|
||||
}
|
||||
@@ -72,7 +70,6 @@ extension QueryInterfaceRequest where T: RowConvertible {
|
||||
/// let persons = request.fetchAll(db) // [Person]
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public func fetchAll(_ db: Database) -> [T] {
|
||||
return Array(fetch(db))
|
||||
}
|
||||
@@ -84,7 +81,6 @@ extension QueryInterfaceRequest where T: RowConvertible {
|
||||
/// let person = request.fetchOne(db) // Person?
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public func fetchOne(_ db: Database) -> T? {
|
||||
return fetch(db).makeIterator().next()
|
||||
}
|
||||
@@ -96,13 +92,11 @@ extension QueryInterfaceRequest {
|
||||
// MARK: Request Derivation
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with a new net of selected columns.
|
||||
@warn_unused_result
|
||||
public func select(_ selection: _SQLSelectable...) -> QueryInterfaceRequest<T> {
|
||||
return select(selection)
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with a new net of selected columns.
|
||||
@warn_unused_result
|
||||
public func select(_ selection: [_SQLSelectable]) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
query.selection = selection
|
||||
@@ -110,13 +104,11 @@ extension QueryInterfaceRequest {
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with a new net of selected columns.
|
||||
@warn_unused_result
|
||||
public func select(sql: String) -> QueryInterfaceRequest<T> {
|
||||
return select(_SQLLiteral(sql))
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest which returns distinct rows.
|
||||
@warn_unused_result
|
||||
public func distinct() -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
query.isDistinct = true
|
||||
@@ -125,7 +117,6 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
@warn_unused_result
|
||||
public func filter(_ predicate: _SQLExpressible) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
if let whereExpression = query.whereExpression {
|
||||
@@ -138,19 +129,16 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
@warn_unused_result
|
||||
public func filter(sql: String) -> QueryInterfaceRequest<T> {
|
||||
return filter(_SQLLiteral(sql))
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest grouped according to *expressions*.
|
||||
@warn_unused_result
|
||||
public func group(_ expressions: _SQLExpressible...) -> QueryInterfaceRequest<T> {
|
||||
return group(expressions)
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest grouped according to *expressions*.
|
||||
@warn_unused_result
|
||||
public func group(_ expressions: [_SQLExpressible]) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
query.groupByExpressions = expressions.map { $0.sqlExpression }
|
||||
@@ -158,14 +146,12 @@ extension QueryInterfaceRequest {
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with a new grouping.
|
||||
@warn_unused_result
|
||||
public func group(sql: String) -> QueryInterfaceRequest<T> {
|
||||
return group(_SQLLiteral(sql))
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *predicate* added to the
|
||||
/// eventual set of already applied predicates.
|
||||
@warn_unused_result
|
||||
public func having(_ predicate: _SQLExpressible) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
if let havingExpression = query.havingExpression {
|
||||
@@ -178,21 +164,18 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *sql* added to
|
||||
/// the eventual set of already applied predicates.
|
||||
@warn_unused_result
|
||||
public func having(sql: String) -> QueryInterfaceRequest<T> {
|
||||
return having(_SQLLiteral(sql))
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *orderings* added to
|
||||
/// the eventual set of already applied orderings.
|
||||
@warn_unused_result
|
||||
public func order(_ orderings: _SQLOrdering...) -> QueryInterfaceRequest<T> {
|
||||
return order(orderings)
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *orderings* added to
|
||||
/// the eventual set of already applied orderings.
|
||||
@warn_unused_result
|
||||
public func order(_ orderings: [_SQLOrdering]) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
query.orderings.append(contentsOf: orderings)
|
||||
@@ -201,13 +184,11 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a new QueryInterfaceRequest with the provided *sql* added to the
|
||||
/// eventual set of already applied orderings.
|
||||
@warn_unused_result
|
||||
public func order(sql: String) -> QueryInterfaceRequest<T> {
|
||||
return order([_SQLLiteral(sql)])
|
||||
}
|
||||
|
||||
/// Returns a new QueryInterfaceRequest sorted in reversed order.
|
||||
@warn_unused_result
|
||||
public func reversed() -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
query.isReversed = !query.isReversed
|
||||
@@ -216,7 +197,6 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns a QueryInterfaceRequest which fetches *limit* rows, starting at
|
||||
/// *offset*.
|
||||
@warn_unused_result
|
||||
public func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest<T> {
|
||||
var query = self.query
|
||||
query.limit = _SQLLimit(limit: limit, offset: offset)
|
||||
@@ -232,7 +212,6 @@ extension QueryInterfaceRequest {
|
||||
/// Returns the number of rows matched by the request.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public func fetchCount(_ db: Database) -> Int {
|
||||
return Int.fetchOne(db, QueryInterfaceRequest(query: query.countQuery))!
|
||||
}
|
||||
@@ -245,14 +224,12 @@ extension QueryInterfaceRequest {
|
||||
|
||||
/// Returns an SQL expression that checks the inclusion of a value in
|
||||
/// the results of another request.
|
||||
@warn_unused_result
|
||||
public func contains(_ element: _SQLExpressible) -> _SQLExpression {
|
||||
return .inSubQuery(query, element.sqlExpression)
|
||||
}
|
||||
|
||||
/// Returns an SQL expression that checks whether the receiver, as a
|
||||
/// subquery, returns any row.
|
||||
@warn_unused_result
|
||||
public func exists() -> _SQLExpression {
|
||||
return .exists(query)
|
||||
}
|
||||
@@ -264,64 +241,54 @@ extension TableMapping {
|
||||
// MARK: Request Derivation
|
||||
|
||||
/// Returns a QueryInterfaceRequest which fetches all rows in the table.
|
||||
@warn_unused_result
|
||||
public static func all() -> QueryInterfaceRequest<Self> {
|
||||
return QueryInterfaceRequest(tableName: databaseTableName())
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest which selects *selection*.
|
||||
@warn_unused_result
|
||||
public static func select(_ selection: _SQLSelectable...) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(selection)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest which selects *selection*.
|
||||
@warn_unused_result
|
||||
public static func select(_ selection: [_SQLSelectable]) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(selection)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest which selects *sql*.
|
||||
@warn_unused_result
|
||||
public static func select(sql: String) -> QueryInterfaceRequest<Self> {
|
||||
return all().select(sql: sql)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest with the provided *predicate*.
|
||||
@warn_unused_result
|
||||
public static func filter(_ predicate: _SQLExpressible) -> QueryInterfaceRequest<Self> {
|
||||
return all().filter(predicate)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest with the provided *predicate*.
|
||||
@warn_unused_result
|
||||
public static func filter(sql: String) -> QueryInterfaceRequest<Self> {
|
||||
return all().filter(sql: sql)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest sorted according to the
|
||||
/// provided *orderings*.
|
||||
@warn_unused_result
|
||||
public static func order(_ orderings: _SQLOrdering...) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(orderings)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest sorted according to the
|
||||
/// provided *orderings*.
|
||||
@warn_unused_result
|
||||
public static func order(_ orderings: [_SQLOrdering]) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(orderings)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest sorted according to *sql*.
|
||||
@warn_unused_result
|
||||
public static func order(sql: String) -> QueryInterfaceRequest<Self> {
|
||||
return all().order(sql: sql)
|
||||
}
|
||||
|
||||
/// Returns a QueryInterfaceRequest which fetches *limit* rows, starting at
|
||||
/// *offset*.
|
||||
@warn_unused_result
|
||||
public static func limit(_ limit: Int, offset: Int? = nil) -> QueryInterfaceRequest<Self> {
|
||||
return all().limit(limit, offset: offset)
|
||||
}
|
||||
@@ -335,7 +302,6 @@ extension TableMapping {
|
||||
/// Returns the number of records.
|
||||
///
|
||||
/// - parameter db: A database connection.
|
||||
@warn_unused_result
|
||||
public static func fetchCount(_ db: Database) -> Int {
|
||||
return all().fetchCount(db)
|
||||
}
|
||||
|
||||
@@ -152,7 +152,7 @@ public protocol MutablePersistable : TableMapping {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: Whether a database row was deleted.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
func delete(_ db: Database) throws -> Bool
|
||||
@discardableResult func delete(_ db: Database) throws -> Bool
|
||||
|
||||
/// Returns true if and only if the primary key matches a row in
|
||||
/// the database.
|
||||
@@ -203,7 +203,7 @@ public extension MutablePersistable {
|
||||
/// Executes a DELETE statement.
|
||||
///
|
||||
/// The default implementation for delete() invokes performDelete().
|
||||
func delete(_ db: Database) throws -> Bool {
|
||||
@discardableResult func delete(_ db: Database) throws -> Bool {
|
||||
return try performDelete(db)
|
||||
}
|
||||
|
||||
|
||||
@@ -114,7 +114,6 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
/// hasPersistentChangedValues flag.
|
||||
///
|
||||
/// - returns: A copy of self.
|
||||
@warn_unused_result
|
||||
public func copy() -> Self {
|
||||
let copy = self.dynamicType.init(row: Row(persistentDictionary))
|
||||
copy.referenceRow = referenceRow
|
||||
@@ -304,7 +303,7 @@ public class Record : RowConvertible, TableMapping, Persistable {
|
||||
/// - parameter db: A database connection.
|
||||
/// - returns: Whether a database row was deleted.
|
||||
/// - throws: A DatabaseError is thrown whenever an SQLite error occurs.
|
||||
public func delete(_ db: Database) throws -> Bool {
|
||||
@discardableResult public func delete(_ db: Database) throws -> Bool {
|
||||
defer {
|
||||
// Future calls to update() will throw NotFound. Make the user
|
||||
// a favor and make sure this error is thrown even if she checks the
|
||||
|
||||
@@ -65,7 +65,6 @@ extension RowConvertible {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A sequence of records.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> DatabaseSequence<Self> {
|
||||
let row = try! Row(statement: statement).adaptedRow(adapter: adapter, statement: statement)
|
||||
return statement.fetchSequence(arguments: arguments) {
|
||||
@@ -85,7 +84,6 @@ extension RowConvertible {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of records.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> [Self] {
|
||||
return Array(fetch(statement, arguments: arguments, adapter: adapter))
|
||||
}
|
||||
@@ -100,7 +98,6 @@ extension RowConvertible {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional record.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ statement: SelectStatement, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Self? {
|
||||
return fetch(statement, arguments: arguments, adapter: adapter).makeIterator().next()
|
||||
}
|
||||
@@ -130,7 +127,6 @@ extension RowConvertible {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: A sequence of records.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> DatabaseSequence<Self> {
|
||||
return fetch(try! db.makeSelectStatement(sql), arguments: arguments, adapter: adapter)
|
||||
}
|
||||
@@ -145,7 +141,6 @@ extension RowConvertible {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An array of records.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> [Self] {
|
||||
return fetchAll(try! db.makeSelectStatement(sql), arguments: arguments, adapter: adapter)
|
||||
}
|
||||
@@ -160,7 +155,6 @@ extension RowConvertible {
|
||||
/// - arguments: Optional statement arguments.
|
||||
/// - adapter: Optional RowAdapter
|
||||
/// - returns: An optional record.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, _ sql: String, arguments: StatementArguments? = nil, adapter: RowAdapter? = nil) -> Self? {
|
||||
return fetchOne(try! db.makeSelectStatement(sql), arguments: arguments, adapter: adapter)
|
||||
}
|
||||
|
||||
@@ -27,7 +27,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// - db: A Database.
|
||||
/// - keys: A sequence of primary keys.
|
||||
/// - returns: A sequence of records.
|
||||
@warn_unused_result
|
||||
public static func fetch<Sequence: Swift.Sequence where Sequence.Iterator.Element: DatabaseValueConvertible>(_ db: Database, keys: Sequence) -> DatabaseSequence<Self> {
|
||||
guard let statement = fetchByPrimaryKeyStatement(db, values: keys) else {
|
||||
return DatabaseSequence.makeEmptySequence(inDatabase: db)
|
||||
@@ -45,7 +44,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// - db: A database connection.
|
||||
/// - keys: A sequence of primary keys.
|
||||
/// - returns: An array of records.
|
||||
@warn_unused_result
|
||||
public static func fetchAll<Sequence: Swift.Sequence where Sequence.Iterator.Element: DatabaseValueConvertible>(_ db: Database, keys: Sequence) -> [Self] {
|
||||
guard let statement = fetchByPrimaryKeyStatement(db, values: keys) else {
|
||||
return []
|
||||
@@ -61,7 +59,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// - db: A database connection.
|
||||
/// - key: A primary key value.
|
||||
/// - returns: An optional record.
|
||||
@warn_unused_result
|
||||
public static func fetchOne<PrimaryKeyType: DatabaseValueConvertible>(_ db: Database, key: PrimaryKeyType?) -> Self? {
|
||||
guard let key = key else {
|
||||
return nil
|
||||
@@ -72,7 +69,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
// Returns "SELECT * FROM table WHERE id IN (?,?,?)"
|
||||
//
|
||||
// Returns nil if values is empty.
|
||||
@warn_unused_result
|
||||
private static func fetchByPrimaryKeyStatement<Sequence: Swift.Sequence where Sequence.Iterator.Element: DatabaseValueConvertible>(_ db: Database, values: Sequence) -> SelectStatement? {
|
||||
// Fail early if database table does not exist.
|
||||
let databaseTableName = self.databaseTableName()
|
||||
@@ -117,7 +113,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// - db: A Database.
|
||||
/// - keys: An array of key dictionaries.
|
||||
/// - returns: A sequence of records.
|
||||
@warn_unused_result
|
||||
public static func fetch(_ db: Database, keys: [[String: DatabaseValueConvertible?]]) -> DatabaseSequence<Self> {
|
||||
guard let statement = fetchByKeyStatement(db, keys: keys) else {
|
||||
return DatabaseSequence.makeEmptySequence(inDatabase: db)
|
||||
@@ -135,7 +130,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// - db: A database connection.
|
||||
/// - keys: An array of key dictionaries.
|
||||
/// - returns: An array of records.
|
||||
@warn_unused_result
|
||||
public static func fetchAll(_ db: Database, keys: [[String: DatabaseValueConvertible?]]) -> [Self] {
|
||||
guard let statement = fetchByKeyStatement(db, keys: keys) else {
|
||||
return []
|
||||
@@ -151,7 +145,6 @@ extension RowConvertible where Self: TableMapping {
|
||||
/// - db: A database connection.
|
||||
/// - key: A dictionary of values.
|
||||
/// - returns: An optional record.
|
||||
@warn_unused_result
|
||||
public static func fetchOne(_ db: Database, key: [String: DatabaseValueConvertible?]) -> Self? {
|
||||
return fetchOne(fetchByKeyStatement(db, keys: [key])!)
|
||||
}
|
||||
@@ -159,11 +152,10 @@ extension RowConvertible where Self: TableMapping {
|
||||
// Returns "SELECT * FROM table WHERE (a = ? AND b = ?) OR (a = ? AND b = ?) ...
|
||||
//
|
||||
// Returns nil if keys is empty.
|
||||
@warn_unused_result
|
||||
private static func fetchByKeyStatement(_ db: Database, keys: [[String: DatabaseValueConvertible?]]) -> SelectStatement? {
|
||||
// TODO: this method is slow to compile
|
||||
// https://medium.com/swift-programming/speeding-up-slow-swift-build-times-922feeba5780#.s77wmh4h0
|
||||
// 586.8ms /Users/groue/Documents/git/groue/GRDB.swift/GRDB/Record/TableMapping.swift:163:25 @warn_unused_result private static func fetchByKeyStatement(_ db: Database, keys: [[String : DatabaseValueConvertible?]]) -> SelectStatement?
|
||||
// 586.8ms /Users/groue/Documents/git/groue/GRDB.swift/GRDB/Record/TableMapping.swift:163:25 private static func fetchByKeyStatement(_ db: Database, keys: [[String : DatabaseValueConvertible?]]) -> SelectStatement?
|
||||
|
||||
// Avoid performing useless SELECT
|
||||
guard keys.count > 0 else {
|
||||
|
||||
@@ -28,7 +28,7 @@ class DatabaseQueueuReleaseMemoryTests: GRDBTestCase {
|
||||
|
||||
do {
|
||||
// Open & release connection
|
||||
try makeDatabaseQueue()
|
||||
_ = try makeDatabaseQueue()
|
||||
}
|
||||
|
||||
// One reader, one writer
|
||||
|
||||
@@ -11,7 +11,7 @@ class ReadOnlyDatabaseTests : GRDBTestCase {
|
||||
assertNoError {
|
||||
// Create database
|
||||
do {
|
||||
try makeDatabaseQueue()
|
||||
_ = try makeDatabaseQueue()
|
||||
}
|
||||
|
||||
// Open it again, readonly
|
||||
|
||||
@@ -77,9 +77,9 @@ private struct MutablePersistableCustomizedCountry : MutablePersistable {
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(_ db: Database) throws {
|
||||
func delete(_ db: Database) throws -> Bool {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
return try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(_ db: Database) -> Bool {
|
||||
@@ -475,7 +475,8 @@ class MutablePersistableTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[1].value(named: "rowID") as Int64, country2.rowID!)
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
|
||||
try country1.delete(db)
|
||||
// TODO: test delete return value
|
||||
_ = try country1.delete(db)
|
||||
try country1.save(db)
|
||||
|
||||
XCTAssertEqual(insertCount, 2)
|
||||
@@ -524,7 +525,8 @@ class MutablePersistableTests: GRDBTestCase {
|
||||
willExists: { })
|
||||
try country2.insert(db)
|
||||
|
||||
try country1.delete(db)
|
||||
// TODO: test delete return value
|
||||
_ = try country1.delete(db)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
@@ -567,7 +569,8 @@ class MutablePersistableTests: GRDBTestCase {
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 1)
|
||||
|
||||
try country.delete(db)
|
||||
// TODO: test delete return value
|
||||
_ = try country.delete(db)
|
||||
|
||||
XCTAssertFalse(country.exists(db))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
|
||||
@@ -87,9 +87,9 @@ private struct PersistableCustomizedCountry : Persistable {
|
||||
try performSave(db)
|
||||
}
|
||||
|
||||
func delete(_ db: Database) throws {
|
||||
func delete(_ db: Database) throws -> Bool {
|
||||
willDelete()
|
||||
try performDelete(db)
|
||||
return try performDelete(db)
|
||||
}
|
||||
|
||||
func exists(_ db: Database) -> Bool {
|
||||
@@ -530,7 +530,8 @@ class PersistableTests: GRDBTestCase {
|
||||
XCTAssertEqual(rows[1].value(named: "isoCode") as String, "US")
|
||||
XCTAssertEqual(rows[1].value(named: "name") as String, "United States")
|
||||
|
||||
try country1.delete(db)
|
||||
// TODO: test delete return value
|
||||
_ = try country1.delete(db)
|
||||
try country1.save(db)
|
||||
|
||||
XCTAssertEqual(insertCount, 2)
|
||||
@@ -577,7 +578,8 @@ class PersistableTests: GRDBTestCase {
|
||||
willExists: { })
|
||||
try country2.insert(db)
|
||||
|
||||
try country1.delete(db)
|
||||
// TODO: test delete return value
|
||||
_ = try country1.delete(db)
|
||||
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
XCTAssertEqual(updateCount, 0)
|
||||
@@ -619,7 +621,8 @@ class PersistableTests: GRDBTestCase {
|
||||
XCTAssertEqual(deleteCount, 0)
|
||||
XCTAssertEqual(existsCount, 1)
|
||||
|
||||
try country.delete(db)
|
||||
// TODO: test delete return value
|
||||
_ = try country.delete(db)
|
||||
|
||||
XCTAssertFalse(country.exists(db))
|
||||
XCTAssertEqual(insertCount, 1)
|
||||
|
||||
Reference in new issue
Block a user