mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
Remove a bunch of self.
This commit is contained in:
1 parent
b445471d76
commit
bf48bd6ac2
6 files changed
+33
-33
No files matched your search
@@ -80,14 +80,14 @@ public final class Database {
|
||||
public func executeMultiStatement(sql: String) throws -> DatabaseChanges {
|
||||
assertValidQueue()
|
||||
|
||||
let changedRowsBefore = sqlite3_total_changes(self.sqliteConnection)
|
||||
let changedRowsBefore = sqlite3_total_changes(sqliteConnection)
|
||||
|
||||
let code = sqlite3_exec(self.sqliteConnection, sql, nil, nil, nil)
|
||||
let code = sqlite3_exec(sqliteConnection, sql, nil, nil, nil)
|
||||
guard code == SQLITE_OK else {
|
||||
throw DatabaseError(code: code, message: lastErrorMessage, sql: sql, arguments: nil)
|
||||
}
|
||||
|
||||
let changedRowsAfter = sqlite3_total_changes(self.sqliteConnection)
|
||||
let changedRowsAfter = sqlite3_total_changes(sqliteConnection)
|
||||
return DatabaseChanges(changedRowCount: changedRowsAfter - changedRowsBefore, insertedRowID: nil)
|
||||
}
|
||||
|
||||
@@ -312,7 +312,7 @@ public final class Database {
|
||||
|
||||
case .Callback(let callback):
|
||||
let dbPointer = unsafeBitCast(self, UnsafeMutablePointer<Void>.self)
|
||||
self.busyCallback = callback
|
||||
busyCallback = callback
|
||||
|
||||
sqlite3_busy_handler(
|
||||
sqliteConnection,
|
||||
|
||||
@@ -55,17 +55,17 @@ public struct DatabaseValue : Hashable {
|
||||
|
||||
/// Returns a DatabaseValue storing an Integer.
|
||||
public init(int64: Swift.Int64) {
|
||||
self.storage = .Int64(int64)
|
||||
storage = .Int64(int64)
|
||||
}
|
||||
|
||||
/// Returns a DatabaseValue storing an Double.
|
||||
public init(double: Swift.Double) {
|
||||
self.storage = .Double(double)
|
||||
storage = .Double(double)
|
||||
}
|
||||
|
||||
/// Returns a DatabaseValue storing a String.
|
||||
public init(string: Swift.String) {
|
||||
self.storage = .String(string)
|
||||
storage = .String(string)
|
||||
}
|
||||
|
||||
/// Returns a DatabaseValue storing NSData.
|
||||
@@ -75,9 +75,9 @@ public struct DatabaseValue : Hashable {
|
||||
public init(data: NSData) {
|
||||
if data.length == 0 {
|
||||
// SQLite cant' store zero-length blobs.
|
||||
self.storage = .Null
|
||||
storage = .Null
|
||||
} else {
|
||||
self.storage = .Blob(data)
|
||||
storage = .Blob(data)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -170,18 +170,18 @@ public struct DatabaseValue : Hashable {
|
||||
init(sqliteStatement: SQLiteStatement, index: Int) {
|
||||
switch sqlite3_column_type(sqliteStatement, Int32(index)) {
|
||||
case SQLITE_NULL:
|
||||
self.storage = .Null
|
||||
storage = .Null
|
||||
case SQLITE_INTEGER:
|
||||
self.storage = .Int64(sqlite3_column_int64(sqliteStatement, Int32(index)))
|
||||
storage = .Int64(sqlite3_column_int64(sqliteStatement, Int32(index)))
|
||||
case SQLITE_FLOAT:
|
||||
self.storage = .Double(sqlite3_column_double(sqliteStatement, Int32(index)))
|
||||
storage = .Double(sqlite3_column_double(sqliteStatement, Int32(index)))
|
||||
case SQLITE_TEXT:
|
||||
let cString = UnsafePointer<Int8>(sqlite3_column_text(sqliteStatement, Int32(index)))
|
||||
self.storage = .String(Swift.String.fromCString(cString)!)
|
||||
storage = .String(Swift.String.fromCString(cString)!)
|
||||
case SQLITE_BLOB:
|
||||
let bytes = sqlite3_column_blob(sqliteStatement, Int32(index))
|
||||
let length = sqlite3_column_bytes(sqliteStatement, Int32(index))
|
||||
self.storage = .Blob(NSData(bytes: bytes, length: Int(length))) // copy bytes
|
||||
storage = .Blob(NSData(bytes: bytes, length: Int(length))) // copy bytes
|
||||
default:
|
||||
fatalError("Unexpected SQLite column type")
|
||||
}
|
||||
@@ -190,18 +190,18 @@ public struct DatabaseValue : Hashable {
|
||||
init(sqliteValue: SQLiteValue) {
|
||||
switch sqlite3_value_type(sqliteValue) {
|
||||
case SQLITE_NULL:
|
||||
self.storage = .Null
|
||||
storage = .Null
|
||||
case SQLITE_INTEGER:
|
||||
self.storage = .Int64(sqlite3_value_int64(sqliteValue))
|
||||
storage = .Int64(sqlite3_value_int64(sqliteValue))
|
||||
case SQLITE_FLOAT:
|
||||
self.storage = .Double(sqlite3_value_double(sqliteValue))
|
||||
storage = .Double(sqlite3_value_double(sqliteValue))
|
||||
case SQLITE_TEXT:
|
||||
let cString = UnsafePointer<Int8>(sqlite3_value_text(sqliteValue))
|
||||
self.storage = .String(Swift.String.fromCString(cString)!)
|
||||
storage = .String(Swift.String.fromCString(cString)!)
|
||||
case SQLITE_BLOB:
|
||||
let bytes = sqlite3_value_blob(sqliteValue)
|
||||
let length = sqlite3_value_bytes(sqliteValue)
|
||||
self.storage = .Blob(NSData(bytes: bytes, length: Int(length))) // copy bytes
|
||||
storage = .Blob(NSData(bytes: bytes, length: Int(length))) // copy bytes
|
||||
default:
|
||||
fatalError("Unexpected SQLite value type")
|
||||
}
|
||||
|
||||
@@ -59,7 +59,7 @@ extension DatabaseTableMapping {
|
||||
guard let key = key else {
|
||||
return nil
|
||||
}
|
||||
return self.fetchOne(self.fetchByPrimaryKeyStatement(db, keys: [key])!)
|
||||
return fetchOne(fetchByPrimaryKeyStatement(db, keys: [key])!)
|
||||
}
|
||||
|
||||
// Returns "SELECT * FROM table WHERE id IN (?,?,?)"
|
||||
@@ -67,7 +67,7 @@ extension DatabaseTableMapping {
|
||||
// Returns nil if keys is empty.
|
||||
private static func fetchByPrimaryKeyStatement<Sequence: SequenceType where Sequence.Generator.Element: DatabaseValueConvertible>(db: Database, keys: Sequence) -> SelectStatement? {
|
||||
// Fail early if databaseTable is nil
|
||||
guard let databaseTableName = self.databaseTableName() else {
|
||||
guard let databaseTableName = databaseTableName() else {
|
||||
fatalError("Nil returned from \(self).databaseTableName()")
|
||||
}
|
||||
|
||||
@@ -117,10 +117,10 @@ extension DatabaseTableMapping {
|
||||
/// - parameter keys: An array of key dictionaries.
|
||||
/// - returns: A sequence.
|
||||
public static func fetch(db: Database, keys: [[String: DatabaseValueConvertible?]]) -> DatabaseSequence<Self> {
|
||||
guard let statement = self.fetchByKeyStatement(db, keys: keys) else {
|
||||
guard let statement = fetchByKeyStatement(db, keys: keys) else {
|
||||
return DatabaseSequence()
|
||||
}
|
||||
return self.fetch(statement)
|
||||
return fetch(statement)
|
||||
}
|
||||
|
||||
/// Returns an array of values, given an array of key dictionaries.
|
||||
@@ -133,10 +133,10 @@ extension DatabaseTableMapping {
|
||||
/// - parameter keys: An array of key dictionaries.
|
||||
/// - returns: An array.
|
||||
public static func fetchAll(db: Database, keys: [[String: DatabaseValueConvertible?]]) -> [Self] {
|
||||
guard let statement = self.fetchByKeyStatement(db, keys: keys) else {
|
||||
guard let statement = fetchByKeyStatement(db, keys: keys) else {
|
||||
return []
|
||||
}
|
||||
return self.fetchAll(statement)
|
||||
return fetchAll(statement)
|
||||
}
|
||||
|
||||
/// Returns a single value given a key dictionary.
|
||||
@@ -147,7 +147,7 @@ extension DatabaseTableMapping {
|
||||
/// - parameter key: A dictionary of values.
|
||||
/// - returns: An optional value.
|
||||
public static func fetchOne(db: Database, key: [String: DatabaseValueConvertible?]) -> Self? {
|
||||
return self.fetchOne(self.fetchByKeyStatement(db, keys: [key])!)
|
||||
return fetchOne(fetchByKeyStatement(db, keys: [key])!)
|
||||
}
|
||||
|
||||
// Returns "SELECT * FROM table WHERE (a = ? AND b = ?) OR (a = ? AND b = ?) ...
|
||||
@@ -155,7 +155,7 @@ extension DatabaseTableMapping {
|
||||
// Returns nil if keys is empty.
|
||||
private static func fetchByKeyStatement(db: Database, keys: [[String: DatabaseValueConvertible?]]) -> SelectStatement? {
|
||||
// Fail early if databaseTable is nil
|
||||
guard let databaseTableName = self.databaseTableName() else {
|
||||
guard let databaseTableName = databaseTableName() else {
|
||||
fatalError("Nil returned from \(self).databaseTableName()")
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -439,8 +439,8 @@ public final class Row: CollectionType {
|
||||
/// Returns the (ColumnName, DatabaseValue) pair at given index.
|
||||
public subscript(index: RowIndex) -> (String, DatabaseValue) {
|
||||
return (
|
||||
self.impl.columnName(atIndex: index.index),
|
||||
self.impl.databaseValue(atIndex: index.index))
|
||||
impl.columnName(atIndex: index.index),
|
||||
impl.databaseValue(atIndex: index.index))
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ public final class UpdateStatement : Statement {
|
||||
// TransactionObserverType.transactionWillCommit().
|
||||
// Let database handle this case, before throwing a error.
|
||||
try database.updateStatementDidFail()
|
||||
throw DatabaseError(code: code, message: database.lastErrorMessage, sql: sql, arguments: self.arguments)
|
||||
throw DatabaseError(code: code, message: database.lastErrorMessage, sql: sql, arguments: arguments)
|
||||
}
|
||||
|
||||
let changedRowCount = Int(sqlite3_changes(database.sqliteConnection))
|
||||
|
||||
@@ -160,8 +160,8 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabaseStorable {
|
||||
/// - returns: A copy of self.
|
||||
@warn_unused_result
|
||||
public func copy() -> Self {
|
||||
let copy = self.dynamicType.init(row: Row(dictionary: self.storedDatabaseDictionary))
|
||||
copy.referenceRow = self.referenceRow
|
||||
let copy = self.dynamicType.init(row: Row(dictionary: storedDatabaseDictionary))
|
||||
copy.referenceRow = referenceRow
|
||||
return copy
|
||||
}
|
||||
|
||||
@@ -218,7 +218,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabaseStorable {
|
||||
// A change generator that is used by both databaseEdited and
|
||||
// databaseChanges properties.
|
||||
private func generateDatabaseChanges() -> AnyGenerator<(column: String, old: DatabaseValue?, new: DatabaseValue)> {
|
||||
let oldRow = self.referenceRow
|
||||
let oldRow = referenceRow
|
||||
var newValueGenerator = storedDatabaseDictionary.generate()
|
||||
return anyGenerator {
|
||||
// Loop until we find a change, or exhaust columns:
|
||||
|
||||
Reference in new issue
Block a user