diff --git a/samples/basic_db/functions/main.py b/samples/basic_db/functions/main.py index 6b825eb..7fd134e 100644 --- a/samples/basic_db/functions/main.py +++ b/samples/basic_db/functions/main.py @@ -12,22 +12,18 @@ @db_fn.on_value_written(reference="hello/world") def onwriteexample(event: db_fn.Event[db_fn.Change]) -> None: print("Hello from db write event:", event) - print("Reference path:", event.reference.path) @db_fn.on_value_created(reference="hello/world") def oncreatedexample(event: db_fn.Event) -> None: print("Hello from db create event:", event) - print("Reference path:", event.reference.path) @db_fn.on_value_deleted(reference="hello/world") def ondeletedexample(event: db_fn.Event) -> None: print("Hello from db delete event:", event) - print("Reference path:", event.reference.path) @db_fn.on_value_updated(reference="hello/world") def onupdatedexample(event: db_fn.Event[db_fn.Change]) -> None: print("Hello from db updated event:", event) - print("Reference path:", event.reference.path) diff --git a/src/firebase_functions/db_fn.py b/src/firebase_functions/db_fn.py index 81f91c0..410d5f8 100644 --- a/src/firebase_functions/db_fn.py +++ b/src/firebase_functions/db_fn.py @@ -23,10 +23,7 @@ import firebase_functions.private.path_pattern as _path_pattern import firebase_functions.core as _core import cloudevents.http as _ce -import firebase_admin as _fa -import firebase_admin.db as _db -from firebase_admin.db import Reference from firebase_functions.options import DatabaseOptions from firebase_functions.core import Change, T @@ -52,9 +49,9 @@ class Event(_core.CloudEvent[T]): The instance ID portion of the fully qualified resource name. """ - reference: Reference + reference: str """ - The database reference. + The database reference path. """ location: str @@ -99,24 +96,16 @@ def _db_endpoint_handler( before=before, after=after, ) - if _fa._DEFAULT_APP_NAME not in _fa._apps: - _fa.initialize_app() - app = _fa.get_app() event_instance = event_attributes["instance"] - event_database_host = event_attributes["firebasedatabasehost"] - database_reference = _db.reference( - path=event_attributes["ref"], - app=app, - url=f"https://{event_instance}.{event_database_host}", - ) + event_ref = event_attributes["ref"] params: dict[str, str] = { - **ref_pattern.extract_matches(event_attributes["ref"]), + **ref_pattern.extract_matches(event_ref), **instance_pattern.extract_matches(event_instance), } database_event = Event( - firebase_database_host=event_database_host, + firebase_database_host=event_attributes["firebasedatabasehost"], instance=event_instance, - reference=database_reference, + reference=event_ref, location=event_attributes["location"], specversion=event_attributes["specversion"], id=event_attributes["id"],