Coverage for /pythoncovmergedfiles/medio/medio/usr/local/lib/python3.8/site-packages/google/cloud/firestore_v1/transforms.py: 59%
41 statements
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-09 06:27 +0000
« prev ^ index » next coverage.py v7.3.2, created at 2023-12-09 06:27 +0000
1# Copyright 2017 Google LLC All rights reserved.
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7# http://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
15"""Helpful constants to use for Google Cloud Firestore."""
18class Sentinel(object):
19 """Sentinel objects used to signal special handling."""
21 __slots__ = ("description",)
23 def __init__(self, description) -> None:
24 self.description = description
26 def __repr__(self):
27 return "Sentinel: {}".format(self.description)
30DELETE_FIELD = Sentinel("Value used to delete a field in a document.")
33SERVER_TIMESTAMP = Sentinel(
34 "Value used to set a document field to the server timestamp."
35)
38class _ValueList(object):
39 """Read-only list of values.
41 Args:
42 values (List | Tuple): values held in the helper.
43 """
45 slots = ("_values",)
47 def __init__(self, values) -> None:
48 if not isinstance(values, (list, tuple)):
49 raise ValueError("'values' must be a list or tuple.")
51 if len(values) == 0:
52 raise ValueError("'values' must be non-empty.")
54 self._values = list(values)
56 def __eq__(self, other):
57 if not isinstance(other, self.__class__):
58 return NotImplemented
59 return self._values == other._values
61 @property
62 def values(self):
63 """Values to append.
65 Returns (List):
66 values to be appended by the transform.
67 """
68 return self._values
71class ArrayUnion(_ValueList):
72 """Field transform: appends missing values to an array field.
74 See:
75 https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.append_missing_elements
77 Args:
78 values (List | Tuple): values to append.
79 """
82class ArrayRemove(_ValueList):
83 """Field transform: remove values from an array field.
85 See:
86 https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.remove_all_from_array
88 Args:
89 values (List | Tuple): values to remove.
90 """
93class _NumericValue(object):
94 """Hold a single integer / float value.
96 Args:
97 value (int | float): value held in the helper.
98 """
100 def __init__(self, value) -> None:
101 if not isinstance(value, (int, float)):
102 raise ValueError("Pass an integer / float value.")
104 self._value = value
106 @property
107 def value(self):
108 """Value used by the transform.
110 Returns:
111 (Integer | Float) value passed in the constructor.
112 """
113 return self._value
115 def __eq__(self, other):
116 if not isinstance(other, self.__class__):
117 return NotImplemented
118 return self._value == other._value
121class Increment(_NumericValue):
122 """Field transform: increment a numeric field with specified value.
124 See:
125 https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.increment
127 Args:
128 value (int | float): value used to increment the field.
129 """
132class Maximum(_NumericValue):
133 """Field transform: bound numeric field with specified value.
135 See:
136 https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.maximum
138 Args:
139 value (int | float): value used to bound the field.
140 """
143class Minimum(_NumericValue):
144 """Field transform: bound numeric field with specified value.
146 See:
147 https://cloud.google.com/firestore/docs/reference/rpc/google.firestore.v1#google.firestore.v1.DocumentTransform.FieldTransform.FIELDS.google.firestore.v1.ArrayValue.google.firestore.v1.DocumentTransform.FieldTransform.minimum
149 Args:
150 value (int | float): value used to bound the field.
151 """