Using Active Record with Cloud Spanner

Ruby Active Record is an Object-Relational Mapping (ORM) library bundled with Ruby on Rails. Active Record provides an abstraction over the underlying database and includes capabilities such as automatically generating schema changes and managing schema version history.

The Cloud Spanner support for Active Record enables Active Record users to use Cloud Spanner databases. With this support, Ruby applications can take advantage of Cloud Spanner's high availability and external consistency at scale through an ORM.

Setting up the Cloud Spanner support for Active Record

To setup the Cloud Spanner support for Active Record in your application, edit the Gemfile of your Rails application and add the activerecord-spanner-adapter gem.

gem 'activerecord-spanner-adapter'

Next, run bundle to install the gem.

bundle install

As authentication for the Cloud Spanner support for Active Record, the service account JSON credentials file location should be provided in the GOOGLE_APPLICATION_CREDENTIALS environment variable. Otherwise, the Cloud Spanner support for Active Record can also use the default credentials set in the Google Cloud SDK gcloud application.

Using the Cloud Spanner support for Active Record

For more information about the available features, limitations of the Cloud Spanner support for Active Record, recommendations on how to use it, and for code samples, please consult the reference documentation on GitHub.

What's next