-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Firestore: add support for 'ArrayRemove' / 'ArrayUnion' transforms (#…
- Loading branch information
Showing
12 changed files
with
502 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,7 +13,7 @@ API Reference | |
query | ||
batch | ||
transaction | ||
constants | ||
transforms | ||
types | ||
|
||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
Transforms | ||
~~~~~~~~~~ | ||
|
||
.. automodule:: google.cloud.firestore_v1beta1.transforms | ||
:members: | ||
:show-inheritance: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
# Copyright 2017 Google LLC All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Helpful constants to use for Google Cloud Firestore.""" | ||
|
||
|
||
class Sentinel(object): | ||
"""Sentinel objects used to signal special handling.""" | ||
__slots__ = ('description',) | ||
|
||
def __init__(self, description): | ||
self.description = description | ||
|
||
def __repr__(self): | ||
return "Sentinel: {}".format(self.description) | ||
|
||
|
||
DELETE_FIELD = Sentinel("Value used to delete a field in a document.") | ||
|
||
|
||
SERVER_TIMESTAMP = Sentinel( | ||
"Value used to set a document field to the server timestamp.") | ||
|
||
|
||
class _ValueList(object): | ||
"""Read-only list of values. | ||
Args: | ||
values (List | Tuple): values held in the helper. | ||
""" | ||
slots = ('_values',) | ||
|
||
def __init__(self, values): | ||
if not isinstance(values, (list, tuple)): | ||
raise ValueError("'values' must be a list or tuple.") | ||
|
||
if len(values) == 0: | ||
raise ValueError("'values' must be non-empty.") | ||
|
||
self._values = list(values) | ||
|
||
@property | ||
def values(self): | ||
"""Values to append. | ||
Returns (List): | ||
values to be appended by the transform. | ||
""" | ||
return self._values | ||
|
||
|
||
class ArrayUnion(_ValueList): | ||
"""Field transform: appends missing values to an array field. | ||
See: | ||
https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1beta1.ArrayValue.google.firestore.v1beta1.DocumentTransform.FieldTransform.append_missing_elements | ||
Args: | ||
values (List | Tuple): values to append. | ||
""" | ||
|
||
|
||
class ArrayRemove(_ValueList): | ||
"""Field transform: remove values from an array field. | ||
See: | ||
https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1beta1#google.firestore.v1beta1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1beta1.ArrayValue.google.firestore.v1beta1.DocumentTransform.FieldTransform.remove_all_from_array | ||
Args: | ||
values (List | Tuple): values to remove. | ||
""" |
Oops, something went wrong.