Skip to content

Commit e79f075

Browse files
authored
Revert "refactor(db)!: reference is now instance of a Database reference" (#83)
1 parent 11f799f commit e79f075

File tree

2 files changed

+6
-21
lines changed

2 files changed

+6
-21
lines changed

samples/basic_db/functions/main.py

-4
Original file line numberDiff line numberDiff line change
@@ -12,22 +12,18 @@
1212
@db_fn.on_value_written(reference="hello/world")
1313
def onwriteexample(event: db_fn.Event[db_fn.Change]) -> None:
1414
print("Hello from db write event:", event)
15-
print("Reference path:", event.reference.path)
1615

1716

1817
@db_fn.on_value_created(reference="hello/world")
1918
def oncreatedexample(event: db_fn.Event) -> None:
2019
print("Hello from db create event:", event)
21-
print("Reference path:", event.reference.path)
2220

2321

2422
@db_fn.on_value_deleted(reference="hello/world")
2523
def ondeletedexample(event: db_fn.Event) -> None:
2624
print("Hello from db delete event:", event)
27-
print("Reference path:", event.reference.path)
2825

2926

3027
@db_fn.on_value_updated(reference="hello/world")
3128
def onupdatedexample(event: db_fn.Event[db_fn.Change]) -> None:
3229
print("Hello from db updated event:", event)
33-
print("Reference path:", event.reference.path)

src/firebase_functions/db_fn.py

+6-17
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@
2323
import firebase_functions.private.path_pattern as _path_pattern
2424
import firebase_functions.core as _core
2525
import cloudevents.http as _ce
26-
import firebase_admin as _fa
27-
import firebase_admin.db as _db
2826

29-
from firebase_admin.db import Reference
3027
from firebase_functions.options import DatabaseOptions
3128
from firebase_functions.core import Change, T
3229

@@ -52,9 +49,9 @@ class Event(_core.CloudEvent[T]):
5249
The instance ID portion of the fully qualified resource name.
5350
"""
5451

55-
reference: Reference
52+
reference: str
5653
"""
57-
The database reference.
54+
The database reference path.
5855
"""
5956

6057
location: str
@@ -99,24 +96,16 @@ def _db_endpoint_handler(
9996
before=before,
10097
after=after,
10198
)
102-
if _fa._DEFAULT_APP_NAME not in _fa._apps:
103-
_fa.initialize_app()
104-
app = _fa.get_app()
10599
event_instance = event_attributes["instance"]
106-
event_database_host = event_attributes["firebasedatabasehost"]
107-
database_reference = _db.reference(
108-
path=event_attributes["ref"],
109-
app=app,
110-
url=f"https://{event_instance}.{event_database_host}",
111-
)
100+
event_ref = event_attributes["ref"]
112101
params: dict[str, str] = {
113-
**ref_pattern.extract_matches(event_attributes["ref"]),
102+
**ref_pattern.extract_matches(event_ref),
114103
**instance_pattern.extract_matches(event_instance),
115104
}
116105
database_event = Event(
117-
firebase_database_host=event_database_host,
106+
firebase_database_host=event_attributes["firebasedatabasehost"],
118107
instance=event_instance,
119-
reference=database_reference,
108+
reference=event_ref,
120109
location=event_attributes["location"],
121110
specversion=event_attributes["specversion"],
122111
id=event_attributes["id"],

0 commit comments

Comments
 (0)