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.
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 234 235 236 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 198 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.
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 149 150 151 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 65 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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, 8] } 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.
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 438 439 440 441 442 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 402 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 2208 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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, mutation_key: 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.
1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1593 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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, precommit_token: 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.
1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1727 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
168 169 170 171 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 168 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"
.
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 341 342 343 344 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 304 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
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 721 722 723 724 725 726 727 728 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 688 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
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 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1158 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
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 897 898 899 900 901 902 903 904 905 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 865 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
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 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1037 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
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 525 526 527 528 529 530 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 490 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
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 634 635 636 637 638 639 640 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 599 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1961 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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.
2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 2088 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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, order_by: nil, lock_hint: 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.
1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1326 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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
.
1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1823 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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, order_by: nil, lock_hint: nil) ⇒ ::Enumerable<::Google::Cloud::Spanner::V1::PartialResultSet>
1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 1488 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, x-goog-user-project and x-goog-api-version 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-api-version"] = API_VERSION unless API_VERSION.empty? [:"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
178 179 180 |
# File 'lib/google/cloud/spanner/v1/spanner/client.rb', line 178 def universe_domain @spanner_stub.universe_domain end |