firebase / firebase/firebase-ios-sdk
FR: RTDB/Codable: Add support for mapping node IDs to / from attributes on a Swift struct
- Dominant language
- C++
- Stars
- 6.7k
- Forks
- 1.8k
- Avg merge
- 2d 14h
- Merged PRs (30d)
- 72
Description
### Feature proposal
* Firebase Component: Database
Mapping data between RTDB nodes and Swift structs has become a lot easier thanks to the addition of Codable support. However, the current implementation doesn't allow for automatically mapping a node's ID to an attribute on the respective Swift struct. To deal with this situation, developers add an extra field `id` to their RTDB nodes, which might eventually result in a mismatch between this extra attribute and the actual node ID.
I propose to add a property wrapper similar to the one we use in Firestore (`@DocumentID`) to
- map node IDs to the thusly annotated attribute on the Swift struct
- use `childByAutoId` to generate node IDs for new nodes if the attribute annotated with the property wrapper has a `nil` value
A possible name for the property wrapper might be `@NodeID`, to match the `@DocumentID` we use for Firestore.
#### Context
* https://github.com/firebase/firebase-ios-sdk/tree/master/FirebaseDatabaseSwift/Sources/Codable
* https://brontoxx.medium.com/60d6299369f1
Contributor guide
Assessment
This issue has not been assessed yet.