class JunglePath::DBAccess::IO::Select
Public Instance Methods
_model(model)
click to toggle source
# File lib/jungle_path/db_access/io/select.rb, line 9 def _model(model) # select based on a model's primary key. ds = @db[model._table_name].where(model._primary_key) #puts ds.sql hash = ds.first return nil unless hash new_model = model.class.new(hash, false) # false since row (initial values) from db is considered unmodified. end
_model_by_any(model)
click to toggle source
# File lib/jungle_path/db_access/io/select.rb, line 18 def _model_by_any(model) ds = @db[model._table_name].where(handle_json_columns(model, model._modified_hash)) #puts ds.sql hash = ds.first #puts "hash: #{hash}. Nil? #{hash == nil}." return nil unless hash new_model = model.class.new(hash, false) # false since row (initial values) from db is considered unmodified. end
_models(model, *order_by)
click to toggle source
# File lib/jungle_path/db_access/io/select.rb, line 27 def _models(model, *order_by) # select all of a given model. ds = @db[model._table_name] ds = ds.where(handle_json_columns(model, model._has_value_hash)) if model._has_value_hash.length > 0 ds = ds.order(*order_by) if order_by.length > 0 ds = ds.order(model._primary_key_columns.keys) unless order_by.length > 0 #puts ds.sql rows = ds.all models = [] rows.each do |row| models << model.class.new(row, false) end models end