ActAsFireRecordBeta
- Provides Rails applications with an ActiveRecord-like interface to manipulate Firestore.
- Works as a wrapper for the google-cloud-firestore gem.
Installation
Add this line to your application's Gemfile:
gem "act_as_fire_record_beta"And then execute:
$ bundleOr install it yourself as:
$ gem install act_as_fire_record_betaOverview
Model example:
class Book
include ActAsFireRecordBeta
firestore_attribute :title, :string
firestore_attribute :published_on, :date
firestore_attribute :page, :integer
validates :title, presence: true
before_validation :titleize_title
private
def titleize_title
self.title = title.to_s.titleize
end
endCRUD example:
# Create
book = Book.new(title: 'An Awesome Book', published_on: '2022-12-01'.to_date, page: 200)
book.save
bool.id #=> IdG0ZWT0I5DucEQuRgoP
# Read
id = 'IdG0ZWT0I5DucEQuRgoP'
book = Book.find(id)
# Update
book.update(page: 210)
# Delete
book.destroyFinder examples:
book = Book.find_by(title: 'An Awesome Book')
books = Book.all
books = Book.order(:title)
books = Book.order(:title, :desc)
books = Book.where(:page, :>=, 200)
books = Book.where(:page, :>=, 200).order(:page)Please refer test codes for other APIs.
- https://github.com/JunichiIto/act_as_fire_record_beta/blob/main/test/act_as_fire_record_beta_test.rb
- https://github.com/JunichiIto/act_as_fire_record_beta/blob/main/test/google/cloud/firestore/query_test.rb
Setup, usage and etc.
As of now, Japanese document is only available.
Google translate might help you.
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.