https://github.com/shinyak14/gdatastore_mapper
Google Cloud Datastore Mapper in Ruby / Ruby on Rails
https://github.com/shinyak14/gdatastore_mapper
google-cloud-datastore rails ruby
Last synced: 2 months ago
JSON representation
Google Cloud Datastore Mapper in Ruby / Ruby on Rails
- Host: GitHub
- URL: https://github.com/shinyak14/gdatastore_mapper
- Owner: shinyaK14
- License: mit
- Created: 2017-04-05T09:44:34.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2017-05-03T18:47:39.000Z (about 9 years ago)
- Last Synced: 2025-06-27T07:02:24.906Z (about 1 year ago)
- Topics: google-cloud-datastore, rails, ruby
- Language: Ruby
- Homepage:
- Size: 90.8 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
- Code of conduct: CODE_OF_CONDUCT.md
Awesome Lists containing this project
README
# GdatastoreMapper
[](https://circleci.com/gh/shinyaK14/gdatastore_mapper/tree/master) [](https://badge.fury.io/rb/gdatastore_mapper)
GdatastoreMapper is a mapper framework for Google Cloud Datastore in Ruby / Ruby on Rails.
Once you install GdatastoreMapper you can use Google Cloud Datastore like ActiveRecord.
## Table of Contents
- [Demo](#demo)
- [Requirements](#requirements)
- [Installation](#installation)
- [Configuration](#configuration)
- [Model Setting](#model-setting)
- [Persistence Methods](#persistence-methods)
- [Scoping Methods](#scoping-methods)
- [Timestamp](#timestamp)
- [Associations](#associations)
- [One to Many](#one-to-many)
- [Method Chaining](#method-chaining)
- [Callbacks](#callbacks)
- [Validations](#validations)
- [Contact](#contact)
- [Development](#development)
## Demo
Here is [demo](https://gdatastore-mapper.herokuapp.com/). The demo works with Google Cloud Datastore.
Source code is [here](https://github.com/shinyaK14/gdatastore_mapper/tree/master/rails_example).
## Requirements
GdatastoreMapper requires Rails version >= 5
## Installation
Execute rails new with --skip-active-record
```
$ rails new your_project --skip-active-record
```
Add this line to your application's Gemfile:
```ruby
gem 'gdatastore_mapper'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install gdatastore_mapper
## Configuration
GdatastoreMapper configuration can be done through a database.yml. The simplest configuration is as follows, which sets the emulator_host to "localhost:8444" and dataset_id.
```
# config/database.yml
production:
dataset_id: your-google-cloud-platform-project-id
staging:
dataset_id: your-google-cloud-platform-project-id
development:
dataset_id: your-google-cloud-platform-project-id
emulator_host: localhost:8444
test:
dataset_id: your-google-cloud-platform-project-id
emulator_host: localhost:8444
```
## Model Setting
Only 2 things you need to do.
1. To include GdatastoreMapper
2. To set attr_accessor as column
That's it! No need to db:migrate.
```ruby
class Book
include GdatastoreMapper::Base
attr_accessor :title, :author
end
```
## Persistence Methods
new record
```
book = Book.new
book.title = 'Harry Potter'
book.save
```
```
book = Book.new(title: 'Harry Potter')
book.save
```
```
Book.create(title: 'Harry Potter')
```
update
```
book.update(title: 'Harry Potter 2')
```
delete
```
book.delete
```
```
Book.delete_all
```
## Scoping Methods
```
Book.where(title: 'Harry Potter')
=> [#]
```
```
Book.find(12)
=> #
```
```
Book.find_by(title: 'Harry Potter')
=> # [# # # 100
```
```
Book.all
=> [# [# 2
```
```
harry_poter.author
=> [# [# [#