Skip to content

FR: RTDB/Codable: Add support for mapping node IDs to / from attributes on a Swift struct #8827

Open
@peterfriese

Description

@peterfriese

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions