MutablePersistable.databaseDictionary() return [String: DatabaseValue]

This commit is contained in:
Gwendal Roué committed 2017-08-28 08:13:20 +02:00
1 parent 715e12912b
commit d9cfa71fc7
3 files changed
+4 -4

No files matched your search

+1 -1
View File
@@ -82,7 +82,7 @@ Release Notes
```swift
let player = try Player.fetchOne(db, key: 1)
let dict = player.databaseDictionary()
let dict = player.databaseDictionary() // [String: DatabaseValue]
print(dict)
// Prints {"id": 1, "name": "Arthur", "score": 1000}
```
+2 -2
View File
@@ -313,8 +313,8 @@ public protocol MutablePersistable : TableMapping {
extension MutablePersistable {
/// Returns a dictionary whose keys are the columns encoded in the
/// `encode(to:)` method.
public func databaseDictionary() -> [String: DatabaseValueConvertible?] {
return PersistenceContainer(self).storage
public func databaseDictionary() -> [String: DatabaseValue] {
return PersistenceContainer(self).storage.mapValues { $0?.databaseValue ?? .null }
}
}
@@ -274,7 +274,7 @@ class MutablePersistableTests: GRDBTestCase {
func testMutablePersistablePersonDatabaseDictionary() {
let person = MutablePersistablePerson(id: nil, name: "Arthur", age: 24)
let dict = person.databaseDictionary().mapValues { $0?.databaseValue ?? .null }
let dict = person.databaseDictionary()
XCTAssertEqual(dict, ["iD": DatabaseValue.null, "NAme": "Arthur".databaseValue, "aGe": 24.databaseValue])
}