Class: Google::Cloud::Spanner::V1::SpannerClient
- Inherits:
-
Object
- Object
- Google::Cloud::Spanner::V1::SpannerClient
- Defined in:
- lib/google/cloud/spanner/v1/spanner_client.rb
Overview
Cloud Spanner API
The Cloud Spanner API can be used to manage sessions and execute transactions on data stored in Cloud Spanner databases.
Constant Summary collapse
- SERVICE_ADDRESS =
The default address of the service.
"spanner.googleapis.com".freeze
- DEFAULT_SERVICE_PORT =
The default port of the service.
443
- GRPC_INTERCEPTORS =
The default set of gRPC interceptors.
[]
- DEFAULT_TIMEOUT =
30
- ALL_SCOPES =
The scopes needed to make gRPC calls to all of the methods defined in this service.
[ "https://www.googleapis.com/auth/cloud-platform", "https://www.googleapis.com/auth/spanner.data" ].freeze
Class Method Summary collapse
-
.database_path(project, instance, database) ⇒ String
Returns a fully-qualified database resource name string.
-
.session_path(project, instance, database, session) ⇒ String
Returns a fully-qualified session resource name string.
Instance Method Summary collapse
-
#batch_create_sessions(database, session_count, session_template: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::BatchCreateSessionsResponse
Creates multiple new sessions.
-
#begin_transaction(session, options_, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::Transaction
Begins a new transaction.
-
#commit(session, mutations, transaction_id: nil, single_use_transaction: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::CommitResponse
Commits a transaction.
-
#create_session(database, session: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::Session
Creates a new session.
-
#delete_session(name, options: nil) {|result, operation| ... } ⇒ Object
Ends a session, releasing server resources associated with it.
-
#execute_batch_dml(session, transaction, statements, seqno, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::ExecuteBatchDmlResponse
Executes a batch of SQL DML statements.
-
#execute_sql(session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::ResultSet
Executes an SQL statement, returning all results in a single reply.
-
#execute_streaming_sql(session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, options: nil) ⇒ Enumerable<Google::Spanner::V1::PartialResultSet>
Like ExecuteSql, except returns the result set as a stream.
-
#get_session(name, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::Session
Gets a session.
-
#initialize(credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, service_address: nil, service_port: nil, exception_transformer: nil, lib_name: nil, lib_version: "") ⇒ SpannerClient
constructor
A new instance of SpannerClient.
-
#list_sessions(database, page_size: nil, filter: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>
Lists all sessions in a given database.
-
#partition_query(session, sql, transaction: nil, params: nil, param_types: nil, partition_options: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::PartitionResponse
Creates a set of partition tokens that can be used to execute a query operation in parallel.
-
#partition_read(session, table, key_set, transaction: nil, index: nil, columns: nil, partition_options: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::PartitionResponse
Creates a set of partition tokens that can be used to execute a read operation in parallel.
-
#read(session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil) {|result, operation| ... } ⇒ Google::Spanner::V1::ResultSet
Reads rows from the database using key lookups and scans, as a simple key/value style alternative to ExecuteSql.
-
#rollback(session, transaction_id, options: nil) {|result, operation| ... } ⇒ Object
Rolls back a transaction, releasing any locks it holds.
-
#streaming_read(session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil) ⇒ Enumerable<Google::Spanner::V1::PartialResultSet>
Like Read, except returns the result set as a stream.
Constructor Details
#initialize(credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, service_address: nil, service_port: nil, exception_transformer: nil, lib_name: nil, lib_version: "") ⇒ SpannerClient
Returns a new instance of SpannerClient.
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 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 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 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 341 342 343 344 345 346 347 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 148 def initialize \ credentials: nil, scopes: ALL_SCOPES, client_config: {}, timeout: DEFAULT_TIMEOUT, metadata: nil, service_address: nil, service_port: nil, exception_transformer: nil, lib_name: nil, lib_version: "" # 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 "google/gax/grpc" require "google/spanner/v1/spanner_services_pb" credentials ||= Google::Cloud::Spanner::V1::Credentials.default if credentials.is_a?(String) || credentials.is_a?(Hash) updater_proc = Google::Cloud::Spanner::V1::Credentials.new(credentials).updater_proc end if credentials.is_a?(GRPC::Core::Channel) channel = credentials end if credentials.is_a?(GRPC::Core::ChannelCredentials) chan_creds = credentials end if credentials.is_a?(Proc) updater_proc = credentials end if credentials.is_a?(Google::Auth::Credentials) updater_proc = credentials.updater_proc end package_version = Google::Cloud::Spanner::VERSION google_api_client = "gl-ruby/#{RUBY_VERSION}" google_api_client << " #{lib_name}/#{lib_version}" if lib_name google_api_client << " gapic/#{package_version} gax/#{Google::Gax::VERSION}" google_api_client << " grpc/#{GRPC::VERSION}" google_api_client.freeze headers = { :"x-goog-api-client" => google_api_client } if credentials.respond_to?(:quota_project_id) && credentials.quota_project_id headers[:"x-goog-user-project"] = credentials.quota_project_id end headers.merge!() unless .nil? client_config_file = Pathname.new(__dir__).join( "spanner_client_config.json" ) defaults = client_config_file.open do |f| Google::Gax.construct_settings( "google.spanner.v1.Spanner", JSON.parse(f.read), client_config, Google::Gax::Grpc::STATUS_CODE_NAMES, timeout, page_descriptors: PAGE_DESCRIPTORS, errors: Google::Gax::Grpc::API_ERRORS, metadata: headers ) end # Allow overriding the service path/port in subclasses. service_path = service_address || self.class::SERVICE_ADDRESS port = service_port || self.class::DEFAULT_SERVICE_PORT interceptors = self.class::GRPC_INTERCEPTORS @spanner_stub = Google::Gax::Grpc.create_stub( service_path, port, chan_creds: chan_creds, channel: channel, updater_proc: updater_proc, scopes: scopes, interceptors: interceptors, &Google::Spanner::V1::Spanner::Stub.method(:new) ) @create_session = Google::Gax.create_api_call( @spanner_stub.method(:create_session), defaults["create_session"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'database' => request.database} end ) @batch_create_sessions = Google::Gax.create_api_call( @spanner_stub.method(:batch_create_sessions), defaults["batch_create_sessions"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'database' => request.database} end ) @get_session = Google::Gax.create_api_call( @spanner_stub.method(:get_session), defaults["get_session"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'name' => request.name} end ) @list_sessions = Google::Gax.create_api_call( @spanner_stub.method(:list_sessions), defaults["list_sessions"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'database' => request.database} end ) @delete_session = Google::Gax.create_api_call( @spanner_stub.method(:delete_session), defaults["delete_session"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'name' => request.name} end ) @execute_sql = Google::Gax.create_api_call( @spanner_stub.method(:execute_sql), defaults["execute_sql"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @execute_streaming_sql = Google::Gax.create_api_call( @spanner_stub.method(:execute_streaming_sql), defaults["execute_streaming_sql"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @execute_batch_dml = Google::Gax.create_api_call( @spanner_stub.method(:execute_batch_dml), defaults["execute_batch_dml"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @read = Google::Gax.create_api_call( @spanner_stub.method(:read), defaults["read"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @streaming_read = Google::Gax.create_api_call( @spanner_stub.method(:streaming_read), defaults["streaming_read"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @begin_transaction = Google::Gax.create_api_call( @spanner_stub.method(:begin_transaction), defaults["begin_transaction"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @commit = Google::Gax.create_api_call( @spanner_stub.method(:commit), defaults["commit"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @rollback = Google::Gax.create_api_call( @spanner_stub.method(:rollback), defaults["rollback"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @partition_query = Google::Gax.create_api_call( @spanner_stub.method(:partition_query), defaults["partition_query"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) @partition_read = Google::Gax.create_api_call( @spanner_stub.method(:partition_read), defaults["partition_read"], exception_transformer: exception_transformer, params_extractor: proc do |request| {'session' => request.session} end ) end |
Class Method Details
.database_path(project, instance, database) ⇒ String
Returns a fully-qualified database resource name string.
92 93 94 95 96 97 98 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 92 def self.database_path project, instance, database DATABASE_PATH_TEMPLATE.render( :"project" => project, :"instance" => instance, :"database" => database ) end |
.session_path(project, instance, database, session) ⇒ String
Returns a fully-qualified session resource name string.
106 107 108 109 110 111 112 113 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 106 def self.session_path project, instance, database, session SESSION_PATH_TEMPLATE.render( :"project" => project, :"instance" => instance, :"database" => database, :"session" => session ) end |
Instance Method Details
#batch_create_sessions(database, session_count, session_template: nil, options: nil) {|result, operation| ... } ⇒ Google::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.
440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 440 def batch_create_sessions \ database, session_count, session_template: nil, options: nil, &block req = { database: database, session_count: session_count, session_template: session_template }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::BatchCreateSessionsRequest) @batch_create_sessions.call(req, , &block) end |
#begin_transaction(session, options_, options: nil) {|result, operation| ... } ⇒ Google::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.
1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1172 def begin_transaction \ session, , options: nil, &block req = { session: session, options: }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::BeginTransactionRequest) @begin_transaction.call(req, , &block) end |
#commit(session, mutations, transaction_id: nil, single_use_transaction: nil, options: nil) {|result, operation| ... } ⇒ Google::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.
1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1234 def commit \ session, mutations, transaction_id: nil, single_use_transaction: nil, options: nil, &block req = { session: session, mutations: mutations, transaction_id: transaction_id, single_use_transaction: single_use_transaction }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::CommitRequest) @commit.call(req, , &block) end |
#create_session(database, session: nil, options: nil) {|result, operation| ... } ⇒ Google::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"
.
392 393 394 395 396 397 398 399 400 401 402 403 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 392 def create_session \ database, session: nil, options: nil, &block req = { database: database, session: session }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::CreateSessionRequest) @create_session.call(req, , &block) end |
#delete_session(name, options: nil) {|result, operation| ... } ⇒ Object
Ends a session, releasing server resources associated with it. This will asynchronously trigger cancellation of any operations that are running with this session.
574 575 576 577 578 579 580 581 582 583 584 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 574 def delete_session \ name, options: nil, &block req = { name: name }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::DeleteSessionRequest) @delete_session.call(req, , &block) nil end |
#execute_batch_dml(session, transaction, statements, seqno, options: nil) {|result, operation| ... } ⇒ Google::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.
910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 910 def execute_batch_dml \ session, transaction, statements, seqno, options: nil, &block req = { session: session, transaction: transaction, statements: statements, seqno: seqno }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteBatchDmlRequest) @execute_batch_dml.call(req, , &block) end |
#execute_sql(session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, options: nil) {|result, operation| ... } ⇒ Google::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.
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 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 690 def execute_sql \ session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, options: nil, &block req = { session: session, sql: sql, transaction: transaction, params: params, param_types: param_types, resume_token: resume_token, query_mode: query_mode, partition_token: partition_token, seqno: seqno, query_options: }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest) @execute_sql.call(req, , &block) end |
#execute_streaming_sql(session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, options: nil) ⇒ Enumerable<Google::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.
818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 818 def execute_streaming_sql \ session, sql, transaction: nil, params: nil, param_types: nil, resume_token: nil, query_mode: nil, partition_token: nil, seqno: nil, query_options: nil, options: nil req = { session: session, sql: sql, transaction: transaction, params: params, param_types: param_types, resume_token: resume_token, query_mode: query_mode, partition_token: partition_token, seqno: seqno, query_options: }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::ExecuteSqlRequest) @execute_streaming_sql.call(req, ) end |
#get_session(name, options: nil) {|result, operation| ... } ⇒ Google::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.
476 477 478 479 480 481 482 483 484 485 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 476 def get_session \ name, options: nil, &block req = { name: name }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::GetSessionRequest) @get_session.call(req, , &block) end |
#list_sessions(database, page_size: nil, filter: nil, options: nil) {|result, operation| ... } ⇒ Google::Gax::PagedEnumerable<Google::Spanner::V1::Session>
Lists all sessions in a given database.
539 540 541 542 543 544 545 546 547 548 549 550 551 552 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 539 def list_sessions \ database, page_size: nil, filter: nil, options: nil, &block req = { database: database, page_size: page_size, filter: filter }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::ListSessionsRequest) @list_sessions.call(req, , &block) end |
#partition_query(session, sql, transaction: nil, params: nil, param_types: nil, partition_options: nil, options: nil) {|result, operation| ... } ⇒ Google::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.
1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1373 def partition_query \ session, sql, transaction: nil, params: nil, param_types: nil, partition_options: nil, options: nil, &block req = { session: session, sql: sql, transaction: transaction, params: params, param_types: param_types, partition_options: }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionQueryRequest) @partition_query.call(req, , &block) end |
#partition_read(session, table, key_set, transaction: nil, index: nil, columns: nil, partition_options: nil, options: nil) {|result, operation| ... } ⇒ Google::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.
1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1459 def partition_read \ session, table, key_set, transaction: nil, index: nil, columns: nil, partition_options: nil, options: nil, &block req = { session: session, table: table, key_set: key_set, transaction: transaction, index: index, columns: columns, partition_options: }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::PartitionReadRequest) @partition_read.call(req, , &block) end |
#read(session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil) {|result, operation| ... } ⇒ Google::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.
1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1012 def read \ session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil, &block req = { session: session, table: table, columns: columns, key_set: key_set, transaction: transaction, index: index, limit: limit, resume_token: resume_token, partition_token: partition_token }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest) @read.call(req, , &block) end |
#rollback(session, transaction_id, options: nil) {|result, operation| ... } ⇒ Object
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
.
1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1281 def rollback \ session, transaction_id, options: nil, &block req = { session: session, transaction_id: transaction_id }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::RollbackRequest) @rollback.call(req, , &block) nil end |
#streaming_read(session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil) ⇒ Enumerable<Google::Spanner::V1::PartialResultSet>
Like Read, except returns the result set as a stream. Unlike Read, 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.
1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 |
# File 'lib/google/cloud/spanner/v1/spanner_client.rb', line 1117 def streaming_read \ session, table, columns, key_set, transaction: nil, index: nil, limit: nil, resume_token: nil, partition_token: nil, options: nil req = { session: session, table: table, columns: columns, key_set: key_set, transaction: transaction, index: index, limit: limit, resume_token: resume_token, partition_token: partition_token }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Spanner::V1::ReadRequest) @streaming_read.call(req, ) end |