https://github.com/lodestone/iseshima_store
Simple ruby ORM for Google Cloud Datastore.
https://github.com/lodestone/iseshima_store
Last synced: 2 months ago
JSON representation
Simple ruby ORM for Google Cloud Datastore.
- Host: GitHub
- URL: https://github.com/lodestone/iseshima_store
- Owner: lodestone
- License: mit
- Created: 2016-08-06T06:21:14.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2016-06-22T02:23:12.000Z (about 10 years ago)
- Last Synced: 2025-03-08T22:18:53.662Z (over 1 year ago)
- Language: Ruby
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- 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
# IseshimaStore :dolls:
Simple ruby ORM for Google Cloud Datastore.
## Installation
Add this line to your application's Gemfile:
```ruby
gem 'iseshima_store'
```
And then execute:
$ bundle
Or install it yourself as:
$ gem install iseshima_store
## Usage
### Setup
You need to set project_id.
```ruby
IseshimaStore::Connection.configure do |config|
config.project_id = 'xxxx'
end
```
Iseshima Store depends on `gcloud-ruby` which uses ENV variables, you can set your variables through ENV.
### Model
```ruby
class User
include IseshimaStore::Base
attr_properties :name, :email
end
```
The only thing you have to do is just 2 things.
1. include `IseshimaStore::Base` in your model class.
2. declare your properties with `attr_properties`
Any class is ok to use.
### Create
```ruby
user = User.new
user.email = 'taro@test.com'
user.name = 'taro'
user.save!
```
or
```ruby
User.new.assign_attributes(
email: 'taro@test.com',
name: 'taro'
).save!
```
### Save or Delete
```
# save
user = User.first
user.assign_attributes(email: 'taro@test.jp')
user.save!
# delete
user.destroy
```
IseshimaStore does not have validations.
Another gem like `ActiveModel` is recommended to combine.
### Finder
```ruby
users = User.where(email: 'test@test.com')
user = User.find_by(email: 'test@test.com')
user = User.find(12345) # id
# You can chain queries.
user = User.where(visible: true).find(10)
```
### Relation
```ruby
diary = Diary.new
diary.title = 'My nightmare'
diary.parent = user
diary.save!
```
`parent=(model)` sets model's key to the key's parent of instance.
### Low level search
```ruby
query = Gcloud::Datastore::Query.new
query.kind('User')
query.where('email', '=', 'test@test.com')
res = User.search(query: query)
users = res[:records]
```
If you need `limit` & `cursor`, use this API.
## License
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).