Added delete option to database storage.

This commit is contained in:
Batuhan Berk Başoğlu 2020-10-12 12:10:01 -04:00
parent 308604a33c
commit 963b5bc68b
1868 changed files with 192402 additions and 13278 deletions

View file

@ -0,0 +1,180 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020 Google LLC
#
# 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
#
# https://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.
"""Wrappers for protocol buffer enum types."""
import enum
class NullValue(enum.IntEnum):
"""
``NullValue`` is a singleton enumeration to represent the null value
for the ``Value`` type union.
The JSON representation for ``NullValue`` is JSON ``null``.
Attributes:
NULL_VALUE (int): Null value.
"""
NULL_VALUE = 0
class DocumentTransform(object):
class FieldTransform(object):
class ServerValue(enum.IntEnum):
"""
A value that is calculated by the server.
Attributes:
SERVER_VALUE_UNSPECIFIED (int): Unspecified. This value must not be used.
REQUEST_TIME (int): The time at which the server processed the request, with millisecond
precision.
"""
SERVER_VALUE_UNSPECIFIED = 0
REQUEST_TIME = 1
class StructuredQuery(object):
class Direction(enum.IntEnum):
"""
A sort direction.
Attributes:
DIRECTION_UNSPECIFIED (int): Unspecified.
ASCENDING (int): Ascending.
DESCENDING (int): Descending.
"""
DIRECTION_UNSPECIFIED = 0
ASCENDING = 1
DESCENDING = 2
class CompositeFilter(object):
class Operator(enum.IntEnum):
"""
A composite filter operator.
Attributes:
OPERATOR_UNSPECIFIED (int): Unspecified. This value must not be used.
AND (int): The results are required to satisfy each of the combined filters.
"""
OPERATOR_UNSPECIFIED = 0
AND = 1
class FieldFilter(object):
class Operator(enum.IntEnum):
"""
A field filter operator.
Attributes:
OPERATOR_UNSPECIFIED (int): Unspecified. This value must not be used.
LESS_THAN (int): The given ``field`` is less than the given ``value``.
Requires:
- That ``field`` come first in ``order_by``.
LESS_THAN_OR_EQUAL (int): The given ``field`` is less than or equal to the given ``value``.
Requires:
- That ``field`` come first in ``order_by``.
GREATER_THAN (int): The given ``field`` is greater than the given ``value``.
Requires:
- That ``field`` come first in ``order_by``.
GREATER_THAN_OR_EQUAL (int): The given ``field`` is greater than or equal to the given ``value``.
Requires:
- That ``field`` come first in ``order_by``.
EQUAL (int): The given ``field`` is equal to the given ``value``.
ARRAY_CONTAINS (int): The given ``field`` is an array that contains the given ``value``.
IN (int): The given ``field`` is equal to at least one value in the given
array.
Requires:
- That ``value`` is a non-empty ``ArrayValue`` with at most 10 values.
- No other ``IN``, ``ARRAY_CONTAINS_ANY``, or ``NOT_IN``.
ARRAY_CONTAINS_ANY (int): The given ``field`` is an array that contains any of the values in
the given array.
Requires:
- That ``value`` is a non-empty ``ArrayValue`` with at most 10 values.
- No other ``IN``, ``ARRAY_CONTAINS_ANY``, or ``NOT_IN``.
"""
OPERATOR_UNSPECIFIED = 0
LESS_THAN = 1
LESS_THAN_OR_EQUAL = 2
GREATER_THAN = 3
GREATER_THAN_OR_EQUAL = 4
EQUAL = 5
ARRAY_CONTAINS = 7
IN = 8
ARRAY_CONTAINS_ANY = 9
class UnaryFilter(object):
class Operator(enum.IntEnum):
"""
A unary operator.
Attributes:
OPERATOR_UNSPECIFIED (int): Unspecified. This value must not be used.
IS_NAN (int): The given ``field`` is equal to ``NaN``.
IS_NULL (int): The given ``field`` is equal to ``NULL``.
"""
OPERATOR_UNSPECIFIED = 0
IS_NAN = 2
IS_NULL = 3
class TargetChange(object):
class TargetChangeType(enum.IntEnum):
"""
The type of change.
Attributes:
NO_CHANGE (int): No change has occurred. Used only to send an updated
``resume_token``.
ADD (int): The targets have been added.
REMOVE (int): The targets have been removed.
CURRENT (int): The targets reflect all changes committed before the targets were
added to the stream.
This will be sent after or with a ``read_time`` that is greater than or
equal to the time at which the targets were added.
Listeners can wait for this change if read-after-write semantics are
desired.
RESET (int): The targets have been reset, and a new initial state for the targets
will be returned in subsequent changes.
After the initial state is complete, ``CURRENT`` will be returned even
if the target was previously indicated to be ``CURRENT``.
"""
NO_CHANGE = 0
ADD = 1
REMOVE = 2
CURRENT = 3
RESET = 4

File diff suppressed because it is too large Load diff

View file

@ -0,0 +1,109 @@
config = {
"interfaces": {
"google.firestore.v1.Firestore": {
"retry_codes": {
"idempotent": ["DEADLINE_EXCEEDED", "INTERNAL", "UNAVAILABLE"],
"aborted_unavailable": ["ABORTED", "UNAVAILABLE"],
"non_idempotent": [],
"idempotent2": ["DEADLINE_EXCEEDED", "UNAVAILABLE"],
},
"retry_params": {
"default": {
"initial_retry_delay_millis": 100,
"retry_delay_multiplier": 1.3,
"max_retry_delay_millis": 60000,
"initial_rpc_timeout_millis": 60000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 60000,
"total_timeout_millis": 600000,
},
"streaming": {
"initial_retry_delay_millis": 100,
"retry_delay_multiplier": 1.3,
"max_retry_delay_millis": 60000,
"initial_rpc_timeout_millis": 60000,
"rpc_timeout_multiplier": 1.0,
"max_rpc_timeout_millis": 60000,
"total_timeout_millis": 600000,
},
},
"methods": {
"GetDocument": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent2",
"retry_params_name": "default",
},
"ListDocuments": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent2",
"retry_params_name": "default",
},
"CreateDocument": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"UpdateDocument": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"DeleteDocument": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"BatchGetDocuments": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "streaming",
},
"BatchWrite": {
"timeout_millis": 60000,
"retry_codes_name": "aborted_unavailable",
"retry_params_name": "default",
},
"BeginTransaction": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"Commit": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
"Rollback": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"RunQuery": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "streaming",
},
"Write": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "streaming",
},
"Listen": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "streaming",
},
"ListCollectionIds": {
"timeout_millis": 60000,
"retry_codes_name": "idempotent",
"retry_params_name": "default",
},
"PartitionQuery": {
"timeout_millis": 60000,
"retry_codes_name": "non_idempotent",
"retry_params_name": "default",
},
},
}
}
}

View file

@ -0,0 +1,319 @@
# -*- coding: utf-8 -*-
#
# Copyright 2020 Google LLC
#
# 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
#
# https://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.
import google.api_core.grpc_helpers
from google.cloud.firestore_v1.proto import firestore_pb2_grpc
class FirestoreGrpcTransport(object):
"""gRPC transport class providing stubs for
google.firestore.v1 Firestore API.
The transport provides access to the raw gRPC stubs,
which can be used to take advantage of advanced
features of gRPC.
"""
# The scopes needed to make gRPC calls to all of the methods defined
# in this service.
_OAUTH_SCOPES = (
"https://www.googleapis.com/auth/cloud-platform",
"https://www.googleapis.com/auth/datastore",
)
def __init__(
self, channel=None, credentials=None, address="firestore.googleapis.com:443"
):
"""Instantiate the transport class.
Args:
channel (grpc.Channel): A ``Channel`` instance through
which to make calls. This argument is mutually exclusive
with ``credentials``; providing both will raise an exception.
credentials (google.auth.credentials.Credentials): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If none
are specified, the client will attempt to ascertain the
credentials from the environment.
address (str): The address where the service is hosted.
"""
# If both `channel` and `credentials` are specified, raise an
# exception (channels come with credentials baked in already).
if channel is not None and credentials is not None:
raise ValueError(
"The `channel` and `credentials` arguments are mutually " "exclusive.",
)
# Create the channel.
if channel is None:
channel = self.create_channel(
address=address,
credentials=credentials,
options={
"grpc.max_send_message_length": -1,
"grpc.max_receive_message_length": -1,
}.items(),
)
self._channel = channel
# gRPC uses objects called "stubs" that are bound to the
# channel and provide a basic method for each RPC.
self._stubs = {
"firestore_stub": firestore_pb2_grpc.FirestoreStub(channel),
}
@classmethod
def create_channel(
cls, address="firestore.googleapis.com:443", credentials=None, **kwargs
):
"""Create and return a gRPC channel object.
Args:
address (str): The host for the channel to use.
credentials (~.Credentials): The
authorization credentials to attach to requests. These
credentials identify this application to the service. If
none are specified, the client will attempt to ascertain
the credentials from the environment.
kwargs (dict): Keyword arguments, which are passed to the
channel creation.
Returns:
grpc.Channel: A gRPC channel object.
"""
return google.api_core.grpc_helpers.create_channel(
address, credentials=credentials, scopes=cls._OAUTH_SCOPES, **kwargs
)
@property
def channel(self):
"""The gRPC channel used by the transport.
Returns:
grpc.Channel: A gRPC channel object.
"""
return self._channel
@property
def get_document(self):
"""Return the gRPC stub for :meth:`FirestoreClient.get_document`.
Gets a single document.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].GetDocument
@property
def list_documents(self):
"""Return the gRPC stub for :meth:`FirestoreClient.list_documents`.
Lists documents.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].ListDocuments
@property
def create_document(self):
"""Return the gRPC stub for :meth:`FirestoreClient.create_document`.
Creates a new document.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].CreateDocument
@property
def update_document(self):
"""Return the gRPC stub for :meth:`FirestoreClient.update_document`.
Updates or inserts a document.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].UpdateDocument
@property
def delete_document(self):
"""Return the gRPC stub for :meth:`FirestoreClient.delete_document`.
Deletes a document.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].DeleteDocument
@property
def batch_get_documents(self):
"""Return the gRPC stub for :meth:`FirestoreClient.batch_get_documents`.
Gets multiple documents.
Documents returned by this method are not guaranteed to be returned in the
same order that they were requested.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].BatchGetDocuments
@property
def batch_write(self):
"""Return the gRPC stub for :meth:`FirestoreClient.batch_write`.
Applies a batch of write operations.
The BatchWrite method does not apply the write operations atomically and
can apply them out of order. Method does not allow more than one write
per document. Each write succeeds or fails independently. See the
``BatchWriteResponse`` for the success status of each write.
If you require an atomically applied set of writes, use ``Commit``
instead.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].BatchWrite
@property
def begin_transaction(self):
"""Return the gRPC stub for :meth:`FirestoreClient.begin_transaction`.
Starts a new transaction.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].BeginTransaction
@property
def commit(self):
"""Return the gRPC stub for :meth:`FirestoreClient.commit`.
Commits a transaction, while optionally updating documents.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].Commit
@property
def rollback(self):
"""Return the gRPC stub for :meth:`FirestoreClient.rollback`.
Rolls back a transaction.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].Rollback
@property
def run_query(self):
"""Return the gRPC stub for :meth:`FirestoreClient.run_query`.
Runs a query.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].RunQuery
@property
def write(self):
"""Return the gRPC stub for :meth:`FirestoreClient.write`.
Streams batches of document updates and deletes, in order.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].Write
@property
def listen(self):
"""Return the gRPC stub for :meth:`FirestoreClient.listen`.
Listens to changes.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].Listen
@property
def list_collection_ids(self):
"""Return the gRPC stub for :meth:`FirestoreClient.list_collection_ids`.
Lists all the collection IDs underneath a document.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].ListCollectionIds
@property
def partition_query(self):
"""Return the gRPC stub for :meth:`FirestoreClient.partition_query`.
Partitions a query by returning partition cursors that can be used to run
the query in parallel. The returned partition cursors are split points that
can be used by RunQuery as starting/end points for the query results.
Returns:
Callable: A callable which accepts the appropriate
deserialized request object and returns a
deserialized response object.
"""
return self._stubs["firestore_stub"].PartitionQuery