Module: Google::Cloud::Spanner

Defined in:
lib/google/cloud/spanner.rb,
lib/google/cloud/spanner/data.rb,
lib/google/cloud/spanner/pool.rb,
lib/google/cloud/spanner/range.rb,
lib/google/cloud/spanner/client.rb,
lib/google/cloud/spanner/commit.rb,
lib/google/cloud/spanner/errors.rb,
lib/google/cloud/spanner/fields.rb,
lib/google/cloud/spanner/policy.rb,
lib/google/cloud/spanner/status.rb,
lib/google/cloud/spanner/convert.rb,
lib/google/cloud/spanner/project.rb,
lib/google/cloud/spanner/results.rb,
lib/google/cloud/spanner/service.rb,
lib/google/cloud/spanner/session.rb,
lib/google/cloud/spanner/version.rb,
lib/google/cloud/spanner/database.rb,
lib/google/cloud/spanner/instance.rb,
lib/google/cloud/spanner/snapshot.rb,
lib/google/cloud/spanner/partition.rb,
lib/google/cloud/spanner/credentials.rb,
lib/google/cloud/spanner/transaction.rb,
lib/google/cloud/spanner/batch_client.rb,
lib/google/cloud/spanner/batch_update.rb,
lib/google/cloud/spanner/column_value.rb,
lib/google/cloud/spanner/database/job.rb,
lib/google/cloud/spanner/instance/job.rb,
lib/google/cloud/spanner/database/list.rb,
lib/google/cloud/spanner/instance/list.rb,
lib/google/cloud/spanner/admin/database.rb,
lib/google/cloud/spanner/admin/instance.rb,
lib/google/cloud/spanner/batch_snapshot.rb,
lib/google/cloud/spanner/v1/credentials.rb,
lib/google/cloud/spanner/instance/config.rb,
lib/google/cloud/spanner/admin/database/v1.rb,
lib/google/cloud/spanner/admin/instance/v1.rb,
lib/google/cloud/spanner/v1/spanner_client.rb,
lib/google/cloud/spanner/instance/config/list.rb,
lib/google/cloud/spanner/admin/database/credentials.rb,
lib/google/cloud/spanner/admin/instance/credentials.rb,
lib/google/cloud/spanner/admin/database/v1/credentials.rb,
lib/google/cloud/spanner/admin/instance/v1/credentials.rb,
lib/google/cloud/spanner/admin/database/v1/database_admin_client.rb,
lib/google/cloud/spanner/admin/instance/v1/instance_admin_client.rb

Overview

Cloud Spanner

Cloud Spanner is a fully managed, mission-critical, relational database service that offers transactional consistency at global scale, schemas, SQL (ANSI 2011 with extensions), and automatic, synchronous replication for high availability.

For more information about Cloud Spanner, read the Cloud Spanner Documentation.

See Spanner Overview.

Defined Under Namespace

Modules: Admin, V1 Classes: BatchClient, BatchSnapshot, BatchUpdate, BatchUpdateError, Client, ClientClosedError, ColumnValue, Commit, Credentials, Data, Database, DuplicateNameError, Fields, Instance, Partition, Policy, Project, Range, Results, Rollback, SessionLimitError, Snapshot, Status, Transaction

Constant Summary collapse

VERSION =
"1.10.1".freeze

Class Method Summary collapse

Class Method Details

.configure {|Google::Cloud.configure.spanner| ... } ⇒ Google::Cloud::Config

Configure the Google Cloud Spanner library.

The following Spanner configuration parameters are supported:

  • project_id - (String) Identifier for a Spanner project. (The parameter project is considered deprecated, but may also be used.)
  • credentials - (String, Hash, Google::Auth::Credentials) The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials) (The parameter keyfile is considered deprecated, but may also be used.)
  • scope - (String, Array) The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access.
  • timeout - (Integer) Default timeout to use in requests.
  • client_config - (Hash) A hash of values to override the default behavior of the API client.
  • endpoint - (String) Override of the endpoint host name, or nil to use the default endpoint.

Yields:

Returns:

  • (Google::Cloud::Config)

    The configuration object the Google::Cloud::Spanner library uses.



124
125
126
127
128
# File 'lib/google/cloud/spanner.rb', line 124

def self.configure
  yield Google::Cloud.configure.spanner if block_given?

  Google::Cloud.configure.spanner
end

.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, client_config: nil, endpoint: nil, project: nil, keyfile: nil) ⇒ Google::Cloud::Spanner::Project

Creates a new object for connecting to the Spanner service. Each call creates a new connection.

For more information on connecting to Google Cloud see the Authentication Guide.

Examples:

require "google/cloud/spanner"

spanner = Google::Cloud::Spanner.new

Parameters:

  • project_id (String) (defaults to: nil)

    Project identifier for the Spanner service you are connecting to. If not present, the default project for the credentials is used.

  • credentials (String, Hash, Google::Auth::Credentials) (defaults to: nil)

    The path to the keyfile as a String, the contents of the keyfile as a Hash, or a Google::Auth::Credentials object. (See Credentials)

  • scope (String, Array<String>) (defaults to: nil)

    The OAuth 2.0 scopes controlling the set of resources and operations that the connection can access. See Using OAuth 2.0 to Access Google APIs.

    The default scopes are:

    • https://www.googleapis.com/auth/spanner
    • https://www.googleapis.com/auth/spanner.data
  • timeout (Integer) (defaults to: nil)

    Default timeout to use in requests. Optional.

  • client_config (Hash) (defaults to: nil)

    A hash of values to override the default behavior of the API client. Optional.

  • endpoint (String) (defaults to: nil)

    Override of the endpoint host name. Optional. If the param is nil, uses the default endpoint.

  • project (String) (defaults to: nil)

    Alias for the project_id argument. Deprecated.

  • keyfile (String) (defaults to: nil)

    Alias for the credentials argument. Deprecated.

Returns:

Raises:

  • (ArgumentError)


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
# File 'lib/google/cloud/spanner.rb', line 75

def self.new project_id: nil, credentials: nil, scope: nil, timeout: nil,
             client_config: nil, endpoint: nil, project: nil, keyfile: nil
  project_id    ||= (project || default_project_id)
  scope         ||= configure.scope
  timeout       ||= configure.timeout
  client_config ||= configure.client_config
  endpoint      ||= configure.endpoint
  credentials   ||= (keyfile || default_credentials(scope: scope))

  unless credentials.is_a? Google::Auth::Credentials
    credentials = Spanner::Credentials.new credentials, scope: scope
  end

  if credentials.respond_to? :project_id
    project_id ||= credentials.project_id
  end
  project_id = project_id.to_s # Always cast to a string
  raise ArgumentError, "project_id is missing" if project_id.empty?

  Spanner::Project.new(
    Spanner::Service.new(
      project_id, credentials,
      host: endpoint, timeout: timeout, client_config: client_config
    )
  )
end