class RailsDb::TableData
Attributes
Public Class Methods
Source
# File lib/rails_db/table_data.rb, line 12 def initialize(table) @table = table end
Public Instance Methods
Source
# File lib/rails_db/table_data.rb, line 65 def columns if select_columns && select_columns.any? select_columns else table.column_names end end
Source
# File lib/rails_db/table_data.rb, line 16 def data @data ||= begin commands = [] if select_columns && select_columns.any? commands.push("SELECT #{select_columns.join(', ')} FROM #{table.name}") else commands.push("SELECT * FROM #{table.name}") end if sort_column commands.push("ORDER BY #{sort_column} #{sort_order}") end if per_page commands.push("LIMIT #{per_page.to_i} OFFSET #{offset.to_i}") end results, @time = Database.select(commands.join(' ')) results end end
Source
# File lib/rails_db/table_data.rb, line 40 def desc self.sort_order = 'desc' self end
Source
# File lib/rails_db/table_data.rb, line 35 def limit(limit) self.per_page = limit self end
Source
# File lib/rails_db/table_data.rb, line 55 def order(sort_order) self.send(sort_order) if [:asc, :desc].include?(sort_order.to_sym) self end
Source
# File lib/rails_db/table_data.rb, line 50 def order_by(column) self.sort_column = column self end
Source
# File lib/rails_db/table_data.rb, line 60 def select(*select_columns) self.select_columns = Array.wrap(select_columns).flatten self end