Ruby Active Record は、Ruby on Rails にバンドルされたオブジェクト リレーショナル マッピング(ORM)ライブラリです。Active Record は、基盤となるデータベースを抽象化し、スキーマの変更を自動生成する機能やスキーマのバージョン履歴を管理する機能などを提供します。
[[["わかりやすい","easyToUnderstand","thumb-up"],["問題の解決に役立った","solvedMyProblem","thumb-up"],["その他","otherUp","thumb-up"]],[["わかりにくい","hardToUnderstand","thumb-down"],["情報またはサンプルコードが不正確","incorrectInformationOrSampleCode","thumb-down"],["必要な情報 / サンプルがない","missingTheInformationSamplesINeed","thumb-down"],["翻訳に関する問題","translationIssue","thumb-down"],["その他","otherDown","thumb-down"]],["最終更新日 2025-09-03 UTC。"],[],[],null,["# Using Active Record with Spanner\n\nRuby [Active Record](https://guides.rubyonrails.org/active_record_basics.html) is an Object-Relational\nMapping (ORM) library bundled with [Ruby on Rails](https://rubyonrails.org/).\nActive Record provides an abstraction over the underlying database and\nincludes capabilities such as automatically generating schema changes and\nmanaging schema version history.\n\nThe [Spanner support for Active Record](https://github.com/googleapis/ruby-spanner-activerecord)\nenables [Active Record](https://guides.rubyonrails.org/active_record_basics.html) users to use Spanner\ndatabases. With this support, Ruby applications can take advantage of\nSpanner's high availability and external consistency at scale through\nan ORM.\n\n\n| **PostgreSQL interface note:** The [PostgreSQL interface for Spanner](/spanner/docs/postgresql-interface) doesn't support Active Record.\n\n\u003cbr /\u003e\n\nSetting up the Spanner support for Active Record\n------------------------------------------------\n\nTo setup the Spanner support for Active Record in your application, edit the\n`Gemfile` of your Rails application and add the\n[activerecord-spanner-adapter](https://rubygems.org/gems/activerecord-spanner-adapter)\ngem. \n\n gem 'activerecord-spanner-adapter'\n\nNext, run bundle to install the gem. \n\n bundle install\n\nAs authentication for the Spanner support for Active Record, the\n[service account JSON credentials](/docs/authentication/getting-started) file location should be\nprovided in the `GOOGLE_APPLICATION_CREDENTIALS` environment variable.\nOtherwise, the Spanner support for Active Record can also use the default credentials\nset in the Google Cloud SDK `gcloud` application.\n\nUsing the Spanner support for Active Record\n-------------------------------------------\n\nFor more information about the available features, limitations of the\nSpanner support for Active Record, recommendations on how to use it, and for code\nsamples, please consult the\n[reference documentation](https://github.com/googleapis/ruby-spanner-activerecord#readme)\non GitHub.\n\nWhat's next\n-----------\n\n- Checkout the [code examples](https://github.com/googleapis/ruby-spanner-activerecord#examples) on how to use the Spanner support for Active Record.\n- View the repository for the Spanner support for Active Record on [GitHub](https://github.com/googleapis/ruby-spanner-activerecord).\n- File a [GitHub issue](https://github.com/googleapis/ruby-spanner-activerecord/issues) to report a bug or ask a question about the Spanner support for Active Record.\n- Learn more about [Active Record](https://guides.rubyonrails.org/active_record_basics.html).\n- Learn more about [Ruby Gems](https://rubygems.org/).\n- Learn about authorization and authentication credentials in [Getting started with authentication](/docs/authentication/getting-started)."]]