SqlcachedClient
A Ruby client for Sqlcached.
Installation
Add this line to your application's Gemfile:
gem 'sqlcached_client'
And then execute:
$ bundle
Or install it yourself as:
$ gem install sqlcached_client
Usage
Create your models as you would do with ActiveRecord.
require 'sqlcached_client'
class Base < SqlcachedClient::Entity
# things shared amongst all models
server({ host: 'localhost', port: 8081 })
end
class User < Base
entity_name 'user'
query " SELECT * FROM users WHERE id IN ({{ ids }})\n SQL\n\n has_many :posts, where: { user_id: :id }\n\n has_many :pictures, class_name: 'Image',\n where: { imageable_id: :id, imageable_type: 'User' }\n\n has_one :address, where: { user_id: :id }\nend\n\n\nclass Post < Base\n entity_name 'post'\n\n query <<-SQL\n SELECT * FROM posts WHERE author_id = {{ user_id }}\n SQL\nend\n\n"
Run some queries:
users = User.where(ids: '1, 2, 3, 4')
users[0].pictures.each # you can navigate through the associations
Load in memory every associated set recursively:
users.build_associations # for each entity in the resultset, or...
users[0].build_associations # for a single entity
Contributing
- Fork it ( https://github.com/rmaestroni/sqlcached_client/fork )
- Create your feature branch (
git checkout -b my-new-feature) - Commit your changes (
git commit -am 'Add some feature') - Push to the branch (
git push origin my-new-feature) - Create a new Pull Request