Module: Lims::Core::Persistence::Sequel::Persistor
- Includes:
- Filters
- Defined in:
- lib/lims-core/persistence/sequel/persistor.rb
Overview
Mixin giving extended the persistor classes with the Sequel (load/save) behavior.
Constant Summary
Constants included from Filters
Filters::COMPARISON_OPERATORS, Filters::LIKE_OPERATOR
Class Method Summary collapse
Instance Method Summary collapse
- #bulk_insert(states, *params) ⇒ Object
- #bulk_load(ids, *params, &block) ⇒ Object
-
#count ⇒ Fixnum
Returns the number of object in the store.
-
#dataset ⇒ ::Sequel::Dataset
The Sequel::Dataset.
- #initialize(session_or_persistor, dataset = nil, *args, &block) ⇒ Object
-
#table_name ⇒ String
The name of the table.
Methods included from Filters
#add_comparison_filter, #comparison_filter, #multi_criteria_filter
Class Method Details
.included(klass) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lims-core/persistence/sequel/persistor.rb', line 16 def self.included(klass) klass.class_eval do # @return [String] the name of SQL table. def self.table_name @table_name ||= parent_scope.name.split('::').last.pluralize.snakecase.to_sym end # The Sequel::Dataset. # Corresponds to table. # @param [Sequel::Session] session # @return [::Sequel::Dataset] def self.dataset(session) session.database[self.table_name] end end end |
Instance Method Details
#bulk_insert(states, *params) ⇒ Object
115 116 117 118 119 |
# File 'lib/lims-core/persistence/sequel/persistor.rb', line 115 def bulk_insert(states, *params) #super(states, *params) bulk_insert_multi(states, *params) #bulk_insert_prepared(states, *params) end |
#bulk_load(ids, *params, &block) ⇒ Object
91 92 93 |
# File 'lib/lims-core/persistence/sequel/persistor.rb', line 91 def bulk_load(ids, *params, &block) dataset.filter(qualified_key => ids.map(&:id)).all(&block) end |
#count ⇒ Fixnum
Returns the number of object in the store
68 69 70 |
# File 'lib/lims-core/persistence/sequel/persistor.rb', line 68 def count dataset.count end |
#dataset ⇒ ::Sequel::Dataset
The Sequel::Dataset. Corresponds to a table.
61 62 63 |
# File 'lib/lims-core/persistence/sequel/persistor.rb', line 61 def dataset @dataset end |
#initialize(session_or_persistor, dataset = nil, *args, &block) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lims-core/persistence/sequel/persistor.rb', line 32 def initialize(session_or_persistor, dataset=nil, *args, &block ) id_to_state, object_to_state = [nil, nil] case session_or_persistor when Sequel::Persistor # We link the session and the identity map variables, # so that object loaded via this persistor can be found (and their id) # through the origial persistor. # Hack to get those private variables. session, identity_map_parameters = session_or_persistor.instance_eval do [@session, [@id_to_state, @object_to_state]] end super(session, *args, &block) @id_to_state , @object_to_state = identity_map_parameters else Session super(session_or_persistor, *args, &block) end @dataset = dataset || self.class.dataset(@session) end |
#table_name ⇒ String
Returns the name of the table.
53 54 55 |
# File 'lib/lims-core/persistence/sequel/persistor.rb', line 53 def table_name self.class.table_name end |