mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-28 04:24:20 +00:00
merge
This commit is contained in:
commit
32f73fb816
58 files changed
+780
-720
No files matched your search
+32
-6
@@ -1,16 +1,42 @@
|
||||
Release Notes
|
||||
=============
|
||||
|
||||
## 0.35.0
|
||||
## Next Release
|
||||
|
||||
The Record class has been refactored so that it gets closer from its RowConvertible and DatabasePersistable adopted protocols.
|
||||
The Record class has been refactored so that it gets closer from the RowConvertible and DatabasePersistable protocols. It also makes it easier to write subclasses that have non-optional properties.
|
||||
|
||||
Methods names that did not match [Swift 3 API Design Guidelines](https://swift.org/documentation/api-design-guidelines.html) have been refactored.
|
||||
|
||||
**New**
|
||||
|
||||
- `Float` adopts DatabaseValueConvertible, and can be stored and fetched from the database without Double conversion ([documentation](https://github.com/groue/GRDB.swift#values)).
|
||||
|
||||
**Breaking Changes**
|
||||
|
||||
- `Record.reload()` has been removed.
|
||||
- `Record.updateFromRow()` has been removed. Override `init(row:)` instead.
|
||||
- `Record.didInsertWithRowID(_:forColumn:)` should be overriden by Record subclasses that are interested with their inserted rowID.
|
||||
- `Row.value(named:)` returns nil if no such column exists in the row.
|
||||
DatabasePersistable:
|
||||
|
||||
- `DatabasePersistable.storedDatabaseDictionary` has been renamed `persistentDictionary` ([documentation](https://github.com/groue/GRDB.swift#databasepersistable-protocol)).
|
||||
|
||||
Row:
|
||||
|
||||
- `Row.value(named:)` returns nil if no such column exists in the row. It used to crash with a fatal error ([documentation](https://github.com/groue/GRDB.swift#column-values)).
|
||||
|
||||
DatabaseValue:
|
||||
|
||||
- `DatabaseValue` has no public initializers. To create one, use `DatabaseValue.Null`, or the fact that Int, String, etc. adopt the protocol: `1.databaseValue`, `"foo".databaseValue` ([documentation](https://github.com/groue/GRDB.swift#custom-value-types)).
|
||||
|
||||
Record ([documentation](https://github.com/groue/GRDB.swift#record)):
|
||||
|
||||
- `Record.reload()` has been removed. You have to provide your own implementation, should you need reloading.
|
||||
- `Record.init(row: Row)` has been renamed `Record.init(_ row: Row)` (unlabelled row argument).
|
||||
- `Record.updateFromRow()` has been removed. Override `init(_ row: Row)` instead.
|
||||
- `Record.didInsertWithRowID(_:forColumn:)` should be overriden by Record subclasses that are interested with their row ids.
|
||||
- `Record.databaseEdited` has been renamed `hasPersistentChangedValues`.
|
||||
- `Record.databaseChanges` has been renamed `persistentChangedValues` and now returns `[String: DatabaseValue?]`, the dictionary of old values for changed columns.
|
||||
|
||||
DatabaseMigrator:
|
||||
|
||||
- `DatabaseMigrator.registerMigrationWithoutForeignKeyChecks(_:_:)` has been renamed `DatabaseMigrator.registerMigration(_:withDisabledForeignKeyChecks:migrate:)` ([documentation](https://github.com/groue/GRDB.swift#advanced-database-schema-changes)).
|
||||
|
||||
|
||||
## 0.34.0
|
||||
|
||||
@@ -14,20 +14,22 @@ class Person : Record {
|
||||
super.init()
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Record
|
||||
|
||||
override class func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
firstName = row.value(named: "firstName")
|
||||
lastName = row.value(named: "lastName")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return [
|
||||
"id": id,
|
||||
"firstName": firstName,
|
||||
@@ -35,7 +37,7 @@ class Person : Record {
|
||||
}
|
||||
|
||||
override func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.id = rowID
|
||||
id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -12,39 +12,42 @@
|
||||
562FF99A1BCE8FA400759400 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 562FF9981BCE8FA400759400 /* Main.storyboard */; };
|
||||
562FF99C1BCE8FA400759400 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 562FF99B1BCE8FA400759400 /* Assets.xcassets */; };
|
||||
562FF99F1BCE8FA400759400 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 562FF99D1BCE8FA400759400 /* LaunchScreen.storyboard */; };
|
||||
562FF9CD1BCE902400759400 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9AA1BCE902400759400 /* Configuration.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9CE1BCE902400759400 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9AB1BCE902400759400 /* Database.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9CF1BCE902400759400 /* DatabaseChanges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9AC1BCE902400759400 /* DatabaseChanges.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D01BCE902400759400 /* DatabaseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9AD1BCE902400759400 /* DatabaseError.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D11BCE902400759400 /* DatabaseQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9AE1BCE902400759400 /* DatabaseQueue.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D21BCE902400759400 /* DatabaseValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9AF1BCE902400759400 /* DatabaseValue.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D31BCE902400759400 /* DatabaseTableMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B11BCE902400759400 /* DatabaseTableMapping.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D41BCE902400759400 /* DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B21BCE902400759400 /* DatabaseValueConvertible.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D51BCE902400759400 /* RowConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B31BCE902400759400 /* RowConvertible.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D61BCE902400759400 /* SQLiteStatementConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B41BCE902400759400 /* SQLiteStatementConvertible.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D71BCE902400759400 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B51BCE902400759400 /* Row.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D81BCE902400759400 /* SelectStatement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B61BCE902400759400 /* SelectStatement.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9D91BCE902400759400 /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B71BCE902400759400 /* Statement.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9DA1BCE902400759400 /* StatementArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B81BCE902400759400 /* StatementArguments.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9DB1BCE902400759400 /* UpdateStatement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9B91BCE902400759400 /* UpdateStatement.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9DC1BCE902400759400 /* DatabaseDateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9BB1BCE902400759400 /* DatabaseDateComponents.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9DD1BCE902400759400 /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9BC1BCE902400759400 /* NSData.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9DE1BCE902400759400 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9BD1BCE902400759400 /* NSDate.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9DF1BCE902400759400 /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9BE1BCE902400759400 /* NSNull.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E01BCE902400759400 /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9BF1BCE902400759400 /* NSNumber.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E11BCE902400759400 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C01BCE902400759400 /* NSString.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E21BCE902400759400 /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C11BCE902400759400 /* NSURL.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E31BCE902400759400 /* Row+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C21BCE902400759400 /* Row+Foundation.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E41BCE902400759400 /* RowConvertible+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C31BCE902400759400 /* RowConvertible+Foundation.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E51BCE902400759400 /* StatementArguments+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C41BCE902400759400 /* StatementArguments+Foundation.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E61BCE902400759400 /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C61BCE902400759400 /* DatabaseMigrator.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E71BCE902400759400 /* DatabaseStorable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C81BCE902400759400 /* DatabaseStorable.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E81BCE902400759400 /* Record.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9C91BCE902400759400 /* Record.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9E91BCE902400759400 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9CB1BCE902400759400 /* RawRepresentable.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9EA1BCE902400759400 /* StandardLibraryTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9CC1BCE902400759400 /* StandardLibraryTypes.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9EC1BCE903D00759400 /* libsqlite3.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = 562FF9EB1BCE903D00759400 /* libsqlite3.tbd */; };
|
||||
562FF9EF1BCE912C00759400 /* PersonEditionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9EE1BCE912C00759400 /* PersonEditionViewController.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9F21BCE914E00759400 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9F11BCE914E00759400 /* Person.swift */; settings = {ASSET_TAGS = (); }; };
|
||||
562FF9EF1BCE912C00759400 /* PersonEditionViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9EE1BCE912C00759400 /* PersonEditionViewController.swift */; };
|
||||
562FF9F21BCE914E00759400 /* Person.swift in Sources */ = {isa = PBXBuildFile; fileRef = 562FF9F11BCE914E00759400 /* Person.swift */; };
|
||||
56FCB3691C21210B00305D10 /* Configuration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3421C21210B00305D10 /* Configuration.swift */; };
|
||||
56FCB36A1C21210B00305D10 /* Database.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3431C21210B00305D10 /* Database.swift */; };
|
||||
56FCB36B1C21210B00305D10 /* DatabaseChanges.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3441C21210B00305D10 /* DatabaseChanges.swift */; };
|
||||
56FCB36C1C21210B00305D10 /* DatabaseError.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3451C21210B00305D10 /* DatabaseError.swift */; };
|
||||
56FCB36D1C21210B00305D10 /* DatabaseQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3461C21210B00305D10 /* DatabaseQueue.swift */; };
|
||||
56FCB36E1C21210B00305D10 /* DatabaseValue.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3471C21210B00305D10 /* DatabaseValue.swift */; };
|
||||
56FCB36F1C21210B00305D10 /* DatabasePersistable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3491C21210B00305D10 /* DatabasePersistable.swift */; };
|
||||
56FCB3701C21210B00305D10 /* DatabaseTableMapping.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB34A1C21210B00305D10 /* DatabaseTableMapping.swift */; };
|
||||
56FCB3711C21210B00305D10 /* DatabaseValueConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB34B1C21210B00305D10 /* DatabaseValueConvertible.swift */; };
|
||||
56FCB3721C21210B00305D10 /* RowConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB34C1C21210B00305D10 /* RowConvertible.swift */; };
|
||||
56FCB3731C21210B00305D10 /* SQLiteStatementConvertible.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB34D1C21210B00305D10 /* SQLiteStatementConvertible.swift */; };
|
||||
56FCB3741C21210B00305D10 /* Row.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB34E1C21210B00305D10 /* Row.swift */; };
|
||||
56FCB3751C21210B00305D10 /* SelectStatement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB34F1C21210B00305D10 /* SelectStatement.swift */; };
|
||||
56FCB3761C21210B00305D10 /* Statement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3501C21210B00305D10 /* Statement.swift */; };
|
||||
56FCB3771C21210B00305D10 /* StatementArguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3511C21210B00305D10 /* StatementArguments.swift */; };
|
||||
56FCB3781C21210B00305D10 /* UpdateStatement.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3521C21210B00305D10 /* UpdateStatement.swift */; };
|
||||
56FCB3791C21210B00305D10 /* CGFloat.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3541C21210B00305D10 /* CGFloat.swift */; };
|
||||
56FCB37A1C21210B00305D10 /* DatabaseCoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3561C21210B00305D10 /* DatabaseCoder.swift */; };
|
||||
56FCB37B1C21210B00305D10 /* DatabaseDateComponents.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3571C21210B00305D10 /* DatabaseDateComponents.swift */; };
|
||||
56FCB37C1C21210B00305D10 /* DatabaseValue+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3581C21210B00305D10 /* DatabaseValue+Foundation.swift */; };
|
||||
56FCB37D1C21210B00305D10 /* NSData.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3591C21210B00305D10 /* NSData.swift */; };
|
||||
56FCB37E1C21210B00305D10 /* NSDate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB35A1C21210B00305D10 /* NSDate.swift */; };
|
||||
56FCB37F1C21210B00305D10 /* NSNull.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB35B1C21210B00305D10 /* NSNull.swift */; };
|
||||
56FCB3801C21210B00305D10 /* NSNumber.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB35C1C21210B00305D10 /* NSNumber.swift */; };
|
||||
56FCB3811C21210B00305D10 /* NSString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB35D1C21210B00305D10 /* NSString.swift */; };
|
||||
56FCB3821C21210B00305D10 /* NSURL.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB35E1C21210B00305D10 /* NSURL.swift */; };
|
||||
56FCB3831C21210B00305D10 /* Row+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB35F1C21210B00305D10 /* Row+Foundation.swift */; };
|
||||
56FCB3841C21210B00305D10 /* StatementArguments+Foundation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3601C21210B00305D10 /* StatementArguments+Foundation.swift */; };
|
||||
56FCB3851C21210B00305D10 /* DatabaseMigrator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3621C21210B00305D10 /* DatabaseMigrator.swift */; };
|
||||
56FCB3861C21210B00305D10 /* Migration.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3631C21210B00305D10 /* Migration.swift */; };
|
||||
56FCB3871C21210B00305D10 /* Record.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3651C21210B00305D10 /* Record.swift */; };
|
||||
56FCB3881C21210B00305D10 /* RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3671C21210B00305D10 /* RawRepresentable.swift */; };
|
||||
56FCB3891C21210B00305D10 /* StandardLibraryTypes.swift in Sources */ = {isa = PBXBuildFile; fileRef = 56FCB3681C21210B00305D10 /* StandardLibraryTypes.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@@ -55,40 +58,43 @@
|
||||
562FF99B1BCE8FA400759400 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
562FF99E1BCE8FA400759400 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
|
||||
562FF9A01BCE8FA400759400 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
|
||||
562FF9AA1BCE902400759400 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
|
||||
562FF9AB1BCE902400759400 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
|
||||
562FF9AC1BCE902400759400 /* DatabaseChanges.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseChanges.swift; sourceTree = "<group>"; };
|
||||
562FF9AD1BCE902400759400 /* DatabaseError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseError.swift; sourceTree = "<group>"; };
|
||||
562FF9AE1BCE902400759400 /* DatabaseQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueue.swift; sourceTree = "<group>"; };
|
||||
562FF9AF1BCE902400759400 /* DatabaseValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValue.swift; sourceTree = "<group>"; };
|
||||
562FF9B11BCE902400759400 /* DatabaseTableMapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTableMapping.swift; sourceTree = "<group>"; };
|
||||
562FF9B21BCE902400759400 /* DatabaseValueConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertible.swift; sourceTree = "<group>"; };
|
||||
562FF9B31BCE902400759400 /* RowConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowConvertible.swift; sourceTree = "<group>"; };
|
||||
562FF9B41BCE902400759400 /* SQLiteStatementConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLiteStatementConvertible.swift; sourceTree = "<group>"; };
|
||||
562FF9B51BCE902400759400 /* Row.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = "<group>"; };
|
||||
562FF9B61BCE902400759400 /* SelectStatement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatement.swift; sourceTree = "<group>"; };
|
||||
562FF9B71BCE902400759400 /* Statement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Statement.swift; sourceTree = "<group>"; };
|
||||
562FF9B81BCE902400759400 /* StatementArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArguments.swift; sourceTree = "<group>"; };
|
||||
562FF9B91BCE902400759400 /* UpdateStatement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateStatement.swift; sourceTree = "<group>"; };
|
||||
562FF9BB1BCE902400759400 /* DatabaseDateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateComponents.swift; sourceTree = "<group>"; };
|
||||
562FF9BC1BCE902400759400 /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = "<group>"; };
|
||||
562FF9BD1BCE902400759400 /* NSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDate.swift; sourceTree = "<group>"; };
|
||||
562FF9BE1BCE902400759400 /* NSNull.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNull.swift; sourceTree = "<group>"; };
|
||||
562FF9BF1BCE902400759400 /* NSNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNumber.swift; sourceTree = "<group>"; };
|
||||
562FF9C01BCE902400759400 /* NSString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSString.swift; sourceTree = "<group>"; };
|
||||
562FF9C11BCE902400759400 /* NSURL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSURL.swift; sourceTree = "<group>"; };
|
||||
562FF9C21BCE902400759400 /* Row+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+Foundation.swift"; sourceTree = "<group>"; };
|
||||
562FF9C31BCE902400759400 /* RowConvertible+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "RowConvertible+Foundation.swift"; sourceTree = "<group>"; };
|
||||
562FF9C41BCE902400759400 /* StatementArguments+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+Foundation.swift"; sourceTree = "<group>"; };
|
||||
562FF9C61BCE902400759400 /* DatabaseMigrator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigrator.swift; sourceTree = "<group>"; };
|
||||
562FF9C81BCE902400759400 /* DatabaseStorable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseStorable.swift; sourceTree = "<group>"; };
|
||||
562FF9C91BCE902400759400 /* Record.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Record.swift; sourceTree = "<group>"; };
|
||||
562FF9CB1BCE902400759400 /* RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = "<group>"; };
|
||||
562FF9CC1BCE902400759400 /* StandardLibraryTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibraryTypes.swift; sourceTree = "<group>"; };
|
||||
562FF9EB1BCE903D00759400 /* libsqlite3.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.tbd; path = usr/lib/libsqlite3.tbd; sourceTree = SDKROOT; };
|
||||
562FF9EE1BCE912C00759400 /* PersonEditionViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PersonEditionViewController.swift; sourceTree = "<group>"; };
|
||||
562FF9F11BCE914E00759400 /* Person.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Person.swift; sourceTree = "<group>"; };
|
||||
562FF9F41BCE930C00759400 /* GRDBDemoiOS7-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "GRDBDemoiOS7-Bridging-Header.h"; sourceTree = "<group>"; };
|
||||
56FCB3421C21210B00305D10 /* Configuration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Configuration.swift; sourceTree = "<group>"; };
|
||||
56FCB3431C21210B00305D10 /* Database.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Database.swift; sourceTree = "<group>"; };
|
||||
56FCB3441C21210B00305D10 /* DatabaseChanges.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseChanges.swift; sourceTree = "<group>"; };
|
||||
56FCB3451C21210B00305D10 /* DatabaseError.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseError.swift; sourceTree = "<group>"; };
|
||||
56FCB3461C21210B00305D10 /* DatabaseQueue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseQueue.swift; sourceTree = "<group>"; };
|
||||
56FCB3471C21210B00305D10 /* DatabaseValue.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValue.swift; sourceTree = "<group>"; };
|
||||
56FCB3491C21210B00305D10 /* DatabasePersistable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabasePersistable.swift; sourceTree = "<group>"; };
|
||||
56FCB34A1C21210B00305D10 /* DatabaseTableMapping.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseTableMapping.swift; sourceTree = "<group>"; };
|
||||
56FCB34B1C21210B00305D10 /* DatabaseValueConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseValueConvertible.swift; sourceTree = "<group>"; };
|
||||
56FCB34C1C21210B00305D10 /* RowConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RowConvertible.swift; sourceTree = "<group>"; };
|
||||
56FCB34D1C21210B00305D10 /* SQLiteStatementConvertible.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SQLiteStatementConvertible.swift; sourceTree = "<group>"; };
|
||||
56FCB34E1C21210B00305D10 /* Row.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Row.swift; sourceTree = "<group>"; };
|
||||
56FCB34F1C21210B00305D10 /* SelectStatement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SelectStatement.swift; sourceTree = "<group>"; };
|
||||
56FCB3501C21210B00305D10 /* Statement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Statement.swift; sourceTree = "<group>"; };
|
||||
56FCB3511C21210B00305D10 /* StatementArguments.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StatementArguments.swift; sourceTree = "<group>"; };
|
||||
56FCB3521C21210B00305D10 /* UpdateStatement.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = UpdateStatement.swift; sourceTree = "<group>"; };
|
||||
56FCB3541C21210B00305D10 /* CGFloat.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CGFloat.swift; sourceTree = "<group>"; };
|
||||
56FCB3561C21210B00305D10 /* DatabaseCoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseCoder.swift; sourceTree = "<group>"; };
|
||||
56FCB3571C21210B00305D10 /* DatabaseDateComponents.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseDateComponents.swift; sourceTree = "<group>"; };
|
||||
56FCB3581C21210B00305D10 /* DatabaseValue+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "DatabaseValue+Foundation.swift"; sourceTree = "<group>"; };
|
||||
56FCB3591C21210B00305D10 /* NSData.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSData.swift; sourceTree = "<group>"; };
|
||||
56FCB35A1C21210B00305D10 /* NSDate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSDate.swift; sourceTree = "<group>"; };
|
||||
56FCB35B1C21210B00305D10 /* NSNull.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNull.swift; sourceTree = "<group>"; };
|
||||
56FCB35C1C21210B00305D10 /* NSNumber.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSNumber.swift; sourceTree = "<group>"; };
|
||||
56FCB35D1C21210B00305D10 /* NSString.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSString.swift; sourceTree = "<group>"; };
|
||||
56FCB35E1C21210B00305D10 /* NSURL.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NSURL.swift; sourceTree = "<group>"; };
|
||||
56FCB35F1C21210B00305D10 /* Row+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "Row+Foundation.swift"; sourceTree = "<group>"; };
|
||||
56FCB3601C21210B00305D10 /* StatementArguments+Foundation.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "StatementArguments+Foundation.swift"; sourceTree = "<group>"; };
|
||||
56FCB3621C21210B00305D10 /* DatabaseMigrator.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DatabaseMigrator.swift; sourceTree = "<group>"; };
|
||||
56FCB3631C21210B00305D10 /* Migration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Migration.swift; sourceTree = "<group>"; };
|
||||
56FCB3651C21210B00305D10 /* Record.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Record.swift; sourceTree = "<group>"; };
|
||||
56FCB3671C21210B00305D10 /* RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = RawRepresentable.swift; sourceTree = "<group>"; };
|
||||
56FCB3681C21210B00305D10 /* StandardLibraryTypes.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StandardLibraryTypes.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@@ -154,89 +160,17 @@
|
||||
562FF9A81BCE900100759400 /* GRDB */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
562FF9A91BCE902400759400 /* Core */,
|
||||
562FF9BA1BCE902400759400 /* Foundation */,
|
||||
562FF9C51BCE902400759400 /* Migrations */,
|
||||
562FF9C71BCE902400759400 /* Record */,
|
||||
562FF9CA1BCE902400759400 /* Swift */,
|
||||
56FCB3411C21210B00305D10 /* Core */,
|
||||
56FCB3531C21210B00305D10 /* CoreGraphics */,
|
||||
56FCB3551C21210B00305D10 /* Foundation */,
|
||||
56FCB3611C21210B00305D10 /* Migrations */,
|
||||
56FCB3641C21210B00305D10 /* Record */,
|
||||
56FCB3661C21210B00305D10 /* Swift */,
|
||||
);
|
||||
name = GRDB;
|
||||
path = ../../GRDB;
|
||||
sourceTree = SOURCE_ROOT;
|
||||
};
|
||||
562FF9A91BCE902400759400 /* Core */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
562FF9AA1BCE902400759400 /* Configuration.swift */,
|
||||
562FF9AB1BCE902400759400 /* Database.swift */,
|
||||
562FF9AC1BCE902400759400 /* DatabaseChanges.swift */,
|
||||
562FF9AD1BCE902400759400 /* DatabaseError.swift */,
|
||||
562FF9AE1BCE902400759400 /* DatabaseQueue.swift */,
|
||||
562FF9AF1BCE902400759400 /* DatabaseValue.swift */,
|
||||
562FF9B01BCE902400759400 /* Protocols */,
|
||||
562FF9B51BCE902400759400 /* Row.swift */,
|
||||
562FF9B61BCE902400759400 /* SelectStatement.swift */,
|
||||
562FF9B71BCE902400759400 /* Statement.swift */,
|
||||
562FF9B81BCE902400759400 /* StatementArguments.swift */,
|
||||
562FF9B91BCE902400759400 /* UpdateStatement.swift */,
|
||||
);
|
||||
path = Core;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
562FF9B01BCE902400759400 /* Protocols */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
562FF9B11BCE902400759400 /* DatabaseTableMapping.swift */,
|
||||
562FF9B21BCE902400759400 /* DatabaseValueConvertible.swift */,
|
||||
562FF9B31BCE902400759400 /* RowConvertible.swift */,
|
||||
562FF9B41BCE902400759400 /* SQLiteStatementConvertible.swift */,
|
||||
);
|
||||
path = Protocols;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
562FF9BA1BCE902400759400 /* Foundation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
562FF9BB1BCE902400759400 /* DatabaseDateComponents.swift */,
|
||||
562FF9BC1BCE902400759400 /* NSData.swift */,
|
||||
562FF9BD1BCE902400759400 /* NSDate.swift */,
|
||||
562FF9BE1BCE902400759400 /* NSNull.swift */,
|
||||
562FF9BF1BCE902400759400 /* NSNumber.swift */,
|
||||
562FF9C01BCE902400759400 /* NSString.swift */,
|
||||
562FF9C11BCE902400759400 /* NSURL.swift */,
|
||||
562FF9C21BCE902400759400 /* Row+Foundation.swift */,
|
||||
562FF9C31BCE902400759400 /* RowConvertible+Foundation.swift */,
|
||||
562FF9C41BCE902400759400 /* StatementArguments+Foundation.swift */,
|
||||
);
|
||||
path = Foundation;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
562FF9C51BCE902400759400 /* Migrations */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
562FF9C61BCE902400759400 /* DatabaseMigrator.swift */,
|
||||
);
|
||||
path = Migrations;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
562FF9C71BCE902400759400 /* Record */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
562FF9C81BCE902400759400 /* DatabaseStorable.swift */,
|
||||
562FF9C91BCE902400759400 /* Record.swift */,
|
||||
);
|
||||
path = Record;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
562FF9CA1BCE902400759400 /* Swift */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
562FF9CB1BCE902400759400 /* RawRepresentable.swift */,
|
||||
562FF9CC1BCE902400759400 /* StandardLibraryTypes.swift */,
|
||||
);
|
||||
path = Swift;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
562FF9ED1BCE904D00759400 /* Libraries */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
@@ -263,6 +197,89 @@
|
||||
name = Models;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56FCB3411C21210B00305D10 /* Core */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FCB3421C21210B00305D10 /* Configuration.swift */,
|
||||
56FCB3431C21210B00305D10 /* Database.swift */,
|
||||
56FCB3441C21210B00305D10 /* DatabaseChanges.swift */,
|
||||
56FCB3451C21210B00305D10 /* DatabaseError.swift */,
|
||||
56FCB3461C21210B00305D10 /* DatabaseQueue.swift */,
|
||||
56FCB3471C21210B00305D10 /* DatabaseValue.swift */,
|
||||
56FCB3481C21210B00305D10 /* Protocols */,
|
||||
56FCB34E1C21210B00305D10 /* Row.swift */,
|
||||
56FCB34F1C21210B00305D10 /* SelectStatement.swift */,
|
||||
56FCB3501C21210B00305D10 /* Statement.swift */,
|
||||
56FCB3511C21210B00305D10 /* StatementArguments.swift */,
|
||||
56FCB3521C21210B00305D10 /* UpdateStatement.swift */,
|
||||
);
|
||||
path = Core;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56FCB3481C21210B00305D10 /* Protocols */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FCB3491C21210B00305D10 /* DatabasePersistable.swift */,
|
||||
56FCB34A1C21210B00305D10 /* DatabaseTableMapping.swift */,
|
||||
56FCB34B1C21210B00305D10 /* DatabaseValueConvertible.swift */,
|
||||
56FCB34C1C21210B00305D10 /* RowConvertible.swift */,
|
||||
56FCB34D1C21210B00305D10 /* SQLiteStatementConvertible.swift */,
|
||||
);
|
||||
path = Protocols;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56FCB3531C21210B00305D10 /* CoreGraphics */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FCB3541C21210B00305D10 /* CGFloat.swift */,
|
||||
);
|
||||
path = CoreGraphics;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56FCB3551C21210B00305D10 /* Foundation */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FCB3561C21210B00305D10 /* DatabaseCoder.swift */,
|
||||
56FCB3571C21210B00305D10 /* DatabaseDateComponents.swift */,
|
||||
56FCB3581C21210B00305D10 /* DatabaseValue+Foundation.swift */,
|
||||
56FCB3591C21210B00305D10 /* NSData.swift */,
|
||||
56FCB35A1C21210B00305D10 /* NSDate.swift */,
|
||||
56FCB35B1C21210B00305D10 /* NSNull.swift */,
|
||||
56FCB35C1C21210B00305D10 /* NSNumber.swift */,
|
||||
56FCB35D1C21210B00305D10 /* NSString.swift */,
|
||||
56FCB35E1C21210B00305D10 /* NSURL.swift */,
|
||||
56FCB35F1C21210B00305D10 /* Row+Foundation.swift */,
|
||||
56FCB3601C21210B00305D10 /* StatementArguments+Foundation.swift */,
|
||||
);
|
||||
path = Foundation;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56FCB3611C21210B00305D10 /* Migrations */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FCB3621C21210B00305D10 /* DatabaseMigrator.swift */,
|
||||
56FCB3631C21210B00305D10 /* Migration.swift */,
|
||||
);
|
||||
path = Migrations;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56FCB3641C21210B00305D10 /* Record */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FCB3651C21210B00305D10 /* Record.swift */,
|
||||
);
|
||||
path = Record;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
56FCB3661C21210B00305D10 /* Swift */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
56FCB3671C21210B00305D10 /* RawRepresentable.swift */,
|
||||
56FCB3681C21210B00305D10 /* StandardLibraryTypes.swift */,
|
||||
);
|
||||
path = Swift;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
/* End PBXGroup section */
|
||||
|
||||
/* Begin PBXNativeTarget section */
|
||||
@@ -333,40 +350,43 @@
|
||||
isa = PBXSourcesBuildPhase;
|
||||
buildActionMask = 2147483647;
|
||||
files = (
|
||||
562FF9D21BCE902400759400 /* DatabaseValue.swift in Sources */,
|
||||
562FF9CD1BCE902400759400 /* Configuration.swift in Sources */,
|
||||
562FF9E81BCE902400759400 /* Record.swift in Sources */,
|
||||
562FF9D41BCE902400759400 /* DatabaseValueConvertible.swift in Sources */,
|
||||
562FF9E31BCE902400759400 /* Row+Foundation.swift in Sources */,
|
||||
562FF9D81BCE902400759400 /* SelectStatement.swift in Sources */,
|
||||
562FF9D71BCE902400759400 /* Row.swift in Sources */,
|
||||
56FCB3821C21210B00305D10 /* NSURL.swift in Sources */,
|
||||
56FCB3781C21210B00305D10 /* UpdateStatement.swift in Sources */,
|
||||
56FCB3771C21210B00305D10 /* StatementArguments.swift in Sources */,
|
||||
56FCB3881C21210B00305D10 /* RawRepresentable.swift in Sources */,
|
||||
56FCB3841C21210B00305D10 /* StatementArguments+Foundation.swift in Sources */,
|
||||
56FCB37A1C21210B00305D10 /* DatabaseCoder.swift in Sources */,
|
||||
56FCB3891C21210B00305D10 /* StandardLibraryTypes.swift in Sources */,
|
||||
56FCB3731C21210B00305D10 /* SQLiteStatementConvertible.swift in Sources */,
|
||||
56FCB37F1C21210B00305D10 /* NSNull.swift in Sources */,
|
||||
56FCB37D1C21210B00305D10 /* NSData.swift in Sources */,
|
||||
56FCB36A1C21210B00305D10 /* Database.swift in Sources */,
|
||||
56FCB37C1C21210B00305D10 /* DatabaseValue+Foundation.swift in Sources */,
|
||||
562FF9EF1BCE912C00759400 /* PersonEditionViewController.swift in Sources */,
|
||||
56FCB3831C21210B00305D10 /* Row+Foundation.swift in Sources */,
|
||||
56FCB3711C21210B00305D10 /* DatabaseValueConvertible.swift in Sources */,
|
||||
56FCB3691C21210B00305D10 /* Configuration.swift in Sources */,
|
||||
56FCB3851C21210B00305D10 /* DatabaseMigrator.swift in Sources */,
|
||||
56FCB37E1C21210B00305D10 /* NSDate.swift in Sources */,
|
||||
562FF9971BCE8FA400759400 /* PersonsViewController.swift in Sources */,
|
||||
562FF9CE1BCE902400759400 /* Database.swift in Sources */,
|
||||
562FF9E01BCE902400759400 /* NSNumber.swift in Sources */,
|
||||
562FF9CF1BCE902400759400 /* DatabaseChanges.swift in Sources */,
|
||||
562FF9E51BCE902400759400 /* StatementArguments+Foundation.swift in Sources */,
|
||||
562FF9D61BCE902400759400 /* SQLiteStatementConvertible.swift in Sources */,
|
||||
56FCB36E1C21210B00305D10 /* DatabaseValue.swift in Sources */,
|
||||
56FCB3791C21210B00305D10 /* CGFloat.swift in Sources */,
|
||||
56FCB3801C21210B00305D10 /* NSNumber.swift in Sources */,
|
||||
562FF9F21BCE914E00759400 /* Person.swift in Sources */,
|
||||
562FF9D91BCE902400759400 /* Statement.swift in Sources */,
|
||||
562FF9E91BCE902400759400 /* RawRepresentable.swift in Sources */,
|
||||
56FCB3701C21210B00305D10 /* DatabaseTableMapping.swift in Sources */,
|
||||
56FCB3861C21210B00305D10 /* Migration.swift in Sources */,
|
||||
56FCB3761C21210B00305D10 /* Statement.swift in Sources */,
|
||||
56FCB36C1C21210B00305D10 /* DatabaseError.swift in Sources */,
|
||||
56FCB3751C21210B00305D10 /* SelectStatement.swift in Sources */,
|
||||
56FCB3811C21210B00305D10 /* NSString.swift in Sources */,
|
||||
56FCB36F1C21210B00305D10 /* DatabasePersistable.swift in Sources */,
|
||||
562FF9951BCE8FA400759400 /* AppDelegate.swift in Sources */,
|
||||
562FF9EA1BCE902400759400 /* StandardLibraryTypes.swift in Sources */,
|
||||
562FF9D31BCE902400759400 /* DatabaseTableMapping.swift in Sources */,
|
||||
562FF9DD1BCE902400759400 /* NSData.swift in Sources */,
|
||||
562FF9D11BCE902400759400 /* DatabaseQueue.swift in Sources */,
|
||||
562FF9DE1BCE902400759400 /* NSDate.swift in Sources */,
|
||||
562FF9E41BCE902400759400 /* RowConvertible+Foundation.swift in Sources */,
|
||||
562FF9E61BCE902400759400 /* DatabaseMigrator.swift in Sources */,
|
||||
562FF9D01BCE902400759400 /* DatabaseError.swift in Sources */,
|
||||
562FF9DB1BCE902400759400 /* UpdateStatement.swift in Sources */,
|
||||
562FF9E21BCE902400759400 /* NSURL.swift in Sources */,
|
||||
562FF9DA1BCE902400759400 /* StatementArguments.swift in Sources */,
|
||||
562FF9E71BCE902400759400 /* DatabaseStorable.swift in Sources */,
|
||||
562FF9E11BCE902400759400 /* NSString.swift in Sources */,
|
||||
562FF9DC1BCE902400759400 /* DatabaseDateComponents.swift in Sources */,
|
||||
562FF9DF1BCE902400759400 /* NSNull.swift in Sources */,
|
||||
562FF9D51BCE902400759400 /* RowConvertible.swift in Sources */,
|
||||
56FCB3741C21210B00305D10 /* Row.swift in Sources */,
|
||||
56FCB36D1C21210B00305D10 /* DatabaseQueue.swift in Sources */,
|
||||
56FCB37B1C21210B00305D10 /* DatabaseDateComponents.swift in Sources */,
|
||||
56FCB3871C21210B00305D10 /* Record.swift in Sources */,
|
||||
56FCB3721C21210B00305D10 /* RowConvertible.swift in Sources */,
|
||||
56FCB36B1C21210B00305D10 /* DatabaseChanges.swift in Sources */,
|
||||
);
|
||||
runOnlyForDeploymentPostprocessing = 0;
|
||||
};
|
||||
|
||||
@@ -12,27 +12,29 @@ class Person : Record {
|
||||
super.init()
|
||||
}
|
||||
|
||||
// MARK: - Record
|
||||
|
||||
required init(row: Row) {
|
||||
super.init(row: row)
|
||||
}
|
||||
// MARK: - Record
|
||||
|
||||
override class func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
override func updateFromRow(row: Row) {
|
||||
if let dbv = row["id"] { id = dbv.value() }
|
||||
if let dbv = row["firstName"] { firstName = dbv.value() }
|
||||
if let dbv = row["lastName"] { lastName = dbv.value() }
|
||||
super.updateFromRow(row) // Subclasses are required to call super.
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
firstName = row.value(named: "firstName")
|
||||
lastName = row.value(named: "lastName")
|
||||
super.init(row)
|
||||
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return [
|
||||
"id": id,
|
||||
"firstName": firstName,
|
||||
"lastName": lastName]
|
||||
}
|
||||
|
||||
override func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
id = rowID
|
||||
}
|
||||
}
|
||||
@@ -226,7 +226,7 @@
|
||||
// // Answer: this is an artificial column that makes our tests run despite
|
||||
// // the fact that Record.update() does nothing when there is nothing to
|
||||
// // update.
|
||||
// override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
// override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
// return ["id": id, "data": nil]
|
||||
// }
|
||||
//
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
// init() {
|
||||
// direction = .Save
|
||||
// }
|
||||
// init(row: Row) {
|
||||
// init(_ row: Row) {
|
||||
// direction = .Fetch(row)
|
||||
// }
|
||||
// subscript(name: String) -> Binding {
|
||||
@@ -123,14 +123,14 @@
|
||||
// super.updateFromRow(row) // Subclasses are required to call super.
|
||||
// }
|
||||
//
|
||||
// override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
// override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
// let mapping = Mapping()
|
||||
// map(mapping)
|
||||
// return mapping.dictionary
|
||||
// }
|
||||
//
|
||||
// required init(row: Row) {
|
||||
// super.init(row: row)
|
||||
// required init(_ row: Row) {
|
||||
// super.init(row)
|
||||
// }
|
||||
//}
|
||||
//
|
||||
|
||||
@@ -103,22 +103,18 @@ class PerformanceRecord : Record {
|
||||
|
||||
// Record
|
||||
|
||||
required init(row: Row) {
|
||||
super.init(row: row)
|
||||
}
|
||||
|
||||
override func updateFromRow(row: Row) {
|
||||
if let dbv = row["i0"] { i0 = dbv.value() }
|
||||
if let dbv = row["i1"] { i1 = dbv.value() }
|
||||
if let dbv = row["i2"] { i2 = dbv.value() }
|
||||
if let dbv = row["i3"] { i3 = dbv.value() }
|
||||
if let dbv = row["i4"] { i4 = dbv.value() }
|
||||
if let dbv = row["i5"] { i5 = dbv.value() }
|
||||
if let dbv = row["i6"] { i6 = dbv.value() }
|
||||
if let dbv = row["i7"] { i7 = dbv.value() }
|
||||
if let dbv = row["i8"] { i8 = dbv.value() }
|
||||
if let dbv = row["i9"] { i9 = dbv.value() }
|
||||
super.updateFromRow(row)
|
||||
required init(_ row: Row) {
|
||||
i0 = row.value(named: "i0")
|
||||
i1 = row.value(named: "i1")
|
||||
i2 = row.value(named: "i2")
|
||||
i3 = row.value(named: "i3")
|
||||
i4 = row.value(named: "i4")
|
||||
i5 = row.value(named: "i5")
|
||||
i6 = row.value(named: "i6")
|
||||
i7 = row.value(named: "i7")
|
||||
i8 = row.value(named: "i8")
|
||||
i9 = row.value(named: "i9")
|
||||
super.init(row)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -15,22 +15,18 @@ class PerformanceRecord : Record {
|
||||
|
||||
// Record
|
||||
|
||||
required init(row: Row) {
|
||||
super.init(row: row)
|
||||
}
|
||||
|
||||
override func updateFromRow(row: Row) {
|
||||
if let dbv = row["i0"] { i0 = dbv.value() }
|
||||
if let dbv = row["i1"] { i1 = dbv.value() }
|
||||
if let dbv = row["i2"] { i2 = dbv.value() }
|
||||
if let dbv = row["i3"] { i3 = dbv.value() }
|
||||
if let dbv = row["i4"] { i4 = dbv.value() }
|
||||
if let dbv = row["i5"] { i5 = dbv.value() }
|
||||
if let dbv = row["i6"] { i6 = dbv.value() }
|
||||
if let dbv = row["i7"] { i7 = dbv.value() }
|
||||
if let dbv = row["i8"] { i8 = dbv.value() }
|
||||
if let dbv = row["i9"] { i9 = dbv.value() }
|
||||
super.updateFromRow(row)
|
||||
required init(_ row: Row) {
|
||||
i0 = row.value(named: "i0")
|
||||
i1 = row.value(named: "i1")
|
||||
i2 = row.value(named: "i2")
|
||||
i3 = row.value(named: "i3")
|
||||
i4 = row.value(named: "i4")
|
||||
i5 = row.value(named: "i5")
|
||||
i6 = row.value(named: "i6")
|
||||
i7 = row.value(named: "i7")
|
||||
i8 = row.value(named: "i8")
|
||||
i9 = row.value(named: "i9")
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
// FMDB
|
||||
|
||||
@@ -8,7 +8,7 @@ struct PersistablePerson : DatabasePersistable {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": name]
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ class PersistablePersonClass : DatabasePersistable {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
@@ -43,7 +43,7 @@ struct PersistableCountry : DatabasePersistable {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
}
|
||||
@@ -61,7 +61,7 @@ struct PersistableCustomizedCountry : DatabasePersistable {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ struct MutablePersistablePerson : MutableDatabasePersistable {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ struct MutablePersistableCountry : MutableDatabasePersistable {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ struct MutablePersistableCustomizedCountry : MutableDatabasePersistable {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
|
||||
|
||||
@@ -20,53 +20,53 @@ class DatabaseValueTests: GRDBTestCase {
|
||||
let barData = "bar".dataUsingEncoding(NSUTF8StringEncoding)!
|
||||
|
||||
XCTAssertEqual(DatabaseValue.Null, DatabaseValue.Null)
|
||||
XCTAssertNotEqual(DatabaseValue.Null, DatabaseValue(int64: 1))
|
||||
XCTAssertNotEqual(DatabaseValue.Null, DatabaseValue(double: 1.0))
|
||||
XCTAssertNotEqual(DatabaseValue.Null, DatabaseValue(string: "foo"))
|
||||
XCTAssertNotEqual(DatabaseValue.Null, DatabaseValue(data: fooData))
|
||||
XCTAssertNotEqual(DatabaseValue.Null, 1.databaseValue)
|
||||
XCTAssertNotEqual(DatabaseValue.Null, 1.0.databaseValue)
|
||||
XCTAssertNotEqual(DatabaseValue.Null, "foo".databaseValue)
|
||||
XCTAssertNotEqual(DatabaseValue.Null, fooData.databaseValue)
|
||||
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue.Null)
|
||||
XCTAssertEqual(DatabaseValue(int64: 1), DatabaseValue(int64: 1))
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue(int64: 2))
|
||||
XCTAssertEqual(DatabaseValue(int64: 1), DatabaseValue(double: 1.0))
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue(double: 1.1))
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue(double: 2.0))
|
||||
XCTAssertEqual(DatabaseValue(int64: 1 << 53), DatabaseValue(double: Double(1 << 53))) // Any integer up to 2^53 has an exact representation as a IEEE-754 double...
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1 << 53 + 1), DatabaseValue(double: Double(1 << 53 + 1))) // ... 2^53 + 1 does not....
|
||||
XCTAssertEqual(DatabaseValue(int64: 1 << 54), DatabaseValue(double: Double(1 << 54))) // ... but 2^54 does.
|
||||
XCTAssertNotEqual(DatabaseValue(int64: Int64.max), DatabaseValue(double: Double(Int64.max))) // ... and Int64.max does not.
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue(string: "foo"))
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue(string: "1"))
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue(string: "1.0"))
|
||||
XCTAssertNotEqual(DatabaseValue(int64: 1), DatabaseValue(data: fooData))
|
||||
XCTAssertNotEqual(1.databaseValue, DatabaseValue.Null)
|
||||
XCTAssertEqual(1.databaseValue, 1.databaseValue)
|
||||
XCTAssertNotEqual(1.databaseValue, 2.databaseValue)
|
||||
XCTAssertEqual(1.databaseValue, 1.0.databaseValue)
|
||||
XCTAssertNotEqual(1.databaseValue, 1.1.databaseValue)
|
||||
XCTAssertNotEqual(1.databaseValue, 2.0.databaseValue)
|
||||
XCTAssertEqual(Double(1 << 53).databaseValue, Double(1 << 53).databaseValue) // Any integer up to 2^53 has an exact representation as a IEEE-754 double...
|
||||
XCTAssertNotEqual((1 << 53 + 1).databaseValue, Double(1 << 53 + 1).databaseValue) // ... 2^53 + 1 does not....
|
||||
XCTAssertEqual((1 << 54).databaseValue, Double(1 << 54).databaseValue) // ... but 2^54 does.
|
||||
XCTAssertNotEqual(Int64.max.databaseValue, Double(Int64.max).databaseValue) // ... and Int64.max does not.
|
||||
XCTAssertNotEqual(1.databaseValue, "foo".databaseValue)
|
||||
XCTAssertNotEqual(1.databaseValue, "1".databaseValue)
|
||||
XCTAssertNotEqual(1.databaseValue, "1.0".databaseValue)
|
||||
XCTAssertNotEqual(1.databaseValue, fooData.databaseValue)
|
||||
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.0), DatabaseValue.Null)
|
||||
XCTAssertEqual(DatabaseValue(double: 1.0), DatabaseValue(int64: 1))
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.1), DatabaseValue(int64: 1))
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.0), DatabaseValue(int64: 2))
|
||||
XCTAssertEqual(DatabaseValue(double: 1.0), DatabaseValue(double: 1.0))
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.0), DatabaseValue(double: 2.0))
|
||||
XCTAssertEqual(DatabaseValue(double: Double(1 << 53)), DatabaseValue(int64: 1 << 53)) // Any integer up to 2^53 has an exact representation as a IEEE-754 double...
|
||||
XCTAssertNotEqual(DatabaseValue(double: Double(1 << 53 + 1)), DatabaseValue(int64: 1 << 53 + 1)) // ... 2^53 + 1 does not....
|
||||
XCTAssertEqual(DatabaseValue(double: Double(1 << 54)), DatabaseValue(int64: 1 << 54)) // ... but 2^54 does.
|
||||
XCTAssertNotEqual(DatabaseValue(double: Double(Int64.max)), DatabaseValue(int64: Int64.max)) // ... and Int64.max does not.
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.0), DatabaseValue(string: "foo"))
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.0), DatabaseValue(string: "1"))
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.0), DatabaseValue(string: "1.0"))
|
||||
XCTAssertNotEqual(DatabaseValue(double: 1.0), DatabaseValue(data: fooData))
|
||||
XCTAssertNotEqual(1.0.databaseValue, DatabaseValue.Null)
|
||||
XCTAssertEqual(1.0.databaseValue, 1.databaseValue)
|
||||
XCTAssertNotEqual(1.1.databaseValue, 1.databaseValue)
|
||||
XCTAssertNotEqual(1.0.databaseValue, 2.databaseValue)
|
||||
XCTAssertEqual(1.0.databaseValue, 1.0.databaseValue)
|
||||
XCTAssertNotEqual(1.0.databaseValue, 2.0.databaseValue)
|
||||
XCTAssertEqual(Double(1 << 53).databaseValue, Double(1 << 53).databaseValue) // Any integer up to 2^53 has an exact representation as a IEEE-754 double...
|
||||
XCTAssertNotEqual(Double(1 << 53 + 1).databaseValue, (1 << 53 + 1).databaseValue) // ... 2^53 + 1 does not....
|
||||
XCTAssertEqual(Double(1 << 54).databaseValue, (1 << 54).databaseValue) // ... but 2^54 does.
|
||||
XCTAssertNotEqual(Double(Int64.max).databaseValue, Int64.max.databaseValue) // ... and Int64.max does not.
|
||||
XCTAssertNotEqual(1.0.databaseValue, "foo".databaseValue)
|
||||
XCTAssertNotEqual(1.0.databaseValue, "1".databaseValue)
|
||||
XCTAssertNotEqual(1.0.databaseValue, "1.0".databaseValue)
|
||||
XCTAssertNotEqual(1.0.databaseValue, fooData.databaseValue)
|
||||
|
||||
XCTAssertNotEqual(DatabaseValue(string: "foo"), DatabaseValue.Null)
|
||||
XCTAssertNotEqual(DatabaseValue(string: "foo"), DatabaseValue(int64: 1))
|
||||
XCTAssertNotEqual(DatabaseValue(string: "foo"), DatabaseValue(double: 1.0))
|
||||
XCTAssertEqual(DatabaseValue(string: "foo"), DatabaseValue(string: "foo"))
|
||||
XCTAssertNotEqual(DatabaseValue(string: "foo"), DatabaseValue(string: "bar"))
|
||||
XCTAssertNotEqual(DatabaseValue(string: "foo"), DatabaseValue(data: fooData))
|
||||
XCTAssertNotEqual("foo".databaseValue, DatabaseValue.Null)
|
||||
XCTAssertNotEqual("foo".databaseValue, 1.databaseValue)
|
||||
XCTAssertNotEqual("foo".databaseValue, 1.0.databaseValue)
|
||||
XCTAssertEqual("foo".databaseValue, "foo".databaseValue)
|
||||
XCTAssertNotEqual("foo".databaseValue, "bar".databaseValue)
|
||||
XCTAssertNotEqual("foo".databaseValue, fooData.databaseValue)
|
||||
|
||||
XCTAssertNotEqual(DatabaseValue(data: fooData), DatabaseValue.Null)
|
||||
XCTAssertNotEqual(DatabaseValue(data: fooData), DatabaseValue(int64: 1))
|
||||
XCTAssertNotEqual(DatabaseValue(data: fooData), DatabaseValue(double: 1.0))
|
||||
XCTAssertNotEqual(DatabaseValue(data: fooData), DatabaseValue(string: "foo"))
|
||||
XCTAssertEqual(DatabaseValue(data: fooData), DatabaseValue(data: fooData))
|
||||
XCTAssertNotEqual(DatabaseValue(data: fooData), DatabaseValue(data: barData))
|
||||
XCTAssertNotEqual(fooData.databaseValue, DatabaseValue.Null)
|
||||
XCTAssertNotEqual(fooData.databaseValue, 1.databaseValue)
|
||||
XCTAssertNotEqual(fooData.databaseValue, 1.0.databaseValue)
|
||||
XCTAssertNotEqual(fooData.databaseValue, "foo".databaseValue)
|
||||
XCTAssertEqual(fooData.databaseValue, fooData.databaseValue)
|
||||
XCTAssertNotEqual(fooData.databaseValue, barData.databaseValue)
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@ struct DatabaseTimestamp: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(double: date.timeIntervalSince1970)
|
||||
return date.timeIntervalSince1970.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
|
||||
+1
-1
@@ -8,7 +8,7 @@ struct WrappedInt: DatabaseValueConvertible {
|
||||
self.int = int
|
||||
}
|
||||
var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: Int64(int))
|
||||
return int.databaseValue
|
||||
}
|
||||
static func fromDatabaseValue(databaseValue: DatabaseValue) -> WrappedInt? {
|
||||
guard let int = Int.fromDatabaseValue(databaseValue) else {
|
||||
|
||||
+2
-2
@@ -3,7 +3,7 @@ import GRDB
|
||||
|
||||
class FetchableParent : DatabaseValueConvertible, CustomStringConvertible {
|
||||
var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: "Parent")
|
||||
return "Parent".databaseValue
|
||||
}
|
||||
|
||||
class func fromDatabaseValue(databaseValue: DatabaseValue) -> Self? {
|
||||
@@ -26,7 +26,7 @@ class FetchableParent : DatabaseValueConvertible, CustomStringConvertible {
|
||||
class FetchableChild : FetchableParent {
|
||||
/// Returns a value that can be stored in the database.
|
||||
override var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: "Child")
|
||||
return "Child".databaseValue
|
||||
}
|
||||
|
||||
override var description: String { return "Child" }
|
||||
|
||||
@@ -5,7 +5,7 @@ class NSDataTests: GRDBTestCase {
|
||||
|
||||
func testDatabaseValueCanNotStoreEmptyData() {
|
||||
// SQLite can't store zero-length blob.
|
||||
let databaseValue = DatabaseValue(data: NSData())
|
||||
let databaseValue = NSData().databaseValue
|
||||
XCTAssertEqual(databaseValue, DatabaseValue.Null)
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,7 @@ import GRDB
|
||||
|
||||
struct CustomValueType : DatabaseValueConvertible {
|
||||
var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: "CustomValueType")
|
||||
return "CustomValueType".databaseValue
|
||||
}
|
||||
static func fromDatabaseValue(databaseValue: DatabaseValue) -> CustomValueType? {
|
||||
guard let string = String.fromDatabaseValue(databaseValue) where string == "CustomValueType" else {
|
||||
|
||||
+2
-3
@@ -16,7 +16,7 @@ struct FastWrappedInt: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
}
|
||||
|
||||
var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: Int64(int))
|
||||
return int.databaseValue
|
||||
}
|
||||
|
||||
static func fromDatabaseValue(databaseValue: DatabaseValue) -> FastWrappedInt? {
|
||||
@@ -30,8 +30,7 @@ struct FastWrappedInt: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
class SQLiteStatementConvertibleFetchTests: GRDBTestCase {
|
||||
|
||||
func testSlowConversion() {
|
||||
let databaseValue = DatabaseValue(int64: 0)
|
||||
let slow = FastWrappedInt.fromDatabaseValue(databaseValue)!
|
||||
let slow = FastWrappedInt.fromDatabaseValue(0.databaseValue)!
|
||||
XCTAssertEqual(slow.int, 0)
|
||||
XCTAssertEqual(slow.fast, false)
|
||||
}
|
||||
|
||||
@@ -67,13 +67,13 @@ class Artist : Record {
|
||||
return "artists"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
name = row.value(named: "name")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
@@ -109,14 +109,14 @@ class Artwork : Record {
|
||||
return "artworks"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
title = row.value(named: "title")
|
||||
artistId = row.value(named: "artistId")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "artistId": artistId, "title": title]
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class RecordWithInexistingDatabaseTable: Record {
|
||||
}
|
||||
}
|
||||
|
||||
class RecordWithEmptyStoredDatabaseDictionary : Record {
|
||||
class RecordWithEmptyPersistentDictionary : Record {
|
||||
override static func databaseTableName() -> String {
|
||||
return "records"
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class RecordWithNilPrimaryKey : Record {
|
||||
return "records"
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": nil]
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,7 @@ class RecordForTableWithoutPrimaryKey : Record {
|
||||
return "records"
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": "foo"]
|
||||
}
|
||||
}
|
||||
@@ -47,17 +47,17 @@ class RecordForTableWithMultipleColumnsPrimaryKey : Record {
|
||||
return "records"
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": "foo"]
|
||||
}
|
||||
}
|
||||
|
||||
class RecordWithRowIDPrimaryKeyNotExposedInStoredDatabaseDictionary : Record {
|
||||
class RecordWithRowIDPrimaryKeyNotExposedInPersistentDictionary : Record {
|
||||
override static func databaseTableName() -> String {
|
||||
return "records"
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": "foo"]
|
||||
}
|
||||
}
|
||||
@@ -321,58 +321,58 @@ class CrashTests: GRDBTestCase {
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// MARK: - RecordWithEmptyStoredDatabaseDictionary
|
||||
// MARK: - RecordWithEmptyPersistentDictionary
|
||||
|
||||
func testRecordWithEmptyStoredDatabaseDictionaryCanNotBeInserted() {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeInserted() {
|
||||
assertCrash("Invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyStoredDatabaseDictionary().insert(db)
|
||||
try RecordWithEmptyPersistentDictionary().insert(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordWithEmptyStoredDatabaseDictionaryCanNotBeUpdated() {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeUpdated() {
|
||||
assertCrash("Invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyStoredDatabaseDictionary().update(db)
|
||||
try RecordWithEmptyPersistentDictionary().update(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordWithEmptyStoredDatabaseDictionaryCanNotBeSaved() {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeSaved() {
|
||||
assertCrash("Invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyStoredDatabaseDictionary().save(db)
|
||||
try RecordWithEmptyPersistentDictionary().save(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordWithEmptyStoredDatabaseDictionaryCanNotBeDeleted() {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeDeleted() {
|
||||
assertCrash("Invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyStoredDatabaseDictionary().delete(db)
|
||||
try RecordWithEmptyPersistentDictionary().delete(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordWithEmptyStoredDatabaseDictionaryCanNotBeReloaded() {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeReloaded() {
|
||||
assertCrash("Invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
try RecordWithEmptyStoredDatabaseDictionary().reload(db)
|
||||
try RecordWithEmptyPersistentDictionary().reload(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordWithEmptyStoredDatabaseDictionaryCanNotBeTestedForExistence() {
|
||||
func testRecordWithEmptyPersistentDictionaryCanNotBeTestedForExistence() {
|
||||
assertCrash("Invalid empty dictionary") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY)")
|
||||
RecordWithEmptyStoredDatabaseDictionary().exists(db)
|
||||
RecordWithEmptyPersistentDictionary().exists(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -481,13 +481,13 @@ class CrashTests: GRDBTestCase {
|
||||
|
||||
|
||||
// =========================================================================
|
||||
// MARK: - RecordWithRowIDPrimaryKeyNotExposedInStoredDatabaseDictionary
|
||||
// MARK: - RecordWithRowIDPrimaryKeyNotExposedInPersistentDictionary
|
||||
|
||||
func testRecordWithRowIDPrimaryKeyNotExposedInStoredDatabaseDictionaryCanNotBeInserted() {
|
||||
assertCrash("RecordWithRowIDPrimaryKeyNotExposedInStoredDatabaseDictionary.storedDatabaseDictionary must return the value for the primary key \"id\"") {
|
||||
func testRecordWithRowIDPrimaryKeyNotExposedInPersistentDictionaryCanNotBeInserted() {
|
||||
assertCrash("RecordWithRowIDPrimaryKeyNotExposedInPersistentDictionary.persistentDictionary must return the value for the primary key \"id\"") {
|
||||
try dbQueue.inDatabase { db in
|
||||
try db.execute("CREATE TABLE records (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try RecordWithRowIDPrimaryKeyNotExposedInStoredDatabaseDictionary().insert(db)
|
||||
try RecordWithRowIDPrimaryKeyNotExposedInPersistentDictionary().insert(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -365,7 +365,7 @@ class NSDateComponentsTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
func testDatabaseDateComponentsFromUnparsableString() {
|
||||
let databaseDateComponents = DatabaseDateComponents.fromDatabaseValue(DatabaseValue(string: "foo"))
|
||||
let databaseDateComponents = DatabaseDateComponents.fromDatabaseValue("foo".databaseValue)
|
||||
XCTAssertTrue(databaseDateComponents == nil)
|
||||
}
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class NSDateTests : GRDBTestCase {
|
||||
}
|
||||
|
||||
func testNSDateFromUnparsableString() {
|
||||
let date = NSDate.fromDatabaseValue(DatabaseValue(string: "foo"))
|
||||
let date = NSDate.fromDatabaseValue("foo".databaseValue)
|
||||
XCTAssertTrue(date == nil)
|
||||
}
|
||||
|
||||
|
||||
@@ -83,14 +83,14 @@ class DatabaseMigratorTests : GRDBTestCase {
|
||||
let personId = try db.execute("INSERT INTO persons (name) VALUES ('Arthur')").insertedRowID
|
||||
try db.execute("INSERT INTO pets (masterId, name) VALUES (?, 'Bobby')", arguments:[personId])
|
||||
}
|
||||
migrator.registerMigrationWithoutForeignKeyChecks("removePersonTmpColumn") { db in
|
||||
migrator.registerMigration("removePersonTmpColumn", withDisabledForeignKeyChecks: true) { db in
|
||||
// Test the technique described at https://www.sqlite.org/lang_altertable.html#otheralter
|
||||
try db.execute("CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT)")
|
||||
try db.execute("INSERT INTO new_persons SELECT id, name FROM persons")
|
||||
try db.execute("DROP TABLE persons")
|
||||
try db.execute("ALTER TABLE new_persons RENAME TO persons")
|
||||
}
|
||||
migrator.registerMigrationWithoutForeignKeyChecks("foreignKeyError") { db in
|
||||
migrator.registerMigration("foreignKeyError", withDisabledForeignKeyChecks: true) { db in
|
||||
// Make sure foreign keys are checked at the end.
|
||||
try db.execute("INSERT INTO persons (name) VALUES ('Barbara')")
|
||||
do {
|
||||
|
||||
@@ -22,12 +22,12 @@ class MinimalRowID : Record {
|
||||
return "minimalRowIDs"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id]
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createMinimalRowID", MinimalRowID.setupInDatabase)
|
||||
migrator.registerMigration("createMinimalRowID", migrate: MinimalRowID.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -60,7 +60,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
XCTAssertTrue(record.id != nil)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -79,7 +79,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -114,7 +114,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -151,7 +151,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
try record.update(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -190,7 +190,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
XCTAssertTrue(record.id != nil)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -209,7 +209,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -228,7 +228,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -248,7 +248,7 @@ class MinimalPrimaryKeyRowIDTests : GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalRowIDs WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
|
||||
@@ -22,12 +22,12 @@ class MinimalSingle: Record {
|
||||
return "minimalSingles"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
UUID = row.value(named: "UUID")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["UUID": UUID]
|
||||
}
|
||||
}
|
||||
@@ -38,7 +38,7 @@ class MinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createMinimalSingle", MinimalSingle.setupInDatabase)
|
||||
migrator.registerMigration("createMinimalSingle", migrate: MinimalSingle.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -70,7 +70,7 @@ class MinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -107,7 +107,7 @@ class MinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -145,7 +145,7 @@ class MinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.update(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -199,7 +199,7 @@ class MinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -219,7 +219,7 @@ class MinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -240,7 +240,7 @@ class MinimalPrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM minimalSingles WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
|
||||
@@ -30,14 +30,14 @@ class Citizenship : Record {
|
||||
return "citizenships"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
personName = row.value(named: "personName")
|
||||
countryName = row.value(named: "countryName")
|
||||
native = row.value(named: "native")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return [
|
||||
"personName": personName,
|
||||
"countryName": countryName,
|
||||
@@ -52,7 +52,7 @@ class PrimaryKeyMultipleTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createCitizenship", Citizenship.setupInDatabase)
|
||||
migrator.registerMigration("createCitizenship", migrate: Citizenship.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -83,7 +83,7 @@ class PrimaryKeyMultipleTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -118,7 +118,7 @@ class PrimaryKeyMultipleTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -155,7 +155,7 @@ class PrimaryKeyMultipleTests: GRDBTestCase {
|
||||
try record.update(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -207,7 +207,7 @@ class PrimaryKeyMultipleTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -228,7 +228,7 @@ class PrimaryKeyMultipleTests: GRDBTestCase {
|
||||
try record.save(db) // Actual update
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -248,7 +248,7 @@ class PrimaryKeyMultipleTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM citizenships WHERE personName = ? AND countryName = ?", arguments: [record.personName, record.countryName])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
|
||||
@@ -23,12 +23,12 @@ class Item : Record {
|
||||
return "items"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
name = row.value(named: "name")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": name]
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ class PrimaryKeyNoneTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createItem", Item.setupInDatabase)
|
||||
migrator.registerMigration("createItem", migrate: Item.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
|
||||
@@ -32,15 +32,15 @@ class Person : Record {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
age = row.value(named: "age")
|
||||
name = row.value(named: "name")
|
||||
creationDate = row.value(named: "creationDate")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return [
|
||||
"id": id,
|
||||
"name": name,
|
||||
@@ -69,7 +69,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", Person.setupInDatabase)
|
||||
migrator.registerMigration("createPerson", migrate: Person.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -87,7 +87,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
XCTAssertTrue(record.id != nil)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -107,7 +107,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
XCTAssertTrue(record.id != nil)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -128,7 +128,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -175,7 +175,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -212,7 +212,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
try record.update(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -251,7 +251,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
XCTAssertTrue(record.id != nil)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -269,7 +269,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -291,7 +291,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
try record.save(db) // Actual update
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -311,7 +311,7 @@ class PrimaryKeyRowIDTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM persons WHERE id = ?", arguments: [record.id])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
|
||||
@@ -26,13 +26,13 @@ class Pet : Record {
|
||||
return "pets"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
UUID = row.value(named: "UUID")
|
||||
name = row.value(named: "name")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["UUID": UUID, "name": name]
|
||||
}
|
||||
}
|
||||
@@ -43,7 +43,7 @@ class PrimaryKeySingleTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPet", Pet.setupInDatabase)
|
||||
migrator.registerMigration("createPet", migrate: Pet.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -74,7 +74,7 @@ class PrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -109,7 +109,7 @@ class PrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -146,7 +146,7 @@ class PrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.update(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -198,7 +198,7 @@ class PrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -219,7 +219,7 @@ class PrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.save(db) // Actual update
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -239,7 +239,7 @@ class PrimaryKeySingleTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM pets WHERE UUID = ?", arguments: [record.UUID])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
|
||||
@@ -25,13 +25,13 @@ class Email : Record {
|
||||
return "emails"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
email = row.value(named: "email")
|
||||
label = row.value(named: "label")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["email": email, "label": label]
|
||||
}
|
||||
}
|
||||
@@ -42,7 +42,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createEmail", Email.setupInDatabase)
|
||||
migrator.registerMigration("createEmail", migrate: Email.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -75,7 +75,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -97,7 +97,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -118,7 +118,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
try record.insert(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -156,7 +156,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
try record.update(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -210,7 +210,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -230,7 +230,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
@@ -251,7 +251,7 @@ class PrimaryKeySingleWithReplaceConflictResolutionTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
let row = Row.fetchOne(db, "SELECT * FROM emails WHERE email = ?", arguments: [record.email])!
|
||||
for (key, value) in record.storedDatabaseDictionary {
|
||||
for (key, value) in record.persistentDictionary {
|
||||
if let dbv = row[key] {
|
||||
XCTAssertEqual(dbv, value?.databaseValue ?? .Null)
|
||||
} else {
|
||||
|
||||
@@ -20,12 +20,12 @@ class EventRecorder : Record {
|
||||
return "eventRecorders"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id]
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class RecordEventsTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createEventRecorder", EventRecorder.setupInDatabase)
|
||||
migrator.registerMigration("createEventRecorder", migrate: EventRecorder.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -57,7 +57,7 @@ class RecordEventsTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testAwakeFromFetchIsNotTriggeredByInitFromRow() {
|
||||
let record = EventRecorder(row: Row())
|
||||
let record = EventRecorder(Row())
|
||||
XCTAssertEqual(record.awakeFromFetchCount, 0)
|
||||
}
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
import XCTest
|
||||
import GRDB
|
||||
|
||||
class RecordWithoutStoredDatabaseDictionary : Record {
|
||||
class RecordWithoutPersistentDictionary : Record {
|
||||
}
|
||||
|
||||
class SingleColumnRecord : Record {
|
||||
var name: String?
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": name]
|
||||
}
|
||||
}
|
||||
@@ -16,16 +16,16 @@ class DoubleColumnRecord : Record {
|
||||
var name: String?
|
||||
var age: Int?
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["name": name, "age": age]
|
||||
}
|
||||
}
|
||||
|
||||
class RecordDescriptionTests: GRDBTestCase {
|
||||
|
||||
func testRecordWithoutStoredDatabaseDictionaryDescription() {
|
||||
let record = RecordWithoutStoredDatabaseDictionary()
|
||||
XCTAssertEqual(record.description, "<RecordWithoutStoredDatabaseDictionary>")
|
||||
func testRecordWithoutPersistentDictionaryDescription() {
|
||||
let record = RecordWithoutPersistentDictionary()
|
||||
XCTAssertEqual(record.description, "<RecordWithoutPersistentDictionary>")
|
||||
}
|
||||
|
||||
func testSimpleRecordDescription() {
|
||||
|
||||
@@ -11,12 +11,12 @@ class IntegerPropertyOnRealAffinityColumn : Record {
|
||||
|
||||
// Record
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
value = row.value(named: "value")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["value": value]
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", Person.setupInDatabase)
|
||||
migrator.registerMigration("createPerson", migrate: Person.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -38,27 +38,27 @@ class RecordEditedTests: GRDBTestCase {
|
||||
// Create a Record. No fetch has happen, so we don't know if it is
|
||||
// identical to its eventual row in the database. So it is edited.
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
|
||||
func testRecordIsEditedAfterInitFromRow() {
|
||||
// Create a Record from a row. The row may not come from the database.
|
||||
// So it is edited.
|
||||
let row = Row(dictionary: ["name": "Arthur", "age": 41])
|
||||
let person = Person(row: row)
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
let person = Person(row)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
|
||||
func testRecordIsNotEditedAfterFullFetch() {
|
||||
// Fetch a record from a row that contains all the columns in
|
||||
// storedDatabaseDictionary: An update statement, which only saves the
|
||||
// columns in storedDatabaseDictionary would perform no change. So the
|
||||
// persistentDictionary: An update statement, which only saves the
|
||||
// columns in persistentDictionary would perform no change. So the
|
||||
// record is not edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
try Person(name: "Arthur", age: 41).insert(db)
|
||||
let person = Person.fetchOne(db, "SELECT * FROM persons")!
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -80,7 +80,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
|
||||
// Compare to an Int
|
||||
let record = IntegerPropertyOnRealAffinityColumn.fetchOne(db, "SELECT * FROM t")!
|
||||
let row2 = Row(dictionary: record.storedDatabaseDictionary)
|
||||
let row2 = Row(dictionary: record.persistentDictionary)
|
||||
switch row2["value"]!.storage {
|
||||
case .Int64(let int64):
|
||||
XCTAssertEqual(int64, 1)
|
||||
@@ -88,35 +88,35 @@ class RecordEditedTests: GRDBTestCase {
|
||||
XCTFail("Unexpected DatabaseValue")
|
||||
}
|
||||
|
||||
XCTAssertFalse(record.databaseEdited)
|
||||
XCTAssertFalse(record.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordIsNotEditedAfterWiderThanFullFetch() {
|
||||
// Fetch a record from a row that contains all the columns in
|
||||
// storedDatabaseDictionary, plus extra ones: An update statement,
|
||||
// which only saves the columns in storedDatabaseDictionary would
|
||||
// persistentDictionary, plus extra ones: An update statement,
|
||||
// which only saves the columns in persistentDictionary would
|
||||
// perform no change. So the record is not edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
try Person(name: "Arthur", age: 41).insert(db)
|
||||
let person = Person.fetchOne(db, "SELECT *, 1 AS foo FROM persons")!
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordIsEditedAfterPartialFetch() {
|
||||
// Fetch a record from a row that does not contain all the columns in
|
||||
// storedDatabaseDictionary: An update statement saves the columns in
|
||||
// storedDatabaseDictionary, so it may perform unpredictable change.
|
||||
// persistentDictionary: An update statement saves the columns in
|
||||
// persistentDictionary, so it may perform unpredictable change.
|
||||
// So the record is edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
try Person(name: "Arthur", age: 41).insert(db)
|
||||
let person = Person.fetchOne(db, "SELECT name FROM persons")!
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -127,13 +127,13 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try dbQueue.inDatabase { db in
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
try person.insert(db)
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testRecordIsEditedAfterValueChange() {
|
||||
// Any change in a value exposed in storedDatabaseDictionary yields a
|
||||
// Any change in a value exposed in persistentDictionary yields a
|
||||
// record that is edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -142,21 +142,21 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try person.insert(db)
|
||||
XCTAssertTrue(person.name != nil)
|
||||
person.name = "Bobby" // non-nil vs. non-nil
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
do {
|
||||
let person = Person(name: "Arthur")
|
||||
try person.insert(db)
|
||||
XCTAssertTrue(person.name != nil)
|
||||
person.name = nil // non-nil vs. nil
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
do {
|
||||
let person = Person(name: "Arthur")
|
||||
try person.insert(db)
|
||||
XCTAssertTrue(person.age == nil)
|
||||
person.age = 41 // nil vs. non-nil
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -170,14 +170,14 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try person.insert(db)
|
||||
XCTAssertTrue(person.name != nil)
|
||||
person.name = "Arthur" // non-nil vs. non-nil
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
}
|
||||
do {
|
||||
let person = Person(name: "Arthur")
|
||||
try person.insert(db)
|
||||
XCTAssertTrue(person.age == nil)
|
||||
person.age = nil // nil vs. nil
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -191,7 +191,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try person.insert(db)
|
||||
person.name = "Bobby"
|
||||
try person.update(db)
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -202,11 +202,11 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try dbQueue.inDatabase { db in
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
try person.save(db)
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
person.name = "Bobby"
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
try person.save(db)
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -218,7 +218,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
try person.insert(db)
|
||||
person.id = person.id + 1
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -229,42 +229,38 @@ class RecordEditedTests: GRDBTestCase {
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
|
||||
try person.insert(db)
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.copy().databaseEdited)
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
XCTAssertFalse(person.copy().hasPersistentChangedValues)
|
||||
|
||||
person.name = "Barbara"
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.copy().databaseEdited)
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
XCTAssertTrue(person.copy().hasPersistentChangedValues)
|
||||
|
||||
person.databaseEdited = false
|
||||
XCTAssertFalse(person.databaseEdited)
|
||||
XCTAssertFalse(person.copy().databaseEdited)
|
||||
person.hasPersistentChangedValues = false
|
||||
XCTAssertFalse(person.hasPersistentChangedValues)
|
||||
XCTAssertFalse(person.copy().hasPersistentChangedValues)
|
||||
|
||||
person.databaseEdited = true
|
||||
XCTAssertTrue(person.databaseEdited)
|
||||
XCTAssertTrue(person.copy().databaseEdited)
|
||||
person.hasPersistentChangedValues = true
|
||||
XCTAssertTrue(person.hasPersistentChangedValues)
|
||||
XCTAssertTrue(person.copy().hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testChangesAfterInit() {
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
let changes = person.databaseChanges
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 4)
|
||||
for (column, (old: old, new: new)) in changes {
|
||||
for (column, old) in changes {
|
||||
switch column {
|
||||
case "id":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
case "name":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, "Arthur".databaseValue)
|
||||
case "age":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, 41.databaseValue)
|
||||
case "creationDate":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
@@ -272,23 +268,19 @@ class RecordEditedTests: GRDBTestCase {
|
||||
}
|
||||
|
||||
func testChangesAfterInitFromRow() {
|
||||
let person = Person(row: Row(dictionary:["name": "Arthur", "age": 41]))
|
||||
let changes = person.databaseChanges
|
||||
let person = Person(Row(dictionary:["name": "Arthur", "age": 41]))
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 4)
|
||||
for (column, (old: old, new: new)) in changes {
|
||||
for (column, old) in changes {
|
||||
switch column {
|
||||
case "id":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
case "name":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, "Arthur".databaseValue)
|
||||
case "age":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, 41.databaseValue)
|
||||
case "creationDate":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
@@ -297,14 +289,14 @@ class RecordEditedTests: GRDBTestCase {
|
||||
|
||||
func testChangesAfterFullFetch() {
|
||||
// Fetch a record from a row that contains all the columns in
|
||||
// storedDatabaseDictionary: An update statement, which only saves the
|
||||
// columns in storedDatabaseDictionary would perform no change. So the
|
||||
// persistentDictionary: An update statement, which only saves the
|
||||
// columns in persistentDictionary would perform no change. So the
|
||||
// record is not edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
try Person(name: "Arthur", age: 41).insert(db)
|
||||
let person = Person.fetchOne(db, "SELECT * FROM persons")!
|
||||
let changes = person.databaseChanges
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 0)
|
||||
}
|
||||
}
|
||||
@@ -312,26 +304,23 @@ class RecordEditedTests: GRDBTestCase {
|
||||
|
||||
func testChangesAfterPartialFetch() {
|
||||
// Fetch a record from a row that does not contain all the columns in
|
||||
// storedDatabaseDictionary: An update statement saves the columns in
|
||||
// storedDatabaseDictionary, so it may perform unpredictable change.
|
||||
// persistentDictionary: An update statement saves the columns in
|
||||
// persistentDictionary, so it may perform unpredictable change.
|
||||
// So the record is edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
try Person(name: "Arthur", age: 41).insert(db)
|
||||
let person = Person.fetchOne(db, "SELECT name FROM persons")!
|
||||
let changes = person.databaseChanges
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 3)
|
||||
for (column, (old: old, new: new)) in changes {
|
||||
for (column, old) in changes {
|
||||
switch column {
|
||||
case "id":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
case "age":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
case "creationDate":
|
||||
XCTAssertTrue(old == nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
@@ -346,14 +335,14 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try dbQueue.inDatabase { db in
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
try person.insert(db)
|
||||
let changes = person.databaseChanges
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func testChangesAfterValueChange() {
|
||||
// Any change in a value exposed in storedDatabaseDictionary yields a
|
||||
// Any change in a value exposed in persistentDictionary yields a
|
||||
// record that is edited.
|
||||
assertNoError {
|
||||
try dbQueue.inDatabase { db in
|
||||
@@ -363,19 +352,16 @@ class RecordEditedTests: GRDBTestCase {
|
||||
person.name = "Bobby" // non-nil -> non-nil
|
||||
person.age = 41 // nil -> non-nil
|
||||
person.creationDate = nil // non-nil -> nil
|
||||
let changes = person.databaseChanges
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 3)
|
||||
for (column, (old: old, new: new)) in changes {
|
||||
for (column, old) in changes {
|
||||
switch column {
|
||||
case "name":
|
||||
XCTAssertEqual(old, "Arthur".databaseValue)
|
||||
XCTAssertEqual(new, "Bobby".databaseValue)
|
||||
case "age":
|
||||
XCTAssertEqual(old, DatabaseValue.Null)
|
||||
XCTAssertEqual(new, 41.databaseValue)
|
||||
case "creationDate":
|
||||
XCTAssertTrue((old?.value() as NSDate?) != nil)
|
||||
XCTAssertEqual(new, DatabaseValue.Null)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
@@ -392,7 +378,7 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try person.insert(db)
|
||||
person.name = "Bobby"
|
||||
try person.update(db)
|
||||
XCTAssertEqual(person.databaseChanges.count, 0)
|
||||
XCTAssertEqual(person.persistentChangedValues.count, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -403,22 +389,21 @@ class RecordEditedTests: GRDBTestCase {
|
||||
try dbQueue.inDatabase { db in
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
try person.save(db)
|
||||
XCTAssertEqual(person.databaseChanges.count, 0)
|
||||
XCTAssertEqual(person.persistentChangedValues.count, 0)
|
||||
|
||||
person.name = "Bobby"
|
||||
let changes = person.databaseChanges
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 1)
|
||||
for (column, (old: old, new: new)) in changes {
|
||||
for (column, old) in changes {
|
||||
switch column {
|
||||
case "name":
|
||||
XCTAssertEqual(old, "Arthur".databaseValue)
|
||||
XCTAssertEqual(new, "Bobby".databaseValue)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
}
|
||||
try person.save(db)
|
||||
XCTAssertEqual(person.databaseChanges.count, 0)
|
||||
XCTAssertEqual(person.persistentChangedValues.count, 0)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -430,13 +415,12 @@ class RecordEditedTests: GRDBTestCase {
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
try person.insert(db)
|
||||
person.id = person.id + 1
|
||||
let changes = person.databaseChanges
|
||||
let changes = person.persistentChangedValues
|
||||
XCTAssertEqual(changes.count, 1)
|
||||
for (column, (old: old, new: new)) in changes {
|
||||
for (column, old) in changes {
|
||||
switch column {
|
||||
case "id":
|
||||
XCTAssertEqual(old, (person.id - 1).databaseValue)
|
||||
XCTAssertEqual(new, person.id.databaseValue)
|
||||
default:
|
||||
XCTFail("Unexpected column: \(column)")
|
||||
}
|
||||
@@ -451,20 +435,20 @@ class RecordEditedTests: GRDBTestCase {
|
||||
let person = Person(name: "Arthur", age: 41)
|
||||
|
||||
try person.insert(db)
|
||||
XCTAssertEqual(person.databaseChanges.count, 0)
|
||||
XCTAssertEqual(person.copy().databaseChanges.count, 0)
|
||||
XCTAssertEqual(person.persistentChangedValues.count, 0)
|
||||
XCTAssertEqual(person.copy().persistentChangedValues.count, 0)
|
||||
|
||||
person.name = "Barbara"
|
||||
XCTAssertTrue(person.databaseChanges.count > 0) // TODO: compare actual changes
|
||||
XCTAssertEqual(person.databaseChanges.count, person.copy().databaseChanges.count)
|
||||
XCTAssertTrue(person.persistentChangedValues.count > 0) // TODO: compare actual changes
|
||||
XCTAssertEqual(person.persistentChangedValues.count, person.copy().persistentChangedValues.count)
|
||||
|
||||
person.databaseEdited = false
|
||||
XCTAssertEqual(person.databaseChanges.count, 0)
|
||||
XCTAssertEqual(person.copy().databaseChanges.count, 0)
|
||||
person.hasPersistentChangedValues = false
|
||||
XCTAssertEqual(person.persistentChangedValues.count, 0)
|
||||
XCTAssertEqual(person.copy().persistentChangedValues.count, 0)
|
||||
|
||||
person.databaseEdited = true
|
||||
XCTAssertTrue(person.databaseChanges.count > 0) // TODO: compare actual changes
|
||||
XCTAssertEqual(person.databaseChanges.count, person.copy().databaseChanges.count)
|
||||
person.hasPersistentChangedValues = true
|
||||
XCTAssertTrue(person.persistentChangedValues.count > 0) // TODO: compare actual changes
|
||||
XCTAssertEqual(person.persistentChangedValues.count, person.copy().persistentChangedValues.count)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ class RecordFetchTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", Person.setupInDatabase)
|
||||
migrator.registerMigration("createPerson", migrate: Person.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
|
||||
@@ -15,12 +15,12 @@ class EmptyRecordWithoutInitializer : Record {
|
||||
// let name: String?
|
||||
// }
|
||||
|
||||
// What happens with a mutable property, and init(row: Row)?
|
||||
// What happens with a mutable property, and init(_ row: Row)?
|
||||
class RecordWithMutablePropertyAndRowInitializer : Record {
|
||||
var name: String?
|
||||
|
||||
required init(row: Row) {
|
||||
super.init(row: row) // super.init(row: row) is required
|
||||
required init(_ row: Row) {
|
||||
super.init(row) // super.init(row) is required
|
||||
self.name = "toto" // property can be set before or after super.init
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,8 @@ class RecordWithMutablePropertyAndEmptyInitializer : Record {
|
||||
self.name = "toto" // property can be set before or after super.init
|
||||
}
|
||||
|
||||
required init(row: Row) { // init(row: row) is required
|
||||
super.init(row: row) // super.init(row: row) is required
|
||||
required init(_ row: Row) { // init(row) is required
|
||||
super.init(row) // super.init(row) is required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,8 +48,8 @@ class RecordWithMutablePropertyAndCustomInitializer : Record {
|
||||
super.init() // super.init() is required
|
||||
}
|
||||
|
||||
required init(row: Row) { // init(row: row) is required
|
||||
super.init(row: row) // super.init(row: row) is required
|
||||
required init(_ row: Row) { // init(row) is required
|
||||
super.init(row) // super.init(row) is required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -57,9 +57,9 @@ class RecordWithMutablePropertyAndCustomInitializer : Record {
|
||||
class RecordWithImmutableProperty : Record {
|
||||
let initializedFromRow: Bool
|
||||
|
||||
required init(row: Row) { // An initializer is required, and the minimum is init(row: row)
|
||||
initializedFromRow = true // property must bet set before super.init(row: row)
|
||||
super.init(row: row) // super.init(row: row) is required
|
||||
required init(_ row: Row) { // An initializer is required, and the minimum is init(row)
|
||||
initializedFromRow = true // property must bet set before super.init(row)
|
||||
super.init(row) // super.init(row) is required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -68,13 +68,13 @@ class RecordWithPedigree : Record {
|
||||
let initializedFromRow: Bool
|
||||
|
||||
override init() {
|
||||
initializedFromRow = false // property must bet set before super.init(row: row)
|
||||
initializedFromRow = false // property must bet set before super.init(row)
|
||||
super.init() // super.init() is required
|
||||
}
|
||||
|
||||
required init(row: Row) { // An initializer is required, and the minimum is init(row: row)
|
||||
initializedFromRow = true // property must bet set before super.init(row: row)
|
||||
super.init(row: row) // super.init(row: row) is required
|
||||
required init(_ row: Row) { // An initializer is required, and the minimum is init(row)
|
||||
initializedFromRow = true // property must bet set before super.init(row)
|
||||
super.init(row) // super.init(row) is required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,13 +83,13 @@ class RecordWithImmutablePropertyAndCustomInitializer : Record {
|
||||
let initializedFromRow: Bool
|
||||
|
||||
init(name: String? = nil) {
|
||||
initializedFromRow = false // property must bet set before super.init(row: row)
|
||||
initializedFromRow = false // property must bet set before super.init(row)
|
||||
super.init() // super.init() is required
|
||||
}
|
||||
|
||||
required init(row: Row) { // An initializer is required, and the minimum is init(row: row)
|
||||
initializedFromRow = true // property must bet set before super.init(row: row)
|
||||
super.init(row: row) // super.init(row: row) is required
|
||||
required init(_ row: Row) { // An initializer is required, and the minimum is init(row)
|
||||
initializedFromRow = true // property must bet set before super.init(row)
|
||||
super.init(row) // super.init(row) is required
|
||||
}
|
||||
}
|
||||
|
||||
@@ -97,7 +97,7 @@ class RecordInitializersTests : GRDBTestCase {
|
||||
|
||||
func testFetchedRecordAreInitializedFromRow() {
|
||||
|
||||
// Here we test that Record.init(row: Row) can be overriden independently from Record.init().
|
||||
// Here we test that Record.init(_ row: Row) can be overriden independently from Record.init().
|
||||
// People must be able to perform some initialization work when fetching records from the database.
|
||||
|
||||
XCTAssertFalse(RecordWithPedigree().initializedFromRow)
|
||||
|
||||
@@ -6,9 +6,9 @@ class MinimalPersonWithOverrides : Person {
|
||||
|
||||
// Record
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
extra = row.value(named: "extra")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,9 +27,9 @@ class PersonWithOverrides : Person {
|
||||
|
||||
// Record
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
extra = row.value(named: "extra")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override func insert(db: Database) throws {
|
||||
@@ -49,7 +49,7 @@ class RecordSubClassTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createPerson", Person.setupInDatabase)
|
||||
migrator.registerMigration("createPerson", migrate: Person.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ import XCTest
|
||||
import GRDB
|
||||
|
||||
// BadlyMangledStuff.updateFromRow() accepts a row with mangled column names.
|
||||
// Its databaseEdited flag is wrong.
|
||||
// Its hasPersistentChangedValues flag is wrong.
|
||||
class BadlyMangledStuff : Record {
|
||||
var id: Int64?
|
||||
var name: String?
|
||||
@@ -23,15 +23,15 @@ class BadlyMangledStuff : Record {
|
||||
return "stuffs"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
// Here user may peek fancy column names that match his SQL queries.
|
||||
// However this is not the way to do it (see testBadlyMangledStuff()).
|
||||
id = row.value(named: "mangled_id")
|
||||
name = row.value(named: "mangled_name")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
// User won't peek fancy column names because he will notice that the
|
||||
// generated INSERT query needs actual column names.
|
||||
return ["id": id, "name": name]
|
||||
@@ -48,7 +48,7 @@ class RecordWithColumnNameManglingTests: GRDBTestCase {
|
||||
super.setUp()
|
||||
|
||||
var migrator = DatabaseMigrator()
|
||||
migrator.registerMigration("createBadlyMangledStuff", BadlyMangledStuff.setupInDatabase)
|
||||
migrator.registerMigration("createBadlyMangledStuff", migrate: BadlyMangledStuff.setupInDatabase)
|
||||
assertNoError {
|
||||
try migrator.migrate(dbQueue)
|
||||
}
|
||||
@@ -63,7 +63,7 @@ class RecordWithColumnNameManglingTests: GRDBTestCase {
|
||||
try record.save(db)
|
||||
|
||||
// Nothing special here
|
||||
XCTAssertFalse(record.databaseEdited)
|
||||
XCTAssertFalse(record.hasPersistentChangedValues)
|
||||
}
|
||||
do {
|
||||
let record = BadlyMangledStuff.fetchOne(db, "SELECT id AS mangled_id, name AS mangled_name FROM stuffs")!
|
||||
@@ -73,7 +73,7 @@ class RecordWithColumnNameManglingTests: GRDBTestCase {
|
||||
|
||||
// But here lies the problem with BadlyMangledStuff.
|
||||
// It should not be edited:
|
||||
XCTAssertTrue(record.databaseEdited)
|
||||
XCTAssertTrue(record.hasPersistentChangedValues)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -507,7 +507,7 @@ public final class Database {
|
||||
/// not exist.
|
||||
///
|
||||
/// This method is not thread-safe.
|
||||
func primaryKeyForTable(named tableName: String) -> PrimaryKey? {
|
||||
func primaryKey(tableName: String) -> PrimaryKey? {
|
||||
// https://www.sqlite.org/pragma.html
|
||||
//
|
||||
// > PRAGMA database.table_info(table-name);
|
||||
@@ -532,7 +532,7 @@ public final class Database {
|
||||
// 1 | firstName | TEXT | 0 | NULL | 0 |
|
||||
// 2 | lastName | TEXT | 0 | NULL | 0 |
|
||||
|
||||
let columnInfos = columnInfosForTable(named: tableName)
|
||||
let columnInfos = self.columnInfos(tableName)
|
||||
guard columnInfos.count > 0 else {
|
||||
// Table does not exist
|
||||
return nil
|
||||
@@ -609,9 +609,9 @@ public final class Database {
|
||||
}
|
||||
}
|
||||
|
||||
// Cache for columnInfosForTable(named:)
|
||||
// Cache for columnInfos()
|
||||
private var columnInfosCache: [String: [ColumnInfo]] = [:]
|
||||
private func columnInfosForTable(named tableName: String) -> [ColumnInfo] {
|
||||
private func columnInfos(tableName: String) -> [ColumnInfo] {
|
||||
if let columnInfos = columnInfosCache[tableName] {
|
||||
return columnInfos
|
||||
} else {
|
||||
|
||||
@@ -53,18 +53,18 @@ public struct DatabaseValue : Hashable {
|
||||
/// The NULL DatabaseValue.
|
||||
public static let Null = DatabaseValue(storage: .Null)
|
||||
|
||||
/// Returns a DatabaseValue storing an Integer.
|
||||
public init(int64: Swift.Int64) {
|
||||
/// Returns a DatabaseValue storing an Int64.
|
||||
init(_ int64: Swift.Int64) {
|
||||
storage = .Int64(int64)
|
||||
}
|
||||
|
||||
/// Returns a DatabaseValue storing an Double.
|
||||
public init(double: Swift.Double) {
|
||||
/// Returns a DatabaseValue storing a Double.
|
||||
init(_ double: Swift.Double) {
|
||||
storage = .Double(double)
|
||||
}
|
||||
|
||||
/// Returns a DatabaseValue storing a String.
|
||||
public init(string: Swift.String) {
|
||||
init(_ string: Swift.String) {
|
||||
storage = .String(string)
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ public struct DatabaseValue : Hashable {
|
||||
///
|
||||
/// SQLite cant' store zero-length blobs: if data has zero length, the
|
||||
/// result is NULL.
|
||||
public init(data: NSData) {
|
||||
init(_ data: NSData) {
|
||||
if data.length == 0 {
|
||||
// SQLite cant' store zero-length blobs.
|
||||
storage = .Null
|
||||
@@ -82,7 +82,7 @@ public struct DatabaseValue : Hashable {
|
||||
}
|
||||
|
||||
/// Copy initializer
|
||||
public init(_ databaseValue: DatabaseValue) {
|
||||
init(_ databaseValue: DatabaseValue) {
|
||||
// This initializer is used by DatabaseValue.init?(object: AnyObject)
|
||||
self = databaseValue
|
||||
}
|
||||
|
||||
@@ -42,11 +42,11 @@ public protocol MutableDatabasePersistable : DatabaseTableMapping {
|
||||
/// var id: Int64?
|
||||
/// var name: String?
|
||||
///
|
||||
/// var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
/// var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
/// return ["id": id, "name": name]
|
||||
/// }
|
||||
/// }
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] { get }
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] { get }
|
||||
|
||||
/// Don't call this method directly: it is called upon successful insertion,
|
||||
/// with the inserted RowID and the eventual INTEGER PRIMARY KEY
|
||||
@@ -353,7 +353,6 @@ public extension DatabasePersistable {
|
||||
|
||||
/// The default implementation does nothing.
|
||||
func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
|
||||
}
|
||||
|
||||
// MARK: - Immutable CRUD
|
||||
@@ -437,10 +436,10 @@ final class DataMapper {
|
||||
/// The persistable
|
||||
let persistable: MutableDatabasePersistable
|
||||
|
||||
/// DataMapper keeps a copy the persistable's storedDatabaseDictionary, so
|
||||
/// DataMapper keeps a copy the persistable's persistentDictionary, so
|
||||
/// that this dictionary is built once whatever the database operation.
|
||||
/// It is guaranteed to have at least one (key, value) pair.
|
||||
let storedDatabaseDictionary: [String: DatabaseValueConvertible?]
|
||||
let persistentDictionary: [String: DatabaseValueConvertible?]
|
||||
|
||||
/// The table name
|
||||
let databaseTableName: String
|
||||
@@ -448,8 +447,7 @@ final class DataMapper {
|
||||
/// The table primary key
|
||||
let primaryKey: PrimaryKey
|
||||
|
||||
/// An excerpt from storedDatabaseDictionary whose keys are primary key
|
||||
/// columns.
|
||||
/// An excerpt from persistentDictionary whose keys are primary key columns.
|
||||
///
|
||||
/// It is nil when persistable has no primary key.
|
||||
lazy var primaryKeyDictionary: [String: DatabaseValueConvertible?]? = { [unowned self] in
|
||||
@@ -457,15 +455,15 @@ final class DataMapper {
|
||||
guard columns.count > 0 else {
|
||||
return nil
|
||||
}
|
||||
let storedDatabaseDictionary = self.storedDatabaseDictionary
|
||||
let persistentDictionary = self.persistentDictionary
|
||||
var dictionary: [String: DatabaseValueConvertible?] = [:]
|
||||
for column in columns {
|
||||
dictionary[column] = storedDatabaseDictionary[column]
|
||||
dictionary[column] = persistentDictionary[column]
|
||||
}
|
||||
return dictionary
|
||||
}()
|
||||
|
||||
/// An excerpt from storedDatabaseDictionary whose keys are primary key
|
||||
/// An excerpt from persistentDictionary whose keys are primary key
|
||||
/// columns. It is able to resolve a row in the database.
|
||||
///
|
||||
/// It is nil when the primaryKeyDictionary is nil or unable to identify a
|
||||
@@ -511,19 +509,19 @@ final class DataMapper {
|
||||
let databaseTableName = persistable.dynamicType.databaseTableName()
|
||||
|
||||
// Fail early if database table does not exist.
|
||||
guard let primaryKey = db.primaryKeyForTable(named: databaseTableName) else {
|
||||
guard let primaryKey = db.primaryKey(databaseTableName) else {
|
||||
fatalError("Table \(databaseTableName.quotedDatabaseIdentifier) does not exist. See \(persistable.dynamicType).databaseTableName()")
|
||||
}
|
||||
|
||||
// Fail early if storedDatabaseDictionary is empty
|
||||
let storedDatabaseDictionary = persistable.storedDatabaseDictionary
|
||||
guard storedDatabaseDictionary.count > 0 else {
|
||||
fatalError("Invalid empty dictionary returned from \(persistable.dynamicType).storedDatabaseDictionary")
|
||||
// Fail early if persistentDictionary is empty
|
||||
let persistentDictionary = persistable.persistentDictionary
|
||||
guard persistentDictionary.count > 0 else {
|
||||
fatalError("Invalid empty dictionary returned from \(persistable.dynamicType).persistentDictionary")
|
||||
}
|
||||
|
||||
self.db = db
|
||||
self.persistable = persistable
|
||||
self.storedDatabaseDictionary = storedDatabaseDictionary
|
||||
self.persistentDictionary = persistentDictionary
|
||||
self.databaseTableName = databaseTableName
|
||||
self.primaryKey = primaryKey
|
||||
}
|
||||
@@ -532,8 +530,8 @@ final class DataMapper {
|
||||
// MARK: - Statement builders
|
||||
|
||||
func insertStatement() -> UpdateStatement {
|
||||
let insertStatement = db.updateStatement(DataMapper.insertSQL(tableName: databaseTableName, insertedColumns: Array(storedDatabaseDictionary.keys)))
|
||||
insertStatement.arguments = StatementArguments(storedDatabaseDictionary.values)
|
||||
let insertStatement = db.updateStatement(DataMapper.insertSQL(tableName: databaseTableName, insertedColumns: Array(persistentDictionary.keys)))
|
||||
insertStatement.arguments = StatementArguments(persistentDictionary.values)
|
||||
return insertStatement
|
||||
}
|
||||
|
||||
@@ -544,7 +542,7 @@ final class DataMapper {
|
||||
}
|
||||
|
||||
// Don't update primary key columns
|
||||
var updatedDictionary = storedDatabaseDictionary
|
||||
var updatedDictionary = persistentDictionary
|
||||
for column in primaryKeyDictionary.keys {
|
||||
updatedDictionary.removeValueForKey(column)
|
||||
}
|
||||
@@ -559,7 +557,7 @@ final class DataMapper {
|
||||
//
|
||||
// The goal is to be able to write tests with minimal tables,
|
||||
// including tables made of a single primary key column.
|
||||
updatedDictionary = storedDatabaseDictionary
|
||||
updatedDictionary = persistentDictionary
|
||||
}
|
||||
|
||||
// Update
|
||||
|
||||
@@ -70,7 +70,7 @@ extension RowConvertible where Self: DatabaseTableMapping {
|
||||
let databaseTableName = self.databaseTableName()
|
||||
|
||||
// Fail early if database table does not exist.
|
||||
guard let primaryKey = db.primaryKeyForTable(named: databaseTableName) else {
|
||||
guard let primaryKey = db.primaryKey(databaseTableName) else {
|
||||
fatalError("Table \(databaseTableName.quotedDatabaseIdentifier) does not exist. See \(self).databaseTableName()")
|
||||
}
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ public protocol DatabaseValueConvertible : RowConvertible {
|
||||
static func fromDatabaseValue(databaseValue: DatabaseValue) -> Self?
|
||||
}
|
||||
|
||||
/// DatabaseValueConvertible adopts RowConvertible
|
||||
/// DatabaseValueConvertible inherits from RowConvertible.
|
||||
public extension DatabaseValueConvertible {
|
||||
|
||||
/// Returns the value initialized from the leftmost column of the row.
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/// Types that adopt RowConvertible can be initialized from a database Row.
|
||||
///
|
||||
/// let row = Row.fetchOne(db, "SELECT ...")!
|
||||
/// let person = Person(row: row)
|
||||
/// let person = Person(row)
|
||||
///
|
||||
/// The protocol comes with built-in methods that allow to fetch sequences,
|
||||
/// arrays, or single values:
|
||||
|
||||
@@ -5,7 +5,7 @@ extension CGFloat : DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(double: Double(self))
|
||||
return DatabaseValue(Double(self))
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
|
||||
@@ -22,7 +22,7 @@ public struct DatabaseCoder: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(data: NSKeyedArchiver.archivedDataWithRootObject(object))
|
||||
return DatabaseValue(NSKeyedArchiver.archivedDataWithRootObject(object))
|
||||
}
|
||||
|
||||
/// Returns a DatabaseCoder if *databaseValue* contains an archived object.
|
||||
|
||||
@@ -95,7 +95,7 @@ public struct DatabaseDateComponents : DatabaseValueConvertible {
|
||||
timeString = nil
|
||||
}
|
||||
|
||||
return DatabaseValue(string: [dateString, timeString].flatMap { $0 }.joinWithSeparator(" "))
|
||||
return DatabaseValue([dateString, timeString].flatMap { $0 }.joinWithSeparator(" "))
|
||||
}
|
||||
|
||||
/// Returns a DatabaseDateComponents if *databaseValue* contains a
|
||||
|
||||
@@ -4,7 +4,7 @@ import Foundation
|
||||
extension NSData : DatabaseValueConvertible {
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(data: self)
|
||||
return DatabaseValue(self)
|
||||
}
|
||||
|
||||
/// Returns an NSData initialized from *databaseValue*, if it contains
|
||||
|
||||
@@ -6,7 +6,7 @@ extension NSDate : DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: storageDateFormatter.stringFromDate(self))
|
||||
return DatabaseValue(storageDateFormatter.stringFromDate(self))
|
||||
}
|
||||
|
||||
/// Returns an NSDate initialized from *databaseValue*, if possible.
|
||||
|
||||
@@ -5,7 +5,7 @@ extension NSString: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: self as String)
|
||||
return DatabaseValue(self as String)
|
||||
}
|
||||
|
||||
/// Returns an NSString initialized from *databaseValue*, if possible.
|
||||
|
||||
@@ -6,7 +6,7 @@ extension NSURL : DatabaseValueConvertible {
|
||||
/// Returns a value that can be stored in the database.
|
||||
/// (the URL's absoluteString).
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: absoluteString)
|
||||
return DatabaseValue(absoluteString)
|
||||
}
|
||||
|
||||
/// Returns an NSURL initialized from *databaseValue*, if possible.
|
||||
|
||||
@@ -53,28 +53,24 @@ public struct DatabaseMigrator {
|
||||
/// ")")
|
||||
/// }
|
||||
///
|
||||
/// - parameter identifier: The migration identifier. It must be unique.
|
||||
/// - parameter block: The migration block that performs SQL statements.
|
||||
public mutating func registerMigration(identifier: String, _ block: (db: Database) throws -> Void) {
|
||||
registerMigration(Migration(identifier: identifier, disableForeignKeys: false, block: block))
|
||||
}
|
||||
|
||||
/// Registers a migration with disabled foreign key checks.
|
||||
/// To perform advanced migrations, as described at https://www.sqlite.org/lang_altertable.html#otheralter,
|
||||
/// set the disabledForeignKeyChecks parameter to true:
|
||||
///
|
||||
/// migrator.registerMigrationWithDisabledForeignKeys("dropTableColumn") { db in
|
||||
/// try db.execute("...")
|
||||
/// // Add a NOT NULL constraint on persons.name:
|
||||
/// migrator.registerMigration("AddNotNullCheckOnName", withDisabledForeignKeyChecks: true) { db in
|
||||
/// try db.executeMultiStatement(
|
||||
/// "CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT NOT NULL);" +
|
||||
/// "INSERT INTO new_persons SELECT * FROM persons;" +
|
||||
/// "DROP TABLE persons;" +
|
||||
/// "ALTER TABLE new_persons RENAME TO persons;")
|
||||
/// }
|
||||
///
|
||||
/// This technique, described at https://www.sqlite.org/lang_altertable.html#otheralter,
|
||||
/// allows you to make arbitrary changes to the database schema.
|
||||
///
|
||||
/// If foreign key checks were enabled, they are enabled again after your
|
||||
/// migration code has run, regardless of eventual errors.
|
||||
///
|
||||
/// - parameter identifier: The migration identifier. It must be unique.
|
||||
/// - parameter disabledForeignKeyChecks: If true, the migration is run with
|
||||
/// disabled foreign key checks.
|
||||
/// - parameter block: The migration block that performs SQL statements.
|
||||
public mutating func registerMigrationWithoutForeignKeyChecks(identifier: String, _ block: (db: Database) throws -> Void) {
|
||||
registerMigration(Migration(identifier: identifier, disableForeignKeys: true, block: block))
|
||||
public mutating func registerMigration(identifier: String, withDisabledForeignKeyChecks disabledForeignKeyChecks: Bool = false, migrate: (db: Database) throws -> Void) {
|
||||
registerMigration(Migration(identifier: identifier, disabledForeignKeyChecks: disabledForeignKeyChecks, migrate: migrate))
|
||||
}
|
||||
|
||||
/// Iterate migrations in the same order as they were registered. If a
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/// An internal struct that defines a migration.
|
||||
struct Migration {
|
||||
let identifier: String
|
||||
let disableForeignKeys: Bool
|
||||
let block: (db: Database) throws -> Void
|
||||
let disabledForeignKeyChecks: Bool
|
||||
let migrate: (db: Database) throws -> Void
|
||||
|
||||
func run(db: Database) throws {
|
||||
if disableForeignKeys && Bool.fetchOne(db, "PRAGMA foreign_keys")! {
|
||||
if disabledForeignKeyChecks && Bool.fetchOne(db, "PRAGMA foreign_keys")! {
|
||||
try runWithDisabledForeignKeys(db)
|
||||
} else {
|
||||
try runWithoutDisabledForeignKeys(db)
|
||||
@@ -14,7 +14,7 @@ struct Migration {
|
||||
|
||||
private func runWithoutDisabledForeignKeys(db: Database) throws {
|
||||
try db.inTransaction(.Immediate) {
|
||||
try self.block(db: db)
|
||||
try self.migrate(db: db)
|
||||
try self.insertAppliedIdentifier(db)
|
||||
return .Commit
|
||||
}
|
||||
@@ -35,7 +35,7 @@ struct Migration {
|
||||
|
||||
// > 2. Start a transaction.
|
||||
try db.inTransaction(.Immediate) {
|
||||
try self.block(db: db)
|
||||
try self.migrate(db: db)
|
||||
try self.insertAppliedIdentifier(db)
|
||||
|
||||
// > 10. If foreign key constraints were originally enabled then run PRAGMA
|
||||
|
||||
+43
-41
@@ -21,7 +21,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// awakeFromFetch().
|
||||
///
|
||||
/// - parameter row: A Row
|
||||
required public init(row: Row) {
|
||||
required public init(_ row: Row) {
|
||||
}
|
||||
|
||||
/// Don't call this method directly. It is called after a Record has been
|
||||
@@ -31,8 +31,8 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
///
|
||||
/// - parameter row: A Row.
|
||||
public func awakeFromFetch(row: Row) {
|
||||
// Take care of the databaseEdited flag. If the row does not contain
|
||||
// all needed columns, the record turns edited.
|
||||
// Take care of the hasPersistentChangedValues flag. If the row does not
|
||||
/// contain ll needed columns, the record turns edited.
|
||||
//
|
||||
// Row may be a metal row which will turn invalid as soon as the SQLite
|
||||
// statement is iterated. We need to store an immutable and safe copy.
|
||||
@@ -44,7 +44,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// This method is required by the RowConvertible protocol. It returns a
|
||||
/// record initialized from the row. See init(row:Row).
|
||||
public final class func fromRow(row: Row) -> Self {
|
||||
return self.init(row: row)
|
||||
return self.init(row)
|
||||
}
|
||||
|
||||
|
||||
@@ -79,13 +79,13 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// var id: Int64?
|
||||
/// var name: String?
|
||||
///
|
||||
/// override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
/// override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
/// return ["id": id, "name": name]
|
||||
/// }
|
||||
/// }
|
||||
///
|
||||
/// The implementation of the base class Record returns an empty dictionary.
|
||||
public var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
public var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return [:]
|
||||
}
|
||||
|
||||
@@ -104,21 +104,21 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
// MARK: - Copy
|
||||
|
||||
/// Returns a copy of `self`, initialized from the values of
|
||||
/// storedDatabaseDictionary.
|
||||
/// persistentDictionary.
|
||||
///
|
||||
/// Note that the eventual primary key is copied, as well as the
|
||||
/// databaseEdited flag.
|
||||
/// hasPersistentChangedValues flag.
|
||||
///
|
||||
/// - returns: A copy of self.
|
||||
@warn_unused_result
|
||||
public func copy() -> Self {
|
||||
let copy = self.dynamicType.fromRow(Row(dictionary: storedDatabaseDictionary))
|
||||
let copy = self.dynamicType.fromRow(Row(dictionary: persistentDictionary))
|
||||
copy.referenceRow = referenceRow
|
||||
return copy
|
||||
}
|
||||
|
||||
|
||||
// MARK: - Changes
|
||||
// MARK: - Changes Tracking
|
||||
|
||||
/// A boolean that indicates whether the record has changes that have not
|
||||
/// been saved.
|
||||
@@ -126,7 +126,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// This flag is purely informative, and does not prevent insert(),
|
||||
/// update(), and save() from performing their database queries.
|
||||
///
|
||||
/// A record is *edited* if its *storedDatabaseDictionary* has been changed
|
||||
/// A record is *edited* if its *persistentDictionary* has been changed
|
||||
/// since last database synchronization (fetch, update, insert). Comparison
|
||||
/// is performed on *values*: setting a property to the same value does not
|
||||
/// trigger the edited flag.
|
||||
@@ -135,52 +135,50 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// you may set it to true or false when you know better. Setting it to
|
||||
/// false does not prevent it from turning true on subsequent modifications
|
||||
/// of the record.
|
||||
public var databaseEdited: Bool {
|
||||
public var hasPersistentChangedValues: Bool {
|
||||
get {
|
||||
return generateDatabaseChanges().next() != nil
|
||||
return generatePersistentChangedValues().next() != nil
|
||||
}
|
||||
set {
|
||||
if newValue {
|
||||
referenceRow = nil
|
||||
} else {
|
||||
referenceRow = Row(dictionary: storedDatabaseDictionary)
|
||||
referenceRow = Row(dictionary: persistentDictionary)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// A dictionary of changes that have not been saved.
|
||||
///
|
||||
/// Its keys are column names.
|
||||
/// Its keys are column names, and values the old values that have been
|
||||
/// changed since last fetching or saving of the record.
|
||||
///
|
||||
/// Its values are `(old: DatabaseValue?, new: DatabaseValue)` pairs, where
|
||||
/// *old* is the reference DatabaseValue, and *new* the current one.
|
||||
/// Unless the record has actually been fetched or saved, the old values
|
||||
/// are nil.
|
||||
///
|
||||
/// The old DatabaseValue is nil, which means unknown, unless the record has
|
||||
/// been fetched, updated or inserted.
|
||||
///
|
||||
/// See `databaseEdited` for more information.
|
||||
public var databaseChanges: [String: (old: DatabaseValue?, new: DatabaseValue)] {
|
||||
var changes: [String: (old: DatabaseValue?, new: DatabaseValue)] = [:]
|
||||
for (column: column, old: old, new: new) in generateDatabaseChanges() {
|
||||
changes[column] = (old: old, new: new)
|
||||
/// See `hasPersistentChangedValues` for more information.
|
||||
public var persistentChangedValues: [String: DatabaseValue?] {
|
||||
var changes: [String: DatabaseValue?] = [:]
|
||||
for (column: column, old: old) in generatePersistentChangedValues() {
|
||||
changes[column] = old
|
||||
}
|
||||
return changes
|
||||
}
|
||||
|
||||
// A change generator that is used by both databaseEdited and
|
||||
// databaseChanges properties.
|
||||
private func generateDatabaseChanges() -> AnyGenerator<(column: String, old: DatabaseValue?, new: DatabaseValue)> {
|
||||
// A change generator that is used by both hasPersistentChangedValues and
|
||||
// persistentChangedValues properties.
|
||||
private func generatePersistentChangedValues() -> AnyGenerator<(column: String, old: DatabaseValue?)> {
|
||||
let oldRow = referenceRow
|
||||
var newValueGenerator = storedDatabaseDictionary.generate()
|
||||
var newValueGenerator = persistentDictionary.generate()
|
||||
return anyGenerator {
|
||||
// Loop until we find a change, or exhaust columns:
|
||||
while let (column, newValue) = newValueGenerator.next() {
|
||||
let new = newValue?.databaseValue ?? .Null
|
||||
guard let old = oldRow?[column] else {
|
||||
return (column: column, old: nil, new: new)
|
||||
return (column: column, old: nil)
|
||||
}
|
||||
if new != old {
|
||||
return (column: column, old: old, new: new)
|
||||
return (column: column, old: old)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@@ -188,7 +186,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
}
|
||||
|
||||
|
||||
/// Reference row for the *databaseEdited* property.
|
||||
/// Reference row for the *hasPersistentChangedValues* property.
|
||||
var referenceRow: Row?
|
||||
|
||||
|
||||
@@ -196,7 +194,8 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
|
||||
/// Executes an INSERT statement.
|
||||
///
|
||||
/// On success, this method sets the *databaseEdited* flag to false.
|
||||
/// On success, this method sets the *hasPersistentChangedValues* flag
|
||||
/// to false.
|
||||
///
|
||||
/// This method is guaranteed to have inserted a row in the database if it
|
||||
/// returns without error.
|
||||
@@ -209,12 +208,13 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// - throws: A DatabaseError whenever a SQLite error occurs.
|
||||
public func insert(db: Database) throws {
|
||||
try performInsert(db)
|
||||
databaseEdited = false
|
||||
hasPersistentChangedValues = false
|
||||
}
|
||||
|
||||
/// Executes an UPDATE statement.
|
||||
///
|
||||
/// On success, this method sets the *databaseEdited* flag to false.
|
||||
/// On success, this method sets the *hasPersistentChangedValues* flag
|
||||
/// to false.
|
||||
///
|
||||
/// This method is guaranteed to have updated a row in the database if it
|
||||
/// returns without error.
|
||||
@@ -225,7 +225,7 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
/// any row in the database and record could not be updated.
|
||||
public func update(db: Database) throws {
|
||||
try performUpdate(db)
|
||||
databaseEdited = false
|
||||
hasPersistentChangedValues = false
|
||||
}
|
||||
|
||||
/// Executes an INSERT or an UPDATE statement so that `self` is saved in
|
||||
@@ -236,7 +236,8 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
///
|
||||
/// Otherwise, performs an insert.
|
||||
///
|
||||
/// On success, this method sets the *databaseEdited* flag to false.
|
||||
/// On success, this method sets the *hasPersistentChangedValues* flag
|
||||
/// to false.
|
||||
///
|
||||
/// This method is guaranteed to have inserted or updated a row in the
|
||||
/// database if it returns without error.
|
||||
@@ -250,7 +251,8 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
|
||||
/// Executes a DELETE statement.
|
||||
///
|
||||
/// On success, this method sets the *databaseEdited* flag to true.
|
||||
/// On success, this method sets the *hasPersistentChangedValues* flag
|
||||
/// to true.
|
||||
///
|
||||
/// - parameter db: A Database.
|
||||
/// - returns: Whether a database row was deleted.
|
||||
@@ -259,8 +261,8 @@ public class Record : RowConvertible, DatabaseTableMapping, DatabasePersistable
|
||||
let deleted = try performDelete(db)
|
||||
// Future calls to update() will throw NotFound. Make the user
|
||||
// a favor and make sure this error is thrown even if she checks the
|
||||
// databaseEdited flag:
|
||||
databaseEdited = true
|
||||
// hasPersistentChangedValues flag:
|
||||
hasPersistentChangedValues = true
|
||||
return deleted
|
||||
}
|
||||
}
|
||||
@@ -273,7 +275,7 @@ extension Record : CustomStringConvertible {
|
||||
/// A textual representation of `self`.
|
||||
public var description: String {
|
||||
return "<\(self.dynamicType)"
|
||||
+ storedDatabaseDictionary.map { (key, value) in
|
||||
+ persistentDictionary.map { (key, value) in
|
||||
if let value = value {
|
||||
return " \(key):\(String(reflecting: value))"
|
||||
} else {
|
||||
|
||||
@@ -25,7 +25,7 @@ extension DatabaseIntRepresentable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: Int64(rawValue))
|
||||
return DatabaseValue(Int64(rawValue))
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
@@ -68,7 +68,7 @@ extension DatabaseInt32Representable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: Int64(rawValue))
|
||||
return DatabaseValue(Int64(rawValue))
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
@@ -111,7 +111,7 @@ extension DatabaseInt64Representable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: rawValue)
|
||||
return DatabaseValue(rawValue)
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
@@ -154,7 +154,7 @@ extension DatabaseStringRepresentable {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: rawValue)
|
||||
return DatabaseValue(rawValue)
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
|
||||
@@ -11,7 +11,7 @@ extension Bool: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: self ? 1 : 0)
|
||||
return DatabaseValue(Int64(self ? 1 : 0))
|
||||
}
|
||||
|
||||
/// Returns a Bool initialized from *databaseValue*, if possible.
|
||||
@@ -99,7 +99,7 @@ extension Int: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: Int64(self))
|
||||
return DatabaseValue(Int64(self))
|
||||
}
|
||||
|
||||
/// Returns an Int initialized from *databaseValue*, if possible.
|
||||
@@ -131,7 +131,7 @@ extension Int32: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: Int64(self))
|
||||
return DatabaseValue(Int64(self))
|
||||
}
|
||||
|
||||
/// Returns an Int32 initialized from *databaseValue*, if possible.
|
||||
@@ -163,7 +163,7 @@ extension Int64: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(int64: self)
|
||||
return DatabaseValue(self)
|
||||
}
|
||||
|
||||
/// Returns an Int64 initialized from *databaseValue*, if possible.
|
||||
@@ -195,7 +195,7 @@ extension Double: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(double: self)
|
||||
return DatabaseValue(self)
|
||||
}
|
||||
|
||||
/// Returns a Double initialized from *databaseValue*, if possible.
|
||||
@@ -214,6 +214,38 @@ extension Double: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
}
|
||||
}
|
||||
|
||||
/// Float adopts DatabaseValueConvertible and SQLiteStatementConvertible.
|
||||
extension Float: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
/// Returns a value initialized from a raw SQLite statement pointer.
|
||||
///
|
||||
/// - parameter sqliteStatement: A pointer to a SQLite statement.
|
||||
/// - parameter index: The column index.
|
||||
public init(sqliteStatement: SQLiteStatement, index: Int32) {
|
||||
self = Float(sqlite3_column_double(sqliteStatement, index))
|
||||
}
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(Double(self))
|
||||
}
|
||||
|
||||
/// Returns a Float initialized from *databaseValue*, if possible.
|
||||
///
|
||||
/// - parameter databaseValue: A DatabaseValue.
|
||||
/// - returns: An optional Double.
|
||||
public static func fromDatabaseValue(databaseValue: DatabaseValue) -> Float? {
|
||||
switch databaseValue.storage {
|
||||
case .Int64(let int64):
|
||||
return Float(int64)
|
||||
case .Double(let double):
|
||||
return Float(double)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// String adopts DatabaseValueConvertible and SQLiteStatementConvertible.
|
||||
extension String: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
@@ -228,7 +260,7 @@ extension String: DatabaseValueConvertible, SQLiteStatementConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
public var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(string: self)
|
||||
return DatabaseValue(self)
|
||||
}
|
||||
|
||||
/// Returns a String initialized from *databaseValue*, if possible.
|
||||
|
||||
@@ -30,19 +30,30 @@ class Person : Record {
|
||||
var id: Int64?
|
||||
var name: String?
|
||||
|
||||
func updateFromJSON(json: NSDictionary) {
|
||||
id = (json["id"] as? NSNumber)?.longLongValue
|
||||
name = json["name"] as? String
|
||||
}
|
||||
|
||||
// Record overrides
|
||||
|
||||
override class func databaseTableName() -> String {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
override func updateFromRow(row: Row) {
|
||||
if let dbv = row["id"] { id = dbv.value() }
|
||||
if let dbv = row["name"] { name = dbv.value() }
|
||||
super.updateFromRow(row) // Subclasses are required to call super.
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
name = row.value(named: "name")
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
override func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -82,13 +93,12 @@ func synchronizePersonsWithJSON(jsonString: String, inDatabase db: Database) thr
|
||||
case .Right(let jsonPerson):
|
||||
// JSON person without matching database person:
|
||||
let row = Row(dictionary: jsonPerson)!
|
||||
let person = Person(row: row)
|
||||
let person = Person(row)
|
||||
try person.insert(db)
|
||||
case .Common(let person, let jsonPerson):
|
||||
// Matching database and JSON persons:
|
||||
let row = Row(dictionary: jsonPerson)!
|
||||
person.updateFromRow(row)
|
||||
if person.databaseEdited {
|
||||
person.updateFromJSON(jsonPerson)
|
||||
if person.hasPersistentChangedValues {
|
||||
try person.update(db)
|
||||
}
|
||||
}
|
||||
@@ -131,4 +141,4 @@ do {
|
||||
try synchronizePersonsWithJSON(jsonString, inDatabase: db)
|
||||
return .Commit
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -42,18 +42,19 @@ class Person : Record {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
firstName = row.value(named: "firstName")
|
||||
lastName = row.value(named: "lastName")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
return [
|
||||
"id": id,
|
||||
"firstName": firstName,
|
||||
"lastName": lastName]
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "firstName": firstName, "lastName": lastName]
|
||||
}
|
||||
|
||||
override func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -470,9 +470,6 @@ if let databaseValue = row["date"] {
|
||||
print("NSData: \(data)")
|
||||
}
|
||||
}
|
||||
|
||||
// Nil if the column is not present:
|
||||
let date: NSDate = row["date"]?.value()
|
||||
```
|
||||
|
||||
Iterate all the tuples (columnName, databaseValue) in a row, from left to right:
|
||||
@@ -558,7 +555,7 @@ Both `fetch` and `fetchAll` let you iterate the full list of fetched values. The
|
||||
|
||||
GRDB ships with built-in support for the following value types:
|
||||
|
||||
- **Swift Standard Library**: Bool, Double, Int, Int32, Int64, String, [Swift enums](#swift-enums).
|
||||
- **Swift Standard Library**: Bool, Float, Double, Int, Int32, Int64, String, [Swift enums](#swift-enums).
|
||||
|
||||
- **Foundation**: [NSData](#nsdata-and-memory-savings), [NSDate](#nsdate-and-nsdatecomponents), [NSDateComponents](#nsdate-and-nsdatecomponents), NSNull, NSNumber, NSString, NSURL.
|
||||
|
||||
@@ -589,14 +586,14 @@ They can be [directly fetched](#value-queries) from the database:
|
||||
let urls = NSURL.fetchAll(db, "SELECT url FROM links") // [NSURL]
|
||||
```
|
||||
|
||||
Use them in the `storedDatabaseDictionary` property of [DatabasePersistable protocol](#databasepersistable-protocol) and [Record subclasses](#record):
|
||||
Use them in the `persistentDictionary` property of [DatabasePersistable protocol](#databasepersistable-protocol) and [Record subclasses](#record):
|
||||
|
||||
```swift
|
||||
class Link : Record {
|
||||
var url: NSURL?
|
||||
var verified: Bool
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["url": url, "verified": verified]
|
||||
}
|
||||
}
|
||||
@@ -831,7 +828,7 @@ public protocol DatabaseValueConvertible {
|
||||
|
||||
All types that adopt this protocol can be used wherever the built-in types `Int`, `String`, etc. are used. without any limitation or caveat. Those built-in types actually adopt it.
|
||||
|
||||
The `databaseValue` property returns [DatabaseValue](GRDB/Core/DatabaseValue.swift), a type that wraps the five types supported by SQLite: NULL, Int64, Double, String and NSData.
|
||||
The `databaseValue` property returns [DatabaseValue](GRDB/Core/DatabaseValue.swift), a type that wraps the five types supported by SQLite: NULL, Int64, Double, String and NSData. DatabaseValue has no public initializer: to create one, use `DatabaseValue.Null`, or the fact that Int, String, etc. adopt the protocol: `1.databaseValue`, `"foo".databaseValue`.
|
||||
|
||||
The `fromDatabaseValue()` factory method returns an instance of your custom type, if the databaseValue contains a suitable value.
|
||||
|
||||
@@ -860,7 +857,8 @@ struct DatabaseTimestamp: DatabaseValueConvertible {
|
||||
|
||||
/// Returns a value that can be stored in the database.
|
||||
var databaseValue: DatabaseValue {
|
||||
return DatabaseValue(double: date.timeIntervalSince1970)
|
||||
// Double itself adopts DatabaseValueConvertible:
|
||||
return date.timeIntervalSince1970.databaseValue
|
||||
}
|
||||
|
||||
/// Returns a value initialized from *databaseValue*, if possible.
|
||||
@@ -1300,11 +1298,11 @@ NSBundle.mainBundle()
|
||||
|
||||
SQLite does not support many schema changes, and won't let you drop a table column with "ALTER TABLE ... DROP COLUMN ...", for example.
|
||||
|
||||
Yet any kind of schema change is still possible. The SQLite documentation explains in detail how to do so: https://www.sqlite.org/lang_altertable.html#otheralter. This technique requires the temporary disabling of foreign key checks, and is supported by a specific method of DatabaseMigrator:
|
||||
Yet any kind of schema change is still possible. The SQLite documentation explains in detail how to do so: https://www.sqlite.org/lang_altertable.html#otheralter. This technique requires the temporary disabling of foreign key checks:
|
||||
|
||||
```swift
|
||||
// Add a NOT NULL constraint on persons.name:
|
||||
migrator.registerMigrationWithoutForeignKeyChecks("AddNotNullCheckOnName") { db in
|
||||
migrator.registerMigration("AddNotNullCheckOnName", withDisabledForeignKeyChecks: true) { db in
|
||||
try db.executeMultiStatement(
|
||||
"CREATE TABLE new_persons (id INTEGER PRIMARY KEY, name TEXT NOT NULL);" +
|
||||
"INSERT INTO new_persons SELECT * FROM persons;" +
|
||||
@@ -1338,8 +1336,8 @@ try dbQueue.inDatabase { db in
|
||||
|
||||
// Changes tracking
|
||||
person.name = "Barbara"
|
||||
person.databaseChanges.keys // ["name"]
|
||||
if person.databaseEdited { // Avoid useless UPDATE statements
|
||||
person.persistentChangedValues.keys // ["name"]
|
||||
if person.hasPersistentChangedValues { // Avoid useless UPDATE statements
|
||||
try person.save(db)
|
||||
}
|
||||
}
|
||||
@@ -1520,8 +1518,8 @@ public protocol MutableDatabasePersistable : DatabaseTableMapping {
|
||||
/// The name of the database table (from DatabaseTableMapping)
|
||||
static func databaseTableName() -> String
|
||||
|
||||
/// Returns the values that should be stored in the database.
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] { get }
|
||||
/// Returns the values that should be persisted in the database.
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] { get }
|
||||
|
||||
/// Optional method that lets your adopting type store its rowID upon
|
||||
/// successful insertion. Don't call it directly: it is called for you.
|
||||
@@ -1556,7 +1554,7 @@ struct Country : DatabasePersistable {
|
||||
return "countries"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
}
|
||||
@@ -1577,13 +1575,13 @@ struct Person : MutableDatabasePersistable {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
// Update self.id upon successful insertion:
|
||||
// Update person ID upon successful insertion:
|
||||
mutating func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.id = rowID
|
||||
id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1594,7 +1592,7 @@ try person.insert(db)
|
||||
person.id // some value
|
||||
```
|
||||
|
||||
The `storedDatabaseDictionary` property returns a dictionary whose keys are column names, and values any DatabaseValueConvertible value (Bool, Int, String, NSDate, Swift enums, etc.) See [Values](#values) for more information.
|
||||
The `persistentDictionary` property returns a dictionary whose keys are column names, and values any DatabaseValueConvertible value (Bool, Int, String, NSDate, Swift enums, etc.) See [Values](#values) for more information.
|
||||
|
||||
> :point_up: **Note**: Classes should always prefer adopting `DatabasePersistable` over `MutableDatabasePersistable`, even if they mutate on insertion. This will prevent strange compiler errors when they insert an instance stored in a `let` variable (see [SR-142](https://bugs.swift.org/browse/SR-142)).
|
||||
|
||||
@@ -1750,8 +1748,8 @@ Yet, it does a few things well:
|
||||
person = Person.fetch...
|
||||
person.name = "Barbara"
|
||||
person.age = 41
|
||||
person.databaseChanges.keys // ["age"]
|
||||
if person.databaseEdited {
|
||||
person.persistentChangedValues.keys // ["age"]
|
||||
if person.hasPersistentChangedValues {
|
||||
try person.save(db)
|
||||
}
|
||||
```
|
||||
@@ -1767,10 +1765,10 @@ class Record {
|
||||
class func databaseTableName() -> String
|
||||
|
||||
/// Initialize a record from a database row
|
||||
required init(row: Row)
|
||||
required init(_ row: Row)
|
||||
|
||||
/// The values stored in the database
|
||||
var storedDatabaseDictionary: [String: DatabaseValueConvertible?]
|
||||
/// The values persisted in the database
|
||||
var persistentDictionary: [String: DatabaseValueConvertible?]
|
||||
|
||||
/// Optionally update record ID after a successful insertion
|
||||
func didInsertWithRowID(rowID: Int64, forColumn column: String?)
|
||||
@@ -1785,8 +1783,8 @@ class Person {
|
||||
func copy() -> Self
|
||||
|
||||
// Change Tracking
|
||||
var databaseEdited: Bool
|
||||
var databaseChanges: [String: (old: DatabaseValue?, new: DatabaseValue)]
|
||||
var hasPersistentChangedValues: Bool
|
||||
var persistentChangedValues: [String: DatabaseValue?]
|
||||
|
||||
// Persistence
|
||||
func insert(db: Database) throws
|
||||
@@ -1841,11 +1839,11 @@ Country overrides `databaseTableName()` to return the name of the table that sho
|
||||
}
|
||||
```
|
||||
|
||||
Country overrides `storedDatabaseDictionary` and returns a dictionary whose keys are column names, and values any `DatabaseValueConvertible` value (Bool, Int, String, NSDate, Swift enums, etc.) See [Values](#values) for more information:
|
||||
Country overrides `persistentDictionary` and returns a dictionary whose keys are column names, and values any `DatabaseValueConvertible` value (Bool, Int, String, NSDate, Swift enums, etc.) See [Values](#values) for more information:
|
||||
|
||||
```swift
|
||||
/// The values stored in the database
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
/// The values persisted in the database
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["isoCode": isoCode, "name": name]
|
||||
}
|
||||
```
|
||||
@@ -1854,10 +1852,10 @@ Country overrides `init(row:)` so that it can be fetched:
|
||||
|
||||
```swift
|
||||
/// Initialize a Country from a row
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
isoCode = row.value(named: "isoCode")
|
||||
name = row.value(named: "name")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -1883,7 +1881,7 @@ When the database table has an INTEGER PRIMARY KEY, make sure to override the `d
|
||||
// id INTEGER PRIMARY KEY,
|
||||
// name TEXT
|
||||
// )
|
||||
struct Person : MutableDatabasePersistable {
|
||||
class Person : Record {
|
||||
let id: Int64?
|
||||
let name: String?
|
||||
|
||||
@@ -1900,21 +1898,21 @@ struct Person : MutableDatabasePersistable {
|
||||
return "persons"
|
||||
}
|
||||
|
||||
/// The values stored in the database
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
/// The values persisted in the database
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "name": name]
|
||||
}
|
||||
|
||||
/// Initialize a Person from a row
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
id = row.value(named: "id")
|
||||
name = row.value(named: "name")
|
||||
super.init(row: row)
|
||||
super.init(row)
|
||||
}
|
||||
|
||||
/// Update person ID after a successful insertion
|
||||
func didInsertWithRowID(rowID: Int64, forColumn column: String?) {
|
||||
self.id = rowID
|
||||
id = rowID
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1996,12 +1994,12 @@ The order of sequences and arrays returned by the key-based methods is undefined
|
||||
|
||||
#### Record Persistence Methods
|
||||
|
||||
Records can store themselves in the database through the `storedDatabaseDictionary` core property:
|
||||
Records can store themselves in the database through the `persistentDictionary` core property:
|
||||
|
||||
```swift
|
||||
class Person : Record {
|
||||
/// The values stored in the database
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["id": id, "url": url, "name": name, "email": email]
|
||||
}
|
||||
}
|
||||
@@ -2040,16 +2038,16 @@ try dbQueue.inDatabase { db in
|
||||
|
||||
The `update()` method always executes an UPDATE statement. When the record has not been edited, this database access is generally useless.
|
||||
|
||||
Avoid it with the `databaseEdited` property, which returns whether the record has changes that have not been saved:
|
||||
Avoid it with the `hasPersistentChangedValues` property, which returns whether the record has changes that have not been saved:
|
||||
|
||||
```swift
|
||||
// Saves the person if it has changes that have not been saved:
|
||||
if person.databaseEdited {
|
||||
if person.hasPersistentChangedValues {
|
||||
try person.save(db)
|
||||
}
|
||||
```
|
||||
|
||||
Note that `databaseEdited` is based on value comparison: **setting a property to the same value does not set the edited flag**.
|
||||
Note that `hasPersistentChangedValues` is based on value comparison: **setting a property to the same value does not set the edited flag**.
|
||||
|
||||
For an efficient algorithm which synchronizes the content of a database table with a JSON payload, check this [sample code](https://gist.github.com/groue/dcdd3784461747874f41).
|
||||
|
||||
@@ -2077,17 +2075,9 @@ class PersonsViewController: UITableViewController {
|
||||
private class PersonWithBookCount : Person {
|
||||
var bookCount: Int?
|
||||
|
||||
required init(row: Row) {
|
||||
required init(_ row: Row) {
|
||||
bookCount = row.value(named: "bookCount")
|
||||
super.init(row: row)
|
||||
}
|
||||
|
||||
class func fetchAllWithBookCount(db: Database) -> [PersonWithBookCount] {
|
||||
return fetchAll(db,
|
||||
"SELECT persons.*, COUNT(books.id) AS bookCount " +
|
||||
"FROM persons " +
|
||||
"LEFT JOIN books ON books.ownerId = persons.id " +
|
||||
"GROUP BY persons.id")
|
||||
super.init(row)
|
||||
}
|
||||
}
|
||||
```
|
||||
@@ -2096,11 +2086,18 @@ Perform a single request:
|
||||
|
||||
```swift
|
||||
var persons: [PersonWithBookCount]!
|
||||
|
||||
override func viewWillAppear(animated: Bool) {
|
||||
super.viewWillAppear(animated)
|
||||
|
||||
persons = dbQueue.inDatabase { db in
|
||||
PersonWithBookCount.fetchAllWithBookCount(db)
|
||||
PersonWithBookCount.fetchAll(db,
|
||||
"SELECT persons.*, COUNT(books.id) AS bookCount " +
|
||||
"FROM persons " +
|
||||
"LEFT JOIN books ON books.ownerId = persons.id " +
|
||||
"GROUP BY persons.id")
|
||||
}
|
||||
|
||||
tableView.reloadData()
|
||||
}
|
||||
```
|
||||
@@ -2111,7 +2108,7 @@ Other application objects that expect a Person will gently accept the private su
|
||||
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
|
||||
if segue.identifier == "showPerson" {
|
||||
let personVC: PersonViewController = segue...
|
||||
personVC.person = persons[self.tableView.indexPathForSelectedRow!.row]
|
||||
personVC.person = persons[tableView.indexPathForSelectedRow!.row]
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2180,7 +2177,7 @@ CREATE TABLE persons (
|
||||
class Person : Record {
|
||||
var creationDate: NSDate?
|
||||
|
||||
override var storedDatabaseDictionary: [String: DatabaseValueConvertible?] {
|
||||
override var persistentDictionary: [String: DatabaseValueConvertible?] {
|
||||
return ["creationDate": creationDate, ...]
|
||||
}
|
||||
|
||||
@@ -2326,7 +2323,7 @@ class TableChangeObserver : NSObject, TransactionObserverType {
|
||||
|
||||
func databaseDidRollback(db: Database) {
|
||||
// Reset until next database event:
|
||||
self.changedTableNames = []
|
||||
changedTableNames = []
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
@@ -3,31 +3,29 @@
|
||||
- [ ] `IN (?)` sql snippet, with an array argument.
|
||||
- [ ] Write sample code around NSFetchedResultsController: fetch and output a list of TableView sections & row differences.
|
||||
- [ ] Compare DatabaseCoder with http://mjtsai.com/blog/2015/11/08/the-java-deserialization-bug-and-nssecurecoding/
|
||||
- [ ] Now that DatabasePersistable is out, Record has this didInsertWithRowID(:forColumn:) which calls updateFromRow. When we document "The updateFromRow method MUST NOT assume the presence of particular columns. The Record class itself reserves the right to call updateFromRow with arbitrary columns", we are actually talking about didInsertWithRowID, which is now exposed. Users may be confused.
|
||||
- [ ] What happens when RowConvertible.awakeFromFetch and DatabasePersistable.didInsertWithRowID(_:forColumn:) assign to self? Do we need to split RowConvertible into MutableRowConvertible + RowConvertible?
|
||||
- [ ] Check Swift API Guideline https://swift.org/documentation/api-design-guidelines.html
|
||||
- [ ] databaseTableName, etc.
|
||||
- [ ] didInsertWithRowID(_:forColumn:)
|
||||
- [ ] databaseEdited -> hasDatabaseChanges, hasNotPersistedChanges ? Check if doc makes it clear that the changes are based on last fetch. The method name should make it clear too.
|
||||
- [ ] Read conversion methods conventions (fromRow, fromDatabaseValue)
|
||||
- [X] databaseEdited -> hasDatabaseChanges, hasNotPersistedChanges, hasPersistentChangedValues (NSManagedObject)? Check if doc makes it clear that the changes are based on last fetch. The method name should make it clear too.
|
||||
- [X] Check Swift API Guideline https://swift.org/documentation/api-design-guidelines.html
|
||||
- [X] databaseTableName, etc.
|
||||
- [X] didInsertWithRowID(_:forColumn:)
|
||||
- [X] Read conversion methods conventions (fromRow, fromDatabaseValue)
|
||||
- [X] Row.value(named:) should return nil if column is not there.
|
||||
- [X] Row.value(named:) returns nil if column is not there.
|
||||
- [X] Update Row documentation
|
||||
- [X] Update "Optional Columns" chapter of RowConvertible documentation
|
||||
- [ ] Conversion should crash when type mismatch (Optional<String>.fetchOne(db, "SELECT 1"))
|
||||
- [ ] Record:
|
||||
- [X] Record:
|
||||
- [X] Remove reloading
|
||||
- [X] Expose didInsertWithRowID(_:forColumn:)
|
||||
- [X] Make Person subclass that eats an extra column easier to write (in PersonWithOverrides)
|
||||
- [X] Update Record documentation
|
||||
- [X] Update Record playground
|
||||
- [ ] Update JSONSynchronisation playground
|
||||
- [ ] Update https://gist.github.com/groue/dcdd3784461747874f41
|
||||
- [X] Update JSONSynchronisation playground
|
||||
- [X] Update https://gist.github.com/groue/dcdd3784461747874f41
|
||||
|
||||
Not sure:
|
||||
|
||||
- [ ] Since Records' primary key are infered, no operation is possible on the primary key unless we have a Database instance. It's impossible to define the record.primaryKey property, or to provide a copy() function that does not clone the primary key: they miss the database that is the only object aware of the primary key. Should we change our mind, and have Record explicitly expose their primary key again?
|
||||
- [ ] Have Record adopt Hashable and Equatable, based on primary key. Problem: we can't do it know because we don't know the primary key until we have a database connection.
|
||||
- [ ] Conversion should crash when type mismatch (Optional<String>.fetchOne(db, "SELECT 1"))
|
||||
|
||||
|
||||
Require changes in the Swift language:
|
||||
@@ -48,3 +46,4 @@ Reading list:
|
||||
- Full text search (https://www.sqlite.org/fts3.html. Related: https://blogs.gnome.org/jnelson/)
|
||||
- https://www.sqlite.org/undoredo.html
|
||||
- http://www.sqlite.org/intern-v-extern-blob.html
|
||||
- List of documentation keywords: https://swift.org/documentation/api-design-guidelines.html#special-instructions
|
||||
Reference in new issue
Block a user