Class: Google::Cloud::Spanner::V1::Spanner::Client
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::V1::Spanner::Client
- Includes:
- Paths
- Defined in:
- lib/google/cloud/spanner/v1/spanner/client.rb
Overview
Client for the Spanner service.
Cloud Spanner API
The Cloud Spanner API can be used to manage sessions and execute transactions on data stored in Cloud Spanner databases.
Defined Under Namespace
Classes: Configuration
Class Method Summary collapse
-
.configure {|config| ... } ⇒ Client::Configuration
Configure the Spanner Client class.
Instance Method Summary collapse
-
#batch_create_sessions(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse
Creates multiple new sessions.
-
#batch_write(request, options = nil) {|response, operation| ... } ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::BatchWriteResponse>
Batches the supplied mutation groups in a collection of efficient transactions.
-
#begin_transaction(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::Transaction
Begins a new transaction.
-
#commit(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::CommitResponse
Commits a transaction.
-
#configure {|config| ... } ⇒ Client::Configuration
Configure the Spanner Client instance.
-
#create_session(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::Session
Creates a new session.
-
#delete_session(request, options = nil) {|response, operation| ... } ⇒ ::Google::Protobuf::Empty
Ends a session, releasing server resources associated with it.
-
#execute_batch_dml(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse
Executes a batch of SQL DML statements.
-
#execute_sql(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::ResultSet
Executes an SQL statement, returning all results in a single reply.
-
#execute_streaming_sql(request, options = nil) {|response, operation| ... } ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>
Like ExecuteSql, except returns the result set as a stream.
-
#get_session(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::Session
Gets a session.
-
#initialize {|config| ... } ⇒ Client
constructor
Create a new Spanner client object.
-
#list_sessions(request, options = nil) {|response, operation| ... } ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session>
Lists all sessions in a given database.
-
#partition_query(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse
Creates a set of partition tokens that can be used to execute a query operation in parallel.
-
#partition_read(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse
Creates a set of partition tokens that can be used to execute a read operation in parallel.
-
#read(request, options = nil) {|response, operation| ... } ⇒ ::Google::Cloud::Spanner::V1::ResultSet
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ExecuteSql.
-
#rollback(request, options = nil) {|response, operation| ... } ⇒ ::Google::Protobuf::Empty
Rolls back a transaction, releasing any locks it holds.
-
#streaming_read(request, options = nil) {|response, operation| ... } ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>
Like Read, except returns the result set as a stream.
-
#universe_domain ⇒ String
The effective universe domain.
Methods included from Paths
Constructor Details
#initialize {|config| ... } ⇒ Client
Create a new Spanner client object.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 195 def initialize # These require statements are intentionally placed here to initialize # the gRPC module only when it's required. # See https://github.com/googleapis/toolkit/issues/446 require "gapic/grpc" require "google/spanner/v1/spanner_services_pb" # Create the configuration object @config = Configuration.new Client.configure # Yield the configuration if needed yield @config if block_given? # Create credentials credentials = @config.credentials # Use self-signed JWT if the endpoint is unchanged from default, # but only if the default endpoint does not have a region prefix. enable_self_signed_jwt = @config.endpoint.nil? || (@config.endpoint == Configuration::DEFAULT_ENDPOINT && !@config.endpoint.split(".").first.include?("-")) credentials ||= Credentials.default scope: @config.scope, enable_self_signed_jwt: enable_self_signed_jwt if credentials.is_a?(::String) || credentials.is_a?(::Hash) credentials = Credentials.new credentials, scope: @config.scope end @quota_project_id = @config.quota_project @quota_project_id ||= credentials.quota_project_id if credentials.respond_to? :quota_project_id @spanner_stub = ::Gapic::ServiceStub.new( ::Google::Cloud::Spanner::V1::Spanner::Stub, credentials: credentials, endpoint: @config.endpoint, endpoint_template: DEFAULT_ENDPOINT_TEMPLATE, universe_domain: @config.universe_domain, channel_args: @config.channel_args, interceptors: @config.interceptors, channel_pool_config: @config.channel_pool ) end |
Class Method Details
.configure {|config| ... } ⇒ Client::Configuration
Configure the Spanner Client class.
See Configuration for a description of the configuration fields.
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 62 def self.configure @configure ||= begin namespace = ["Google", "Cloud", "Spanner", "V1"] parent_config = while namespace.any? parent_name = namespace.join "::" parent_const = const_get parent_name break parent_const.configure if parent_const.respond_to? :configure namespace.pop end default_config = Client::Configuration.new parent_config default_config.rpcs.create_session.timeout = 30.0 default_config.rpcs.create_session.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.batch_create_sessions.timeout = 60.0 default_config.rpcs.batch_create_sessions.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.get_session.timeout = 30.0 default_config.rpcs.get_session.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.list_sessions.timeout = 3600.0 default_config.rpcs.list_sessions.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.delete_session.timeout = 30.0 default_config.rpcs.delete_session.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.execute_sql.timeout = 30.0 default_config.rpcs.execute_sql.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.execute_streaming_sql.timeout = 3600.0 default_config.rpcs.execute_batch_dml.timeout = 30.0 default_config.rpcs.execute_batch_dml.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.read.timeout = 30.0 default_config.rpcs.read.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.streaming_read.timeout = 3600.0 default_config.rpcs.begin_transaction.timeout = 30.0 default_config.rpcs.begin_transaction.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.commit.timeout = 3600.0 default_config.rpcs.commit.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.rollback.timeout = 30.0 default_config.rpcs.rollback.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.partition_query.timeout = 30.0 default_config.rpcs.partition_query.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.partition_read.timeout = 30.0 default_config.rpcs.partition_read.retry_policy = { initial_delay: 0.25, max_delay: 32.0, multiplier: 1.3, retry_codes: [14] } default_config.rpcs.batch_write.timeout = 3600.0 default_config end yield @configure if block_given? @configure end |
Instance Method Details
#batch_create_sessions(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse #batch_create_sessions(database: nil, session_template: nil, session_count: nil) ⇒ ::Google::Cloud::Spanner::V1::BatchCreateSessionsResponse
Creates multiple new sessions.
This API can be used to initialize a session cache on the clients. See https://goo.gl/TgSFN2 for best practices on session cache management.
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 398 def batch_create_sessions request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::BatchCreateSessionsRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.batch_create_sessions..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.database header_params["database"] = request.database end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.batch_create_sessions.timeout, metadata: , retry_policy: @config.rpcs.batch_create_sessions.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :batch_create_sessions, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#batch_write(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::BatchWriteResponse> #batch_write(session: nil, request_options: nil, mutation_groups: nil, exclude_txn_from_change_streams: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::BatchWriteResponse>
Batches the supplied mutation groups in a collection of efficient transactions. All mutations in a group are committed atomically. However, mutations across groups can be committed non-atomically in an unspecified order and thus, they must be independent of each other. Partial failure is possible, i.e., some groups may have been committed successfully, while some may have failed. The results of individual batches are streamed into the response as the batches are applied.
BatchWrite requests are not replay protected, meaning that each mutation group may be applied more than once. Replays of non-idempotent mutations may have undesirable effects. For example, replays of an insert mutation may produce an already exists error or if you use generated or commit timestamp-based keys, it may result in additional rows being added to the mutation's table. We recommend structuring your mutation groups to be idempotent to avoid this issue.
2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 2154 def batch_write request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::BatchWriteRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.batch_write..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.batch_write.timeout, metadata: , retry_policy: @config.rpcs.batch_write.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :batch_write, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#begin_transaction(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Transaction #begin_transaction(session: nil, options: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::Transaction
Begins a new transaction. This step can often be skipped: Read, ExecuteSql and Commit can begin a new transaction as a side-effect.
1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1551 def begin_transaction request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::BeginTransactionRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.begin_transaction..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.begin_transaction.timeout, metadata: , retry_policy: @config.rpcs.begin_transaction.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :begin_transaction, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#commit(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::CommitResponse #commit(session: nil, transaction_id: nil, single_use_transaction: nil, mutations: nil, return_commit_stats: nil, max_commit_delay: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::CommitResponse
Commits a transaction. The request includes the mutations to be applied to rows in the database.
Commit
might return an ABORTED
error. This can occur at any time;
commonly, the cause is conflicts with concurrent
transactions. However, it can also happen for a variety of other
reasons. If Commit
returns ABORTED
, the caller should re-attempt
the transaction from the beginning, re-using the same session.
On very rare occasions, Commit
might return UNKNOWN
. This can happen,
for example, if the client job experiences a 1+ hour networking failure.
At that point, Cloud Spanner has lost track of the transaction outcome and
we recommend that you perform another read from the database to see the
state of things as they are now.
1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1677 def commit request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::CommitRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.commit..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.commit.timeout, metadata: , retry_policy: @config.rpcs.commit.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :commit, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#configure {|config| ... } ⇒ Client::Configuration
Configure the Spanner Client instance.
The configuration is set to the derived mode, meaning that values can be changed, but structural changes (adding new fields, etc.) are not allowed. Structural changes should be made on configure.
See Configuration for a description of the configuration fields.
165 166 167 168 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 165 def configure yield @config if block_given? @config end |
#create_session(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Session #create_session(database: nil, session: nil) ⇒ ::Google::Cloud::Spanner::V1::Session
Creates a new session. A session can be used to perform transactions that read and/or modify data in a Cloud Spanner database. Sessions are meant to be reused for many consecutive transactions.
Sessions can only execute one transaction at a time. To execute multiple concurrent read-write/write-only transactions, create multiple sessions. Note that standalone reads and queries use a transaction internally, and count toward the one transaction limit.
Active sessions use additional server resources, so it is a good idea to
delete idle and unneeded sessions.
Aside from explicit deletes, Cloud Spanner may delete sessions for which no
operations are sent for more than an hour. If a session is deleted,
requests to it return NOT_FOUND
.
Idle sessions can be kept alive by sending a trivial SQL query
periodically, e.g., "SELECT 1"
.
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 301 def create_session request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::CreateSessionRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.create_session..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.database header_params["database"] = request.database end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.create_session.timeout, metadata: , retry_policy: @config.rpcs.create_session.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :create_session, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#delete_session(request, options = nil) ⇒ ::Google::Protobuf::Empty #delete_session(name: nil) ⇒ ::Google::Protobuf::Empty
Ends a session, releasing server resources associated with it. This will asynchronously trigger cancellation of any operations that are running with this session.
681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 681 def delete_session request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::DeleteSessionRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.delete_session..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.delete_session.timeout, metadata: , retry_policy: @config.rpcs.delete_session.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :delete_session, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#execute_batch_dml(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse #execute_batch_dml(session: nil, transaction: nil, statements: nil, seqno: nil, request_options: nil) ⇒ ::Google::Cloud::Spanner::V1::ExecuteBatchDmlResponse
Executes a batch of SQL DML statements. This method allows many statements to be run with lower latency than submitting them sequentially with ExecuteSql.
Statements are executed in sequential order. A request can succeed even if a statement fails. The ExecuteBatchDmlResponse.status field in the response provides information about the statement that failed. Clients must inspect this field to determine whether an error occurred.
Execution stops after the first failed statement; the remaining statements are not executed.
1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1148 def execute_batch_dml request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ExecuteBatchDmlRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.execute_batch_dml..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.execute_batch_dml.timeout, metadata: , retry_policy: @config.rpcs.execute_batch_dml.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :execute_batch_dml, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#execute_sql(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet #execute_sql(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet
Executes an SQL statement, returning all results in a single reply. This
method cannot be used to return a result set larger than 10 MiB;
if the query yields more data than that, the query fails with
a FAILED_PRECONDITION
error.
Operations inside read-write transactions might return ABORTED
. If
this occurs, the application should restart the transaction from
the beginning. See Transaction for more
details.
Larger result sets can be fetched in streaming fashion by calling ExecuteStreamingSql instead.
857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 857 def execute_sql request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ExecuteSqlRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.execute_sql..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.execute_sql.timeout, metadata: , retry_policy: @config.rpcs.execute_sql.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :execute_sql, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#execute_streaming_sql(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet> #execute_streaming_sql(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>
Like ExecuteSql, except returns the result set as a stream. Unlike ExecuteSql, there is no limit on the size of the returned result set. However, no individual row in the result set can exceed 100 MiB, and no column value can exceed 10 MiB.
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1028 def execute_streaming_sql request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ExecuteSqlRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.execute_streaming_sql..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.execute_streaming_sql.timeout, metadata: , retry_policy: @config.rpcs.execute_streaming_sql.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :execute_streaming_sql, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#get_session(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::Session #get_session(name: nil) ⇒ ::Google::Cloud::Spanner::V1::Session
Gets a session. Returns NOT_FOUND
if the session does not exist.
This is mainly useful for determining whether a session is still
alive.
485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 485 def get_session request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::GetSessionRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.get_session..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.name header_params["name"] = request.name end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.get_session.timeout, metadata: , retry_policy: @config.rpcs.get_session.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :get_session, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#list_sessions(request, options = nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session> #list_sessions(database: nil, page_size: nil, page_token: nil, filter: nil) ⇒ ::Gapic::PagedEnumerable<::Google::Cloud::Spanner::V1::Session>
Lists all sessions in a given database.
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 593 def list_sessions request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ListSessionsRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.list_sessions..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.database header_params["database"] = request.database end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.list_sessions.timeout, metadata: , retry_policy: @config.rpcs.list_sessions.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :list_sessions, request, options: do |response, operation| response = ::Gapic::PagedEnumerable.new @spanner_stub, :list_sessions, request, response, operation, yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#partition_query(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse #partition_query(session: nil, transaction: nil, sql: nil, params: nil, param_types: nil, partition_options: nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse
Creates a set of partition tokens that can be used to execute a query operation in parallel. Each of the returned partition tokens can be used by ExecuteStreamingSql to specify a subset of the query result to read. The same session and read-only transaction must be used by the PartitionQueryRequest used to create the partition tokens and the ExecuteSqlRequests that use the partition tokens.
Partition tokens become invalid when the session used to create them is deleted, is idle for too long, begins a new transaction, or becomes too old. When any of these happen, it is not possible to resume the query, and the whole operation must be restarted from the beginning.
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1909 def partition_query request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::PartitionQueryRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.partition_query..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.partition_query.timeout, metadata: , retry_policy: @config.rpcs.partition_query.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :partition_query, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#partition_read(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse #partition_read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, partition_options: nil) ⇒ ::Google::Cloud::Spanner::V1::PartitionResponse
Creates a set of partition tokens that can be used to execute a read operation in parallel. Each of the returned partition tokens can be used by StreamingRead to specify a subset of the read result to read. The same session and read-only transaction must be used by the PartitionReadRequest used to create the partition tokens and the ReadRequests that use the partition tokens. There are no ordering guarantees on rows returned among the returned partition tokens, or even within each individual StreamingRead call issued with a partition_token.
Partition tokens become invalid when the session used to create them is deleted, is idle for too long, begins a new transaction, or becomes too old. When any of these happen, it is not possible to resume the read, and the whole operation must be restarted from the beginning.
2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 2035 def partition_read request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::PartitionReadRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.partition_read..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.partition_read.timeout, metadata: , retry_policy: @config.rpcs.partition_read.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :partition_read, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#read(request, options = nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet #read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, limit: nil, resume_token: nil, partition_token: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Google::Cloud::Spanner::V1::ResultSet
Reads rows from the database using key lookups and scans, as a
simple key/value style alternative to
ExecuteSql. This method cannot be
used to return a result set larger than 10 MiB; if the read matches more
data than that, the read fails with a FAILED_PRECONDITION
error.
Reads inside read-write transactions might return ABORTED
. If
this occurs, the application should restart the transaction from
the beginning. See Transaction for more
details.
Larger result sets can be yielded in streaming fashion by calling StreamingRead instead.
1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1304 def read request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ReadRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.read..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.read.timeout, metadata: , retry_policy: @config.rpcs.read.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :read, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#rollback(request, options = nil) ⇒ ::Google::Protobuf::Empty #rollback(session: nil, transaction_id: nil) ⇒ ::Google::Protobuf::Empty
Rolls back a transaction, releasing any locks it holds. It is a good idea to call this for any transaction that includes one or more Read or ExecuteSql requests and ultimately decides not to commit.
Rollback
returns OK
if it successfully aborts the transaction, the
transaction was already aborted, or the transaction is not
found. Rollback
never returns ABORTED
.
1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1772 def rollback request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::RollbackRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.rollback..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.rollback.timeout, metadata: , retry_policy: @config.rpcs.rollback.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :rollback, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#streaming_read(request, options = nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet> #streaming_read(session: nil, transaction: nil, table: nil, index: nil, columns: nil, key_set: nil, limit: nil, resume_token: nil, partition_token: nil, request_options: nil, directed_read_options: nil, data_boost_enabled: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1454 def streaming_read request, = nil raise ::ArgumentError, "request must be provided" if request.nil? request = ::Gapic::Protobuf.coerce request, to: ::Google::Cloud::Spanner::V1::ReadRequest # Converts hash and nil to an options object = ::Gapic::CallOptions.new(**.to_h) if .respond_to? :to_h # Customize the options with defaults = @config.rpcs.streaming_read..to_h # Set x-goog-api-client and x-goog-user-project headers [:"x-goog-api-client"] ||= ::Gapic::Headers.x_goog_api_client \ lib_name: @config.lib_name, lib_version: @config.lib_version, gapic_version: ::Google::Cloud::Spanner::V1::VERSION [:"x-goog-user-project"] = @quota_project_id if @quota_project_id header_params = {} if request.session header_params["session"] = request.session end request_params_header = header_params.map { |k, v| "#{k}=#{v}" }.join("&") [:"x-goog-request-params"] ||= request_params_header .apply_defaults timeout: @config.rpcs.streaming_read.timeout, metadata: , retry_policy: @config.rpcs.streaming_read.retry_policy .apply_defaults timeout: @config.timeout, metadata: @config., retry_policy: @config.retry_policy @spanner_stub.call_rpc :streaming_read, request, options: do |response, operation| yield response, operation if block_given? return response end rescue ::GRPC::BadStatus => e raise ::Google::Cloud::Error.from_error(e) end |
#universe_domain ⇒ String
The effective universe domain
175 176 177 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 175 def universe_domain @spanner_stub.universe_domain end |