Reference documentation and code samples for the Cloud Spanner API module Google::Cloud::Spanner.
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.
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
quota_project - (String) The project ID for a project that can be
used by client libraries for quota and billing purposes.
timeout - (Integer) Default timeout to use in requests.
endpoint - (String) Override of the endpoint host name, or nil
to use the default endpoint.
emulator_host - (String) Host name of the emulator. Defaults to
ENV["SPANNER_EMULATOR_HOST"].
lib_name - (String) Override the lib name , or nil
to use the default lib name without prefix in agent tracking
header.
lib_version - (String) Override the lib version , or nil
to use the default version lib name without prefix in agent
tracking header.
Yields
(Google::Cloud.configure.spanner)
Returns
(Google::Cloud::Config) — The configuration object the
Google::Cloud::Spanner library uses.
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.
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)
If emulator_host is present, this becomes optional and the value is
internally overriden with :this_channel_is_insecure.
scope (String, Array<String>) (defaults to: nil) —
timeout (Integer) (defaults to: nil) — Default timeout to use in requests. Optional.
endpoint (String) (defaults to: nil) — Override of the endpoint host name. Optional.
If the param is nil, uses emulator_host or 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.
emulator_host (String) (defaults to: nil) — Spanner emulator host. Optional.
If the param is nil, uses the value of the emulator_host config.
lib_name (String) (defaults to: nil) — Library name. This will be added as a prefix
to the API call tracking header x-goog-api-client with provided
lib version for telemetry. Optional. For example prefix looks like
spanner-activerecord/0.0.1 gccl/1.13.1. Here,
spanner-activerecord/0.0.1 is provided custom library name and
version and gccl/1.13.1 represents the Cloud Spanner Ruby library
with version.
lib_version (String) (defaults to: nil) — Library version. This will be added as a
prefix to the API call tracking header x-goog-api-client with
provided lib name for telemetry. Optional. For example prefix look like
spanner-activerecord/0.0.1 gccl/1.13.1. Here,
spanner-activerecord/0.0.1 is provided custom library name and
version and gccl/1.13.1 represents the Cloud Spanner Ruby library
with version.
enable_leader_aware_routing (Boolean) (defaults to: true) — Specifies whether Leader
Aware Routing should be enabled. Defaults to true.
universe_domain (String) (defaults to: nil) — A custom universe domain. Optional.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-28 UTC."],[],[],null,["# Cloud Spanner API - Module Google::Cloud::Spanner (v2.27.0)\n\nVersion latestkeyboard_arrow_down\n\n- [2.27.0 (latest)](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner)\n- [2.26.0](/ruby/docs/reference/google-cloud-spanner/2.26.0/Google-Cloud-Spanner)\n- [2.25.0](/ruby/docs/reference/google-cloud-spanner/2.25.0/Google-Cloud-Spanner)\n- [2.24.0](/ruby/docs/reference/google-cloud-spanner/2.24.0/Google-Cloud-Spanner)\n- [2.23.0](/ruby/docs/reference/google-cloud-spanner/2.23.0/Google-Cloud-Spanner)\n- [2.22.0](/ruby/docs/reference/google-cloud-spanner/2.22.0/Google-Cloud-Spanner)\n- [2.21.0](/ruby/docs/reference/google-cloud-spanner/2.21.0/Google-Cloud-Spanner)\n- [2.20.0](/ruby/docs/reference/google-cloud-spanner/2.20.0/Google-Cloud-Spanner)\n- [2.19.1](/ruby/docs/reference/google-cloud-spanner/2.19.1/Google-Cloud-Spanner)\n- [2.18.1](/ruby/docs/reference/google-cloud-spanner/2.18.1/Google-Cloud-Spanner)\n- [2.17.0](/ruby/docs/reference/google-cloud-spanner/2.17.0/Google-Cloud-Spanner)\n- [2.16.1](/ruby/docs/reference/google-cloud-spanner/2.16.1/Google-Cloud-Spanner)\n- [2.15.0](/ruby/docs/reference/google-cloud-spanner/2.15.0/Google-Cloud-Spanner)\n- [2.14.0](/ruby/docs/reference/google-cloud-spanner/2.14.0/Google-Cloud-Spanner)\n- [2.13.0](/ruby/docs/reference/google-cloud-spanner/2.13.0/Google-Cloud-Spanner)\n- [2.12.1](/ruby/docs/reference/google-cloud-spanner/2.12.1/Google-Cloud-Spanner)\n- [2.11.0](/ruby/docs/reference/google-cloud-spanner/2.11.0/Google-Cloud-Spanner) \nReference documentation and code samples for the Cloud Spanner API module Google::Cloud::Spanner.\n\nCloud Spanner\n-------------\n\nCloud Spanner is a fully managed, mission-critical, relational database\nservice that offers transactional consistency at global scale, schemas,\nSQL (ANSI 2011 with extensions), and automatic, synchronous replication\nfor high availability.\n\nFor more information about Cloud Spanner, read the [Cloud\nSpanner Documentation](https://cloud.google.com/spanner/docs/).\n\nSee [Spanner Overview](./index.html \"Spanner Overview\").\n\nMethods\n-------\n\n### .configure\n\n def self.configure() -\u003e Google::Cloud::Config\n\nConfigure the Google Cloud Spanner library.\n\nThe following Spanner configuration parameters are supported:\n\n- `project_id` - (String) Identifier for a Spanner project. (The parameter `project` is considered deprecated, but may also be used.)\n- `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](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Credentials \"Google::Cloud::Spanner::Credentials (class)\")) (The parameter `keyfile` is considered deprecated, but may also be used.)\n- `scope` - (String, Array\n- `quota_project` - (String) The project ID for a project that can be used by client libraries for quota and billing purposes.\n- `timeout` - (Integer) Default timeout to use in requests.\n- `endpoint` - (String) Override of the endpoint host name, or `nil` to use the default endpoint.\n- `emulator_host` - (String) Host name of the emulator. Defaults to `ENV[\"SPANNER_EMULATOR_HOST\"]`.\n- `lib_name` - (String) Override the lib name , or `nil` to use the default lib name without prefix in agent tracking header.\n- `lib_version` - (String) Override the lib version , or `nil` to use the default version lib name without prefix in agent tracking header. \n**Yields**\n\n- (Google::Cloud.configure.spanner) \n**Returns**\n\n- (Google::Cloud::Config) --- The configuration object the Google::Cloud::Spanner library uses.\n\n### .new\n\n def self.new(project_id: nil, credentials: nil, scope: nil, timeout: nil, endpoint: nil, project: nil, keyfile: nil, emulator_host: nil, lib_name: nil, lib_version: nil, enable_leader_aware_routing: true, universe_domain: nil) -\u003e Google::Cloud::Spanner::Project\n\nCreates a new object for connecting to the Spanner service.\nEach call creates a new connection.\n\n\n\u003cbr /\u003e\n\nFor more information on connecting to Google Cloud see the\n[Authentication Guide](./AUTHENTICATION \"Authentication Guide\"). \n**Parameters**\n\n- **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.\n- **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](/ruby/docs/reference/google-cloud-spanner/latest/Google-Cloud-Spanner-Credentials \"Google::Cloud::Spanner::Credentials (class)\")) If `emulator_host` is present, this becomes optional and the value is internally overriden with `:this_channel_is_insecure`.\n- **scope** (String, Array\\\u003cString\\\u003e) *(defaults to: nil)* ---\n\n The OAuth 2.0 scopes controlling\n the set of resources and operations that the connection can access.\n See [Using OAuth 2.0 to Access Google\n APIs](https://developers.google.com/identity/protocols/OAuth2).\n\n The default scopes are:\n - `https://www.googleapis.com/auth/spanner`\n - `https://www.googleapis.com/auth/spanner.data`\n- **timeout** (Integer) *(defaults to: nil)* --- Default timeout to use in requests. Optional.\n- **endpoint** (String) *(defaults to: nil)* --- Override of the endpoint host name. Optional. If the param is nil, uses `emulator_host` or the default endpoint.\n- **project** (String) *(defaults to: nil)* --- Alias for the `project_id` argument. Deprecated.\n- **keyfile** (String) *(defaults to: nil)* --- Alias for the `credentials` argument. Deprecated.\n- **emulator_host** (String) *(defaults to: nil)* --- Spanner emulator host. Optional. If the param is nil, uses the value of the `emulator_host` config.\n- **lib_name** (String) *(defaults to: nil)* --- Library name. This will be added as a prefix to the API call tracking header `x-goog-api-client` with provided lib version for telemetry. Optional. For example prefix looks like `spanner-activerecord/0.0.1 gccl/1.13.1`. Here, `spanner-activerecord/0.0.1` is provided custom library name and version and `gccl/1.13.1` represents the Cloud Spanner Ruby library with version.\n- **lib_version** (String) *(defaults to: nil)* --- Library version. This will be added as a prefix to the API call tracking header `x-goog-api-client` with provided lib name for telemetry. Optional. For example prefix look like `spanner-activerecord/0.0.1 gccl/1.13.1`. Here, `spanner-activerecord/0.0.1` is provided custom library name and version and `gccl/1.13.1` represents the Cloud Spanner Ruby library with version.\n- **enable_leader_aware_routing** (Boolean) *(defaults to: true)* --- Specifies whether Leader Aware Routing should be enabled. Defaults to true.\n- **universe_domain** (String) *(defaults to: nil)* --- A custom universe domain. Optional. \n**Returns**\n\n- ([Google::Cloud::Spanner::Project](./Google-Cloud-Spanner-Project)) \n**Raises**\n\n- (ArgumentError)\n**Example** \n\n```ruby\nrequire \"google/cloud/spanner\"\n\nspanner = Google::Cloud::Spanner.new\n```\n\nConstants\n---------\n\n### VERSION\n\n**value:**\"2.27.0\".freeze"]]