lib/google/cloud/datastore.rb in google-cloud-datastore-1.2.1 vs lib/google/cloud/datastore.rb in google-cloud-datastore-1.3.0
- old
+ new
@@ -1,12 +1,12 @@
-# Copyright 2014 Google Inc. All rights reserved.
+# Copyright 2014 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
#
-# http://www.apache.org/licenses/LICENSE-2.0
+# 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
@@ -367,10 +367,34 @@
# rescue
# tx.rollback
# end
# ```
#
+ # A read-only transaction cannot modify entities; in return they do not
+ # contend with other read-write or read-only transactions. Using a read-only
+ # transaction for transactions that only read data will potentially improve
+ # throughput.
+ #
+ # ```ruby
+ # require "google/cloud/datastore"
+ #
+ # datastore = Google::Cloud::Datastore.new
+ #
+ # task_list_key = datastore.key "TaskList", "default"
+ # query = datastore.query("Task").
+ # ancestor(task_list_key)
+ #
+ # tasks = nil
+ #
+ # datastore.transaction read_only: true do |tx|
+ # task_list = tx.find task_list_key
+ # if task_list
+ # tasks = tx.run query
+ # end
+ # end
+ # ```
+ #
# See {Google::Cloud::Datastore::Transaction} and
# {Google::Cloud::Datastore::Dataset#transaction}
#
# ## Querying metadata
#
@@ -535,12 +559,10 @@
#
# datastore.save task
# ```
#
module Datastore
- # rubocop:disable MethodLength
-
##
# Creates a new object for connecting to the Datastore service.
# Each call creates a new connection.
#
# For more information on connecting to Google Cloud see the
@@ -612,10 +634,8 @@
Datastore::Dataset.new(
Datastore::Service.new(
project_id, credentials,
timeout: timeout, client_config: client_config))
end
-
- # rubocop:enable MethodLength
end
end
end