module Diary::ModelQuery::ClassMethods
Public Instance Methods
column_names()
click to toggle source
# File lib/diary-ruby/model.rb, line 17 def column_names @column_names ||= columns.map {|col_info| col_info[1]} end
columns()
click to toggle source
# File lib/diary-ruby/model.rb, line 13 def columns @columns ||= connection.execute("PRAGMA table_info(#{table_name})") end
find(attrs)
click to toggle source
# File lib/diary-ruby/model.rb, line 37 def find(attrs) where(attrs).first end
materialize(array_of_rows)
click to toggle source
# File lib/diary-ruby/model.rb, line 27 def materialize(array_of_rows) results_to_hashes(array_of_rows).map do |record_hash| if respond_to?(:from_hash) from_hash(record_hash) else record_hash end end end
new_select_relation()
click to toggle source
# File lib/diary-ruby/model.rb, line 41 def new_select_relation Diary::Query::Select.new(table_name, self) end
results_to_hashes(array_of_rows)
click to toggle source
# File lib/diary-ruby/model.rb, line 21 def results_to_hashes(array_of_rows) array_of_rows.map do |row| Hash[ column_names.zip(row) ] end end