@@ -181,23 +181,6 @@ def lookup(self, project, request_pb):
181181 self .connection .api_base_url ,
182182 request_pb , _datastore_pb2 .LookupResponse )
183183
184- def run_query (self , project , request_pb ):
185- """Perform a ``runQuery`` request.
186-
187- :type project: str
188- :param project: The project to connect to. This is
189- usually your project name in the cloud console.
190-
191- :type request_pb: :class:`.datastore_pb2.RunQueryRequest`
192- :param request_pb: The request protobuf object.
193-
194- :rtype: :class:`.datastore_pb2.RunQueryResponse`
195- :returns: The returned protobuf response object.
196- """
197- return _rpc (self .connection .http , project , 'runQuery' ,
198- self .connection .api_base_url ,
199- request_pb , _datastore_pb2 .RunQueryResponse )
200-
201184
202185class Connection (connection_module .Connection ):
203186 """A connection to the Google Cloud Datastore via the Protobuf API.
@@ -264,71 +247,61 @@ def lookup(self, project, key_pbs,
264247 :rtype: :class:`.datastore_pb2.LookupResponse`
265248 :returns: The returned protobuf for the lookup request.
266249 """
267- lookup_request = _datastore_pb2 .LookupRequest ()
250+ lookup_request = _datastore_pb2 .LookupRequest (keys = key_pbs )
268251 _set_read_options (lookup_request , eventual , transaction_id )
269- _add_keys_to_request (lookup_request .keys , key_pbs )
270-
271252 return self ._datastore_api .lookup (project , lookup_request )
272253
273- def run_query (self , project , query_pb , namespace = None ,
274- eventual = False , transaction_id = None ):
275- """Run a query on the Cloud Datastore.
276254
277- Maps the ``DatastoreService.RunQuery`` protobuf RPC.
255+ class HTTPDatastoreAPI (object ):
256+ """An API object that sends proto-over-HTTP requests.
278257
279- Given a Query protobuf, sends a ``runQuery`` request to the
280- Cloud Datastore API and returns a list of entity protobufs
281- matching the query.
258+ Intended to provide the same methods as the GAPIC ``DatastoreClient``.
282259
283- You typically wouldn't use this method directly, in favor of the
284- :meth:`google.cloud.datastore.query.Query.fetch` method.
260+ :type client: :class:`~google.cloud.datastore.client.Client`
261+ :param client: The client that provides configuration.
262+ """
285263
286- Under the hood, the :class:`google.cloud.datastore.query.Query` class
287- uses this method to fetch data.
264+ def __init__ (self , client ):
265+ self .client = client
266+
267+ def run_query (self , project , partition_id , read_options ,
268+ query = None , gql_query = None ):
269+ """Perform a ``runQuery`` request.
288270
289271 :type project: str
290- :param project: The project over which to run the query.
272+ :param project: The project to connect to. This is
273+ usually your project name in the cloud console.
291274
292- :type query_pb: :class:`.query_pb2.Query`
293- :param query_pb: The Protobuf representing the query to run.
275+ :type partition_id: :class:`.entity_pb2.PartitionId`
276+ :param partition_id: Partition ID corresponding to an optional
277+ namespace and project ID.
294278
295- :type namespace: str
296- :param namespace: The namespace over which to run the query.
279+ :type read_options: :class:`.datastore_pb2.ReadOptions`
280+ :param read_options: The options for this query. Contains a
281+ either the transaction for the read or
282+ ``STRONG`` or ``EVENTUAL`` read consistency.
297283
298- :type eventual: bool
299- :param eventual: If False (the default), request ``STRONG`` read
300- consistency. If True, request ``EVENTUAL`` read
301- consistency.
284+ :type query: :class:`.query_pb2.Query`
285+ :param query: (Optional) The query protobuf to run. At most one of
286+ ``query`` and ``gql_query`` can be specified.
302287
303- :type transaction_id: str
304- :param transaction_id: If passed, make the request in the scope of
305- the given transaction. Incompatible with
306- ``eventual==True``.
288+ :type gql_query: :class:`.query_pb2.GqlQuery`
289+ :param gql_query: (Optional) The GQL query to run. At most one of
290+ ``query`` and ``gql_query`` can be specified.
307291
308292 :rtype: :class:`.datastore_pb2.RunQueryResponse`
309- :returns: The protobuf response from a ``runQuery`` request .
293+ :returns: The returned protobuf response object .
310294 """
311- request = _datastore_pb2 .RunQueryRequest ()
312- _set_read_options (request , eventual , transaction_id )
313-
314- if namespace :
315- request .partition_id .namespace_id = namespace
316-
317- request .query .CopyFrom (query_pb )
318- return self ._datastore_api .run_query (project , request )
319-
320-
321- class HTTPDatastoreAPI (object ):
322- """An API object that sends proto-over-HTTP requests.
323-
324- Intended to provide the same methods as the GAPIC ``DatastoreClient``.
325-
326- :type client: :class:`~google.cloud.datastore.client.Client`
327- :param client: The client that provides configuration.
328- """
329-
330- def __init__ (self , client ):
331- self .client = client
295+ request_pb = _datastore_pb2 .RunQueryRequest (
296+ project_id = project ,
297+ partition_id = partition_id ,
298+ read_options = read_options ,
299+ query = query ,
300+ gql_query = gql_query ,
301+ )
302+ return _rpc (self .client ._http , project , 'runQuery' ,
303+ self .client ._base_url ,
304+ request_pb , _datastore_pb2 .RunQueryResponse )
332305
333306 def begin_transaction (self , project ):
334307 """Perform a ``beginTransaction`` request.
@@ -391,8 +364,10 @@ def rollback(self, project, transaction_id):
391364 :rtype: :class:`.datastore_pb2.RollbackResponse`
392365 :returns: The returned protobuf response object.
393366 """
394- request_pb = _datastore_pb2 .RollbackRequest ()
395- request_pb .transaction = transaction_id
367+ request_pb = _datastore_pb2 .RollbackRequest (
368+ project_id = project ,
369+ transaction = transaction_id ,
370+ )
396371 # Response is empty (i.e. no fields) but we return it anyway.
397372 return _rpc (self .client ._http , project , 'rollback' ,
398373 self .client ._base_url ,
@@ -411,8 +386,7 @@ def allocate_ids(self, project, key_pbs):
411386 :rtype: :class:`.datastore_pb2.AllocateIdsResponse`
412387 :returns: The returned protobuf response object.
413388 """
414- request_pb = _datastore_pb2 .AllocateIdsRequest ()
415- _add_keys_to_request (request_pb .keys , key_pbs )
389+ request_pb = _datastore_pb2 .AllocateIdsRequest (keys = key_pbs )
416390 return _rpc (self .client ._http , project , 'allocateIds' ,
417391 self .client ._base_url ,
418392 request_pb , _datastore_pb2 .AllocateIdsResponse )
@@ -434,16 +408,3 @@ def _set_read_options(request, eventual, transaction_id):
434408 opts .read_consistency = _datastore_pb2 .ReadOptions .EVENTUAL
435409 elif transaction_id :
436410 opts .transaction = transaction_id
437-
438-
439- def _add_keys_to_request (request_field_pb , key_pbs ):
440- """Add protobuf keys to a request object.
441-
442- :type request_field_pb: `RepeatedCompositeFieldContainer`
443- :param request_field_pb: A repeated proto field that contains keys.
444-
445- :type key_pbs: list of :class:`.entity_pb2.Key`
446- :param key_pbs: The keys to add to a request.
447- """
448- for key_pb in key_pbs :
449- request_field_pb .add ().CopyFrom (key_pb )
0 commit comments