octabytes / FireO

Google Cloud Firestore modern and simplest convenient ORM package in Python. FireO is specifically designed for the Google's Firestore
https://fireo.octabyte.io
Apache License 2.0
247 stars 29 forks source link

A way to use "id" instead of "key" in Manager #198

Closed ADR-007 closed 1 year ago

ADR-007 commented 1 year ago

I'm thinking about the right way to implement things like Model.collection.get_by_id(<id>).

Option 1: Add _by_id suffix Examples:

Model.collection.get(<key>)
Model.collection.get_by_id(<id>)

Option 2: Add the "overloaded" versions of the methods: Examples:

Model.collection.get(<key>)
Model.collection.get(<id>)
Model.collection.get(key=<key>)
Model.collection.get(id=<id>)

Implementation (fully supported by mypy):

    @overload
    def get(self, key, transaction=None):
        ...

    @overload
    def get(self, id, transaction=None):
        ...

    @convert_key_or_id_to_key
    def get(self, key, transaction=None):
        """Get document from firestore"""
        return self.queryset.get(key, transaction)

I think I prefer "option 2" but not sure yet. 🤔

Affected methods in Manager:

image

Any suggestions?

AxeemHaider commented 1 year ago

Hmmm... Option 2 looks great.