Using Active Record with Spanner Stay organized with collections Save and categorize content based on your preferences.
RubyActive Record is an Object-Relational Mapping (ORM)library bundled withRuby on Rails. Active Record provides anabstraction over the underlying database and includes capabilities such asautomatically generating schema changes and managing schema version history.
TheSpanner support for Active Record enablesActiveRecord users to use Spannerdatabases. With this support, Ruby applications can take advantage ofSpanner's high availability and external consistency at scalethrough an ORM.
Setting up the Spanner support for Active Record
To setup the Spanner support for Active Record in your application, edit theGemfile of your Rails application and add theactiverecord-spanner-adapter gem.
gem 'activerecord-spanner-adapter'Next, run bundle to install the gem.
bundle installAs authentication for the Spanner support for Active Record, theservice accountJSON credentials file location should be provided in theGOOGLE_APPLICATION_CREDENTIALS environment variable. Otherwise, theSpanner support for Active Record can also use the default credentials set in theGoogle Cloud SDKgcloud application.
Using the Spanner support for Active Record
For more information about the available features, limitations of theSpanner support for Active Record, recommendations on how to use it, and for codesamples, please consult thereference documentation on GitHub.
What's next
- Checkout thecode examples on how to use theSpanner support for Active Record.
- View the repository for the Spanner support for Active Record onGitHub.
- File aGitHub issue to report a bug or ask a questionabout the Spanner support for Active Record.
- Learn more aboutActive Record.
- Learn more aboutRuby Gems.
- Learn about authorization and authentication credentials inGetting startedwith authentication.
Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2026-02-19 UTC.