Skip to content

Commit 9df5121

Browse files
committed
feat(firestore): add core BSON document write support (PR 1A)
1 parent 1857302 commit 9df5121

7 files changed

Lines changed: 676 additions & 0 deletions

File tree

‎packages/google-cloud-firestore/google/cloud/firestore/__init__.py‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@
3535
AsyncQuery,
3636
AsyncTransaction,
3737
AsyncWriteBatch,
38+
BSONBinary,
39+
BSONDecimal128,
40+
BSONInt32,
41+
BSONMaxKey,
42+
BSONMinKey,
43+
BSONObjectID,
44+
BSONRegex,
45+
BSONTimestamp,
3846
Client,
3947
CollectionGroup,
4048
CollectionReference,
@@ -92,6 +100,14 @@
92100
"async_transactional",
93101
"AsyncTransaction",
94102
"AsyncWriteBatch",
103+
"BSONBinary",
104+
"BSONDecimal128",
105+
"BSONInt32",
106+
"BSONMaxKey",
107+
"BSONMinKey",
108+
"BSONObjectID",
109+
"BSONRegex",
110+
"BSONTimestamp",
95111
"Client",
96112
"CountAggregation",
97113
"CollectionGroup",

‎packages/google-cloud-firestore/google/cloud/firestore_v1/__init__.py‎

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
from google.cloud.firestore_v1.base_pipeline import SubPipeline
4747
from google.cloud.firestore_v1.base_query import And, FieldFilter, Or
4848
from google.cloud.firestore_v1.batch import WriteBatch
49+
from google.cloud.firestore_v1.bson import (
50+
BSONBinary,
51+
BSONDecimal128,
52+
BSONInt32,
53+
BSONMaxKey,
54+
BSONMinKey,
55+
BSONObjectID,
56+
BSONRegex,
57+
BSONTimestamp,
58+
)
4959
from google.cloud.firestore_v1.client import Client
5060
from google.cloud.firestore_v1.collection import CollectionReference
5161
from google.cloud.firestore_v1.document import DocumentReference
@@ -147,6 +157,14 @@
147157
"async_transactional",
148158
"AsyncTransaction",
149159
"AsyncWriteBatch",
160+
"BSONBinary",
161+
"BSONDecimal128",
162+
"BSONInt32",
163+
"BSONMaxKey",
164+
"BSONMinKey",
165+
"BSONObjectID",
166+
"BSONRegex",
167+
"BSONTimestamp",
150168
"Client",
151169
"CountAggregation",
152170
"CollectionGroup",

‎packages/google-cloud-firestore/google/cloud/firestore_v1/_helpers.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,10 @@ def encode_value(value) -> types.document.Value:
182182
if value is None:
183183
return document.Value(null_value=struct_pb2.NULL_VALUE)
184184

185+
to_map = getattr(value, "to_map_value", None)
186+
if callable(to_map):
187+
return encode_value(to_map())
188+
185189
# Must come before int since ``bool`` is an integer subtype.
186190
if isinstance(value, bool):
187191
return document.Value(boolean_value=value)

0 commit comments

Comments
 (0)