Tetap teratur dengan koleksi
Simpan dan kategorikan konten berdasarkan preferensi Anda.
Active Record Ruby adalah library Pemetaan
Objek-Relasi (ORM) yang dipaketkan dengan Ruby on Rails.
Active Record menyediakan abstraksi atas database yang mendasarinya dan
menyertakan kemampuan seperti membuat perubahan skema secara otomatis dan
mengelola histori versi skema.
Dukungan Spanner untuk Active Record
memungkinkan pengguna Active Record menggunakan database
Spanner. Dengan dukungan ini, aplikasi Ruby dapat memanfaatkan
ketersediaan tinggi dan konsistensi eksternal Spanner dalam skala besar melalui
ORM.
Menyiapkan dukungan Spanner untuk Active Record
Untuk menyiapkan dukungan Spanner untuk Active Record di aplikasi Anda, edit
Gemfile aplikasi Rails dan tambahkan
gem activerecord-spanner-adapter.
gem 'activerecord-spanner-adapter'
Selanjutnya, jalankan bundle untuk menginstal gem.
bundle install
Sebagai autentikasi untuk dukungan Spanner untuk Active Record, lokasi file kredensial JSON akun layanan harus diberikan di variabel lingkungan GOOGLE_APPLICATION_CREDENTIALS.
Jika tidak, dukungan Spanner untuk Active Record juga dapat menggunakan kredensial default yang ditetapkan di aplikasi gcloud Google Cloud SDK.
Menggunakan dukungan Spanner untuk Active Record
Untuk informasi selengkapnya tentang fitur yang tersedia, batasan dukungan
Spanner untuk Active Record, rekomendasi tentang cara menggunakannya, dan untuk contoh
kode, lihat
dokumentasi referensi
di GitHub.
Langkah selanjutnya
Lihat contoh kode tentang cara menggunakan dukungan Spanner untuk Active Record.
Lihat repositori untuk dukungan Spanner untuk Active Record di
GitHub.
Buat masalah GitHub untuk melaporkan bug atau mengajukan
pertanyaan tentang dukungan Spanner untuk Active Record.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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)."]]