mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-29 04:24:21 +00:00
minor
This commit is contained in:
1 parent
c8cf0df6e1
commit
32b9971cfa
9 files changed
+30
-37
No files matched your search
@@ -22,7 +22,7 @@ class RowFoundationTests: GRDBTestCase {
|
||||
|
||||
func testRowToNSDictionary() {
|
||||
let row = Row(dictionary: ["a": "foo", "b": 1, "c": nil, "d": NSDate(timeIntervalSince1970: 1443642439)])
|
||||
let dictionary = row.toDictionary()
|
||||
let dictionary = row.toNSDictionary()
|
||||
XCTAssertEqual(dictionary.count, 4)
|
||||
XCTAssertTrue((dictionary["a"] as! NSString).isEqualToString("foo"))
|
||||
XCTAssertTrue((dictionary["b"] as! NSNumber).isEqualToNumber(NSNumber(integer: 1)))
|
||||
|
||||
@@ -30,6 +30,7 @@ public struct DatabaseValue : Equatable {
|
||||
/// Returns a DatabaseValue storing NSData.
|
||||
public init(data: NSData) {
|
||||
if data.length == 0 {
|
||||
// SQLite cant' store zero-length blobs.
|
||||
self.storage = .Null
|
||||
} else {
|
||||
self.storage = .Blob(data)
|
||||
@@ -102,11 +103,10 @@ public struct DatabaseValue : Equatable {
|
||||
///
|
||||
/// - returns: A *Value*.
|
||||
public func value<Value: DatabaseValueConvertible>() -> Value {
|
||||
if let value = Value.fromDatabaseValue(self) as Value? {
|
||||
return value
|
||||
} else {
|
||||
guard let value = Value.fromDatabaseValue(self) as Value? else {
|
||||
fatalError("Could not convert \(self) to \(Value.self).")
|
||||
}
|
||||
return value
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -51,12 +51,11 @@ public struct DatabaseDateComponents : DatabaseValueConvertible {
|
||||
/// the database.
|
||||
/// - returns: An optional DatabaseDateComponents.
|
||||
public init?(_ dateComponents: NSDateComponents?, format: Format) {
|
||||
if let dateComponents = dateComponents {
|
||||
self.format = format
|
||||
self.dateComponents = dateComponents
|
||||
} else {
|
||||
guard let dateComponents = dateComponents else {
|
||||
return nil
|
||||
}
|
||||
self.format = format
|
||||
self.dateComponents = dateComponents
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -49,8 +49,9 @@ extension NSDate : DatabaseValueConvertible {
|
||||
|
||||
let date = UTCCalendar.dateFromComponents(dateComponents)!
|
||||
return self.init(timeInterval: 0, sinceDate: date)
|
||||
|
||||
} else if let databaseDateComponents = DatabaseDateComponents.fromDatabaseValue(databaseValue) {
|
||||
}
|
||||
|
||||
if let databaseDateComponents = DatabaseDateComponents.fromDatabaseValue(databaseValue) {
|
||||
// Date components
|
||||
|
||||
switch databaseDateComponents.format {
|
||||
@@ -63,9 +64,9 @@ extension NSDate : DatabaseValueConvertible {
|
||||
// dangerous.
|
||||
return nil
|
||||
}
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -13,10 +13,9 @@ extension NSString: DatabaseValueConvertible {
|
||||
/// - parameter databaseValue: A DatabaseValue.
|
||||
/// - returns: An optional NSString.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
if let string = String.fromDatabaseValue(databaseValue) {
|
||||
return self.init(string: string)
|
||||
} else {
|
||||
guard let string = String.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(string: string)
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,9 @@ extension NSURL : DatabaseValueConvertible {
|
||||
/// - parameter databaseValue: A DatabaseValue.
|
||||
/// - returns: An optional NSURL.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
if let string = String.fromDatabaseValue(databaseValue) {
|
||||
return self.init(string: string)
|
||||
} else {
|
||||
guard let string = String.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(string: string)
|
||||
}
|
||||
}
|
||||
@@ -5,10 +5,10 @@ struct Migration {
|
||||
let block: (db: Database) throws -> Void
|
||||
|
||||
func run(db: Database) throws {
|
||||
if self.disableForeignKeys && Bool.fetchOne(db, "PRAGMA foreign_keys")! {
|
||||
try self.runWithDisabledForeignKeys(db)
|
||||
if disableForeignKeys && Bool.fetchOne(db, "PRAGMA foreign_keys")! {
|
||||
try runWithDisabledForeignKeys(db)
|
||||
} else {
|
||||
try self.runWithoutDisabledForeignKeys(db)
|
||||
try runWithoutDisabledForeignKeys(db)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -340,12 +340,11 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabaseStorable {
|
||||
/// not match any row in the database and record could not be reloaded.
|
||||
public func reload(db: Database) throws {
|
||||
let statement = DataMapper(db, self).reloadStatement()
|
||||
if let row = Row.fetchOne(statement) {
|
||||
updateFromRow(row)
|
||||
awakeFromFetch(row)
|
||||
} else {
|
||||
guard let row = Row.fetchOne(statement) else {
|
||||
throw RecordError.RecordNotFound(self)
|
||||
}
|
||||
updateFromRow(row)
|
||||
awakeFromFetch(row)
|
||||
}
|
||||
|
||||
/// Returns true if and only if the primary key matches a row in
|
||||
|
||||
@@ -33,11 +33,10 @@ extension DatabaseIntRepresentable {
|
||||
/// - parameter databaseValue: A DatabaseValue.
|
||||
/// - returns: An optional Self.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
if let int = Int.fromDatabaseValue(databaseValue) {
|
||||
return self.init(rawValue: int)
|
||||
} else {
|
||||
guard let int = Int.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: int)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -77,11 +76,10 @@ extension DatabaseInt32Representable {
|
||||
/// - parameter databaseValue: A DatabaseValue.
|
||||
/// - returns: An optional Self.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
if let int = Int32.fromDatabaseValue(databaseValue) {
|
||||
return self.init(rawValue: int)
|
||||
} else {
|
||||
guard let int = Int32.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: int)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,11 +119,10 @@ extension DatabaseInt64Representable {
|
||||
/// - parameter databaseValue: A DatabaseValue.
|
||||
/// - returns: An optional Self.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
if let int = Int64.fromDatabaseValue(databaseValue) {
|
||||
return self.init(rawValue: int)
|
||||
} else {
|
||||
guard let int = Int64.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: int)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,10 +162,9 @@ extension DatabaseStringRepresentable {
|
||||
/// - parameter databaseValue: A DatabaseValue.
|
||||
/// - returns: An optional Self.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
if let string = String.fromDatabaseValue(databaseValue) {
|
||||
return self.init(rawValue: string)
|
||||
} else {
|
||||
guard let string = String.fromDatabaseValue(databaseValue) else {
|
||||
return nil
|
||||
}
|
||||
return self.init(rawValue: string)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user