mirror of
https://github.com/groue/GRDB.swift
synced 2026-11-24 04:07:47 +00:00
MutablePersistable.databaseDictionary() return [String: DatabaseValue]
This commit is contained in:
1 parent
715e12912b
commit
d9cfa71fc7
3 files changed
+4
-4
No files matched your search
+1
-1
@@ -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}
|
||||
```
|
||||
|
||||
@@ -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])
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user