Google Cloud Spanner API (docs) provides 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.
- google-cloud-spanner API documentation
- google-cloud-spanner on RubyGems
- Google Cloud Spanner API documentation
From google-cloud-spanner/v2.11.0
onwards, new features for mananging
databases, instances and backups will only be available through the
google-cloud-spanner-admin-instance-v1
and
google-cloud-spanner-admin-database-v1
packages. The
Database
,
Instance
and
Backup
classes in
google-cloud-spanner
and methods related to database and instance management in the
Project
class,
will no longer be updated to support new features. Please refer to the FAQ
for further details.
$ gem install google-cloud-spanner
This library uses Service Account credentials to connect to Google Cloud services. When running on Google Cloud Platform (GCP), including Google Compute Engine (GCE), Google Kubernetes Engine (GKE), Google App Engine (GAE), Google Cloud Functions (GCF) and Cloud Run, the credentials will be discovered automatically. When running on other environments the Service Account credentials can be specified by providing the path to the JSON file, or the JSON itself, in environment variables.
Instructions and configuration options are covered in the Authentication Guide.
require "google/cloud/spanner"
spanner = Google::Cloud::Spanner.new
db = spanner.client "my-instance", "my-database"
db.transaction do |tx|
results = tx.execute_query "SELECT * FROM users"
results.rows.each do |row|
puts "User #{row[:id]} is #{row[:name]}"
end
end
To enable logging for this library, set the logger for the underlying gRPC library. The logger that you set may be a Ruby stdlib Logger
as shown below, or a Google::Cloud::Logging::Logger
that will write logs to Stackdriver Logging. See grpc/logconfig.rb and the gRPC spec_helper.rb for additional information.
Configuring a Ruby stdlib logger:
require "logger"
module MyLogger
LOGGER = Logger.new $stderr, level: Logger::WARN
def logger
LOGGER
end
end
# Define a gRPC module-level logger method before grpc/logconfig.rb loads.
module GRPC
extend MyLogger
end
Yes, these classes and methods can continue to be used for the forseeable
future, even in production applications. P0/P1 bug fixes and security patches
for up to 1 year will be provided after google-cloud-spanner/v2.11.0
is released.
When should I use the google-cloud-spanner-admin-instance-v1
and google-cloud-spanner-admin-database-v1
packages?
Only when your application needs to use Cloud Spanner features for managing
databases and instances that are released after google-cloud-spanner/v2.11.0
.
You may continue to use the existing Database
, Instance
and Backup
classes
from google-cloud-spanner
, and the methods from the Project
class for all
existing usages in your code for managing databases, instances and backups.
Google::Cloud::Spanner::Backup
Google::Cloud::Spanner::Backup::Job
Google::Cloud::Spanner::Backup::Job::List
Google::Cloud::Spanner::Backup::List
Google::Cloud::Spanner::Backup::Restore::Job
Google::Cloud::Spanner::Database
Google::Cloud::Spanner::Database::BackupInfo
Google::Cloud::Spanner::Database::Config
Google::Cloud::Spanner::Database::Job
Google::Cloud::Spanner::Database::Job::List
Google::Cloud::Spanner::Database::List
Google::Cloud::Spanner::Database::RestoreInfo
Google::Cloud::Spanner::Instance
Google::Cloud::Spanner::Instance::Config
Google::Cloud::Spanner::Instance::Job
Google::Cloud::Spanner::Instance::Job::List
Google::Cloud::Spanner::Instance::List
Google::Cloud::Spanner::Project#create_database
Google::Cloud::Spanner::Project#create_instance
Google::Cloud::Spanner::Project#database
Google::Cloud::Spanner::Project#databases
Google::Cloud::Spanner::Project#database_path
Google::Cloud::Spanner::Project#instance
Google::Cloud::Spanner::Project#instances
Google::Cloud::Spanner::Project#instance_config
Google::Cloud::Spanner::Project#instance_configs
The code samples for all new features that relate to managing databases and
instances will include code samples on how to use the feature through
google-cloud-spanner-admin-instance-v1
or
google-cloud-spanner-admin-database-v1
in the documentation.
Code samples on how to manage instances and databases can also be found in OVERVIEW.
This library is supported on Ruby 2.5+.
Google provides official support for Ruby versions that are actively supported by Ruby Core—that is, Ruby versions that are either in normal maintenance or in security maintenance, and not end of life. Currently, this means Ruby 2.5 and later. Older versions of Ruby may still work, but are unsupported and not recommended. See https://www.ruby-lang.org/en/downloads/branches/ for details about the Ruby support schedule.
This library follows Semantic Versioning.
Contributions to this library are always welcome and highly encouraged.
See the Contributing Guide for more information on how to get started.
Please note that this project is released with a Contributor Code of Conduct. By participating in this project you agree to abide by its terms. See Code of Conduct for more information.
This library is licensed under Apache 2.0. Full license text is available in LICENSE.
Please report bugs at the project on Github. Don't hesitate to ask questions about the client or APIs on StackOverflow.