All Projects → yuemori → activerecord-shard_for

yuemori / activerecord-shard_for

Licence: MIT license
Database Sharding Library for ActiveRecord

Programming Languages

ruby
36898 projects - #4 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to activerecord-shard for

rails-countries
Integration between Rails and countries gem.
Stars: ✭ 17 (+6.25%)
Mutual labels:  activerecord, gem
Mixed gauge
A simple and robust database sharding with ActiveRecord.
Stars: ✭ 58 (+262.5%)
Mutual labels:  activerecord, sharding
filtered
Filters ActiveRecord queries in a nice way
Stars: ✭ 28 (+75%)
Mutual labels:  activerecord, gem
rails cursor pagination
Add cursor pagination to your ActiveRecord backed application
Stars: ✭ 21 (+31.25%)
Mutual labels:  activerecord, gem
Activerecord Turntable
ActiveRecord Sharding Plugin
Stars: ✭ 206 (+1187.5%)
Mutual labels:  activerecord, sharding
Algoliasearch Rails
AlgoliaSearch integration to your favorite ORM
Stars: ✭ 352 (+2100%)
Mutual labels:  activerecord, gem
Datagrid
Gem to create tables grids with sortable columns and filters
Stars: ✭ 921 (+5656.25%)
Mutual labels:  activerecord, gem
Active reporting
OLAP-like DSL for ActiveRecord-based reporting
Stars: ✭ 83 (+418.75%)
Mutual labels:  activerecord, gem
Counter culture
Turbo-charged counter caches for your Rails app.
Stars: ✭ 1,397 (+8631.25%)
Mutual labels:  activerecord, gem
Graphql devise
GraphQL interface on top devise_token_auth
Stars: ✭ 100 (+525%)
Mutual labels:  activerecord, gem
active record-updated at
Touch `updated_at` by default with calls to `update_all` and `update_column(s)`
Stars: ✭ 27 (+68.75%)
Mutual labels:  activerecord, gem
Octopus
Database Sharding for ActiveRecord
Stars: ✭ 2,496 (+15500%)
Mutual labels:  activerecord, sharding
index shotgun
duplicate index checker 🔥 🔫 👮
Stars: ✭ 35 (+118.75%)
Mutual labels:  activerecord, gem
sinator
Sinatra application generator
Stars: ✭ 19 (+18.75%)
Mutual labels:  gem
siphon
Siphon enables you to easily combine your scopes with params
Stars: ✭ 23 (+43.75%)
Mutual labels:  activerecord
multi-tenancy-devise
mtdevise adds basecamp style user logins to your ruby on rails application.
Stars: ✭ 27 (+68.75%)
Mutual labels:  gem
bundle outdated formatter
Formatter for `bundle outdated` command
Stars: ✭ 16 (+0%)
Mutual labels:  gem
active record distinct on
Support for `DISTINCT ON` statements when querying with ActiveRecord
Stars: ✭ 23 (+43.75%)
Mutual labels:  activerecord
activeentity
Active Record without Database
Stars: ✭ 46 (+187.5%)
Mutual labels:  activerecord
my-demo
Demo Application for Dubbo, Mycat, Sharding-Proxy, Seata, SkyWalking, PinPoint, ZipKin, Docker, Kubernetes, Istio, Postman/Newman, FitNesse
Stars: ✭ 37 (+131.25%)
Mutual labels:  database-sharding

ActiveRecord::ShardFor

Build Status Dependency Status Code Climate Test Coverage

This is Sharding Library for ActiveRecord, inspire and import codes from mixed_gauge and activerecord-sharding (Thanks!).

Concept

activerecord-shard_for have 3 concepts.

  • simple
  • small
  • pluggable

Installation

Add this line to your application's Gemfile:

gem 'activerecord-shard_for'

And then execute:

$ bundle

Or install it yourself as:

$ gem install activerecord-shard_for

Getting Started

Add additional database connection config to database.yml.

# database.yml
production_user_001:
  adapter: mysql2
  username: user_writable
  host: db-user-001
production_user_002:
  adapter: mysql2
  username: user_writable
  host: db-user-002
production_user_003:
  adapter: mysql2
  username: user_writable
  host: db-user-003
production_user_004:
  adapter: mysql2
  username: user_writable
  host: db-user-004

Define cluster in initializers (e.g initializers/active_record_shard_for.rb)

ActiveRecord::ShardFor.configure do |config|
  config.define_cluster(:user) do |cluster|
    # unique identifier, connection name
    cluster.register(0, :production_user_001)
    cluster.register(1, :production_user_002)
    cluster.register(2, :production_user_003)
    cluster.register(3, :production_user_004)
  end
end

Include ActiveRecord::ShardFor::Model to your model class, specify cluster name and router name for the model, specify distkey which determines node to store.

class User < ActiveRecord::Base
  include ActiveRecord::ShardFor::Model
  use_cluster :user, :hash_modulo # hash_modulo is presented by this library.
  def_distkey :email
end

Use .get to retrieve single record which is connected to proper database node. Use .put! to create new record to proper database node.

.all_shards returns each model class which is connected to proper database node. You can query with these models and aggregate result.

User.put!(email: '[email protected]', name: 'alice')

alice = User.get('[email protected]')
alice.age = 1
alice.save!

User.all_shards.flat_map {|m| m.find_by(name: 'alice') }.compact

Wiki

More imformation and example to see wiki!

Contributing with ActiveRecord::ShardFor

Contributors are welcome! This is what you need to setup your Octopus development environment:

$ git clone https://github.com/yuemori/activerecord-shard_for
$ cd activerecord-shard_for
$ bundle install
$ bundle exec rake appraisal:install
$ bundle exec rake spec

License

The gem is available as open source under the terms of the MIT License.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].