Using Active Record with 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 Spanner support for Active Record enables Active Record users to use Spanner databases. With this support, Ruby applications can take advantage of Spanner's high availability and external consistency at scale through an ORM.

Setting up the Spanner support for Active Record

To setup the 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 Spanner support for Active Record, the service account JSON credentials file location should be provided in the GOOGLE_APPLICATION_CREDENTIALS environment variable. Otherwise, the Spanner support for Active Record can also use the default credentials set in the Google Cloud SDK gcloud application.

Using the Spanner support for Active Record

For more information about the available features, limitations of the 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