Module: Sequel::SchemaSharding::ShardedModel::ClassMethods
- Defined in:
- lib/sequel/schema-sharding/model.rb
Instance Method Summary collapse
-
#result_for(id) ⇒ Object
The result of a lookup for the given id.
-
#schema_and_table(result) ⇒ Object
Construct the schema and table for use in a dataset.
-
#set_sharded_column(column) ⇒ Object
Set the column on which the current model is sharded.
-
#shard_for(id) ⇒ Object
Return a valid Sequel::Dataset that is tied to the shard table and connection for the id and will load values run by the query into the model.
-
#sharded_column ⇒ Object
Accessor for the sharded_columns.
Instance Method Details
#result_for(id) ⇒ Object
The result of a lookup for the given id. See Sequel::SchemaSharding::Finder::Result
60 61 62 |
# File 'lib/sequel/schema-sharding/model.rb', line 60 def result_for(id) Sequel::SchemaSharding::Finder.instance.lookup(self.implicit_table_name, id) end |
#schema_and_table(result) ⇒ Object
Construct the schema and table for use in a dataset.
65 66 67 |
# File 'lib/sequel/schema-sharding/model.rb', line 65 def schema_and_table(result) :"#{result.schema}__#{self.implicit_table_name}" end |
#set_sharded_column(column) ⇒ Object
Set the column on which the current model is sharded. This is used when saving, inserting and finding to decide which connection to use.
39 40 41 |
# File 'lib/sequel/schema-sharding/model.rb', line 39 def set_sharded_column(column) @sharded_column = column end |
#shard_for(id) ⇒ Object
Return a valid Sequel::Dataset that is tied to the shard table and connection for the id and will load values run by the query into the model.
50 51 52 53 54 55 56 57 |
# File 'lib/sequel/schema-sharding/model.rb', line 50 def shard_for(id) result = self.result_for(id) ds = result.connection[schema_and_table(result)] ds.row_proc = self dataset_method_modules.each { |m| ds.instance_eval { extend(m) } } ds.model = self ds end |
#sharded_column ⇒ Object
Accessor for the sharded_columns
44 45 46 |
# File 'lib/sequel/schema-sharding/model.rb', line 44 def sharded_column @sharded_column end |