diff --git a/CHANGELOG.md b/CHANGELOG.md index c421cd9b7..4abdd0298 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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} ``` diff --git a/GRDB/Record/Persistable.swift b/GRDB/Record/Persistable.swift index 26750b1f9..5b997a138 100644 --- a/GRDB/Record/Persistable.swift +++ b/GRDB/Record/Persistable.swift @@ -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 } } } diff --git a/Tests/GRDBTests/MutablePersistableTests.swift b/Tests/GRDBTests/MutablePersistableTests.swift index d9f972497..428f4bf83 100644 --- a/Tests/GRDBTests/MutablePersistableTests.swift +++ b/Tests/GRDBTests/MutablePersistableTests.swift @@ -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]) }