Skip to content

Commit 209f604

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

7 files changed

Lines changed: 713 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
@@ -44,6 +44,7 @@
4444
import google
4545
from google.cloud import exceptions # type: ignore
4646
from google.cloud.firestore_v1 import transforms, types
47+
from google.cloud.firestore_v1.bson import BSONType
4748
from google.cloud.firestore_v1.field_path import FieldPath, parse_field_path
4849
from google.cloud.firestore_v1.types import common, document, write
4950
from google.cloud.firestore_v1.types.write import DocumentTransform
@@ -182,6 +183,9 @@ def encode_value(value) -> types.document.Value:
182183
if value is None:
183184
return document.Value(null_value=struct_pb2.NULL_VALUE)
184185

186+
if isinstance(value, BSONType):
187+
return encode_value(value.to_map_value())
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)