@@ -43,8 +43,18 @@ class Service
4343 RST_STREAM_INTERNAL_ERROR = "Received RST_STREAM" . freeze
4444 EOS_INTERNAL_ERROR = "Received unexpected EOS on DATA frame from server" . freeze
4545
46- ##
47- # Creates a new Service instance.
46+ # Creates a new `Spanner::Service` instance.
47+ # @param project [::String] The project id to use
48+ # @param credentials [::Symbol, ::Google::Auth::Credentials] Credentials
49+ # @param quota_project_id [::String, nil] Optional. The quota project id to use
50+ # @param host [::String, nil] Optional. The endpoint override.
51+ # @param timeout [::Numeric, nil] Optional. Timeout for Gapic client.
52+ # @param lib_name [::String, nil] Optional. Library name for headers.
53+ # @param lib_version [::String, nil] Optional. Library version for headers.
54+ # @param enable_leader_aware_routing [::Boolean, nil] Optional. Whether Leader
55+ # Aware Routing should be enabled.
56+ # @param universe_domain [::String, nil] Optional. The domain of the universe to connect to.
57+ # @private
4858 def initialize project , credentials , quota_project : nil ,
4959 host : nil , timeout : nil , lib_name : nil , lib_version : nil ,
5060 enable_leader_aware_routing : nil , universe_domain : nil
@@ -82,6 +92,8 @@ def chan_creds
8292 GRPC ::Core ::CallCredentials . new credentials . client . updater_proc
8393 end
8494
95+ # `V1::Spanner::Client` or mock.
96+ # @return [::Google::Cloud::Spanner::V1::Spanner::Client]
8597 def service
8698 return mocked_service if mocked_service
8799 @service ||=
@@ -329,13 +341,40 @@ def get_session session_name, call_options: nil
329341 service . get_session ( { name : session_name } , opts )
330342 end
331343
344+ # Creates a new Spanner session.
345+ # This creates a `V1::Session` protobuf object not wrapped in `Spanner::Session`.
346+ #
347+ # @param database_name [::String] The full name of the database.
348+ # @param labels [::Hash, nil] Optional. The labels to be applied to all sessions
349+ # created by the client. Example: `"team" => "billing-service"`.
350+ # @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
351+ # call options. Example option `:timeout`.
352+ # @param database_role [::String, nil] Optional. The Spanner session creator role.
353+ # Example: `analyst`.
354+ # @param multiplexed [::Boolean] Optional. Default to `false`.
355+ # If `true`, specifies a multiplexed session.
356+ # @return [::Google::Cloud::Spanner::V1::Session]
357+ # @private
332358 def create_session database_name , labels : nil ,
333- call_options : nil , database_role : nil
359+ call_options : nil , database_role : nil ,
360+ multiplexed : false
334361 route_to_leader = LARHeaders . create_session
335- opts = default_options session_name : database_name ,
336- call_options : call_options ,
337- route_to_leader : route_to_leader
338- session = V1 ::Session . new labels : labels , creator_role : database_role if labels || database_role
362+ opts = default_options (
363+ session_name : database_name ,
364+ call_options : call_options ,
365+ route_to_leader : route_to_leader
366+ )
367+
368+ params_diff_from_default = !( labels || database_role || multiplexed ) . nil?
369+
370+ if params_diff_from_default
371+ session = V1 ::Session . new (
372+ labels : labels ,
373+ creator_role : database_role ,
374+ multiplexed : multiplexed
375+ )
376+ end
377+
339378 service . create_session (
340379 { database : database_name , session : session } , opts
341380 )
@@ -464,6 +503,29 @@ def partition_query session_name, sql, transaction, params: nil,
464503 service . partition_query request , opts
465504 end
466505
506+ # Commits a transaction. Can be a predefined (`transaction_id`) transaction
507+ # or a single-use created for this request. The request includes the mutations to be
508+ # applied to rows in the database.
509+ #
510+ # @param session_name [::String]
511+ # Required. The session in which the transaction to be committed is running.
512+ # @param mutations [::Array<::Google::Cloud::Spanner::V1::Mutation>] Optional.
513+ # The mutations to be executed when this transaction commits. All
514+ # mutations are applied atomically, in the order they appear in
515+ # this list. Defaults to an empty array.
516+ # @param transaction_id [::String, nil] Optional.
517+ # Commit a previously-started transaction. If nil, a new single-use transation will be used.
518+ # @param exclude_txn_from_change_streams [::Boolean] Optional. Defaults to `false`.
519+ # When `exclude_txn_from_change_streams` is set to `true`, it prevents read
520+ # or write transactions from being tracked in change streams.
521+ # @param commit_options [::Hash, nil] Optional. A hash of commit options.
522+ # Example option: `:return_commit_stats`.
523+ # @param request_options [::Hash, nil] Optional. Common request options.
524+ # Example option: `:priority`.
525+ # @param call_options [::Hash, nil] Optional. A hash of values to specify the custom
526+ # call options. Example option `:timeout`.
527+ # @return [::Google::Cloud::Spanner::V1::CommitResponse]
528+ # @private
467529 def commit session_name , mutations = [ ] ,
468530 transaction_id : nil , exclude_txn_from_change_streams : false ,
469531 commit_options : nil , request_options : nil , call_options : nil
@@ -485,10 +547,16 @@ def commit session_name, mutations = [],
485547 }
486548
487549 request = add_commit_options request , commit_options
488-
550+ # request is a hash equivalent of `::Google::Cloud::Spanner::V1::CommitRequest`
489551 service . commit request , opts
490552 end
491553
554+ # Merges commit options hash to a hash representing a `V1::CommitRequest`.
555+ # @param request [::Hash] A `::Google::Cloud::Spanner::V1::CommitRequest` in a hash form.
556+ # @param commit_options [::Hash, nil] Optional. A hash of commit options.
557+ # Example option: `:return_commit_stats`.
558+ # @return [Hash] An enriched `::Google::Cloud::Spanner::V1::CommitRequest` in a hash form.
559+ # @private
492560 def add_commit_options request , commit_options
493561 if commit_options
494562 if commit_options . key? :return_commit_stats
0 commit comments