module Sequel::SchemaSharding

Constants

VERSION

Public Class Methods

Model(source) click to toggle source

Extensions to the Sequel model to allow logical/physical shards. Actual table models should inherit this class like so:

class Cat < Sequel::SchemaSharding::Model

set_columns [:cat_id, :fur, :tongue, :whiskers] # Columns in the database need to be predefined.
set_sharded_column :cat_id # Define the shard column

def self.by_cat_id(id)
  # You should always call shard_for in finders to select the correct connection.
  shard_for(id).where(cat_id: id)
end

end

# File lib/sequel/schema-sharding/model.rb, line 18
def self.Model(source)
  klass = Sequel::Model(Sequel::SchemaSharding.connection_manager.default_dataset_for(source))

  klass.include(SchemaSharding::ShardedModel)
  klass.send(:simple_table=, false)

  klass
end
config() click to toggle source
# File lib/sequel/schema-sharding.rb, line 17
def self.config
  @config ||= Sequel::SchemaSharding::Configuration.new(ENV['RACK_ENV'], sharding_yml_path)
end
config=(config) click to toggle source
# File lib/sequel/schema-sharding.rb, line 21
def self.config=(config)
  @config = config
end
connection_manager() click to toggle source
# File lib/sequel/schema-sharding.rb, line 41
def self.connection_manager
  @connection_manager ||= ConnectionManager.new
end
connection_manager=(connection_manager) click to toggle source
# File lib/sequel/schema-sharding.rb, line 45
def self.connection_manager=(connection_manager)
  @connection_manager = connection_manager
end
logger() click to toggle source
# File lib/sequel/schema-sharding.rb, line 33
def self.logger
  @logger ||= Logger.new(nil)
end
logger=(logger) click to toggle source
# File lib/sequel/schema-sharding.rb, line 37
def self.logger=(logger)
  @logger = logger
end
migration_path() click to toggle source
# File lib/sequel/schema-sharding.rb, line 57
def self.migration_path
  @migration_path || raise('You must set the migration path.')
end
migration_path=(path) click to toggle source
# File lib/sequel/schema-sharding.rb, line 61
def self.migration_path=(path)
  @migration_path = path
end
replica_strategy() click to toggle source
# File lib/sequel/schema-sharding.rb, line 25
def self.replica_strategy
  @replica_strategy ||= Sequel::SchemaSharding::ConnectionStrategy::Random
end
replica_strategy=(strategy) click to toggle source
# File lib/sequel/schema-sharding.rb, line 29
def self.replica_strategy=(strategy)
  @replica_strategy = strategy
end
sharding_yml_path() click to toggle source
# File lib/sequel/schema-sharding.rb, line 49
def self.sharding_yml_path
  @sharding_yml_path ||= File.expand_path('../../../config/sharding.yml', __FILE__)
end
sharding_yml_path=(path) click to toggle source
# File lib/sequel/schema-sharding.rb, line 53
def self.sharding_yml_path=(path)
  @sharding_yml_path = path
end