https://github.com/lodestone/iseshima_store
Simple ruby ORM for Google Cloud Datastore.
https://github.com/lodestone/iseshima_store
Last synced: 3 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 9 years ago)
- Default Branch: master
- Last Pushed: 2016-06-22T02:23:12.000Z (almost 9 years ago)
- Last Synced: 2025-01-12T11:49:25.559Z (4 months ago)
- Language: Ruby
- Size: 13.7 KB
- Stars: 0
- Watchers: 2
- 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 = '[email protected]'
user.name = 'taro'
user.save!
```or
```ruby
User.new.assign_attributes(
email: '[email protected]',
name: 'taro'
).save!
```### Save or Delete
```
# save
user = User.first
user.assign_attributes(email: '[email protected]')
user.save!# delete
user.destroy
```IseshimaStore does not have validations.
Another gem like `ActiveModel` is recommended to combine.### Finder
```ruby
users = User.where(email: '[email protected]')
user = User.find_by(email: '[email protected]')
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', '=', '[email protected]')
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).