Class: RailsDb::TableData
- Inherits:
-
Object
- Object
- RailsDb::TableData
- Includes:
- Connection, TablePagination
- Defined in:
- lib/rails_db/table_data.rb
Instance Attribute Summary collapse
-
#current_page ⇒ Object
Returns the value of attribute current_page.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#per_page ⇒ Object
Returns the value of attribute per_page.
-
#sort_column ⇒ Object
Returns the value of attribute sort_column.
-
#sort_order ⇒ Object
Returns the value of attribute sort_order.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #count ⇒ Object
- #data ⇒ Object
-
#initialize(table) ⇒ TableData
constructor
A new instance of TableData.
Methods included from TablePagination
#next_page, #paginate, #previous_page, #total_entries, #total_pages
Methods included from Connection
Constructor Details
#initialize(table) ⇒ TableData
Returns a new instance of TableData.
12 13 14 |
# File 'lib/rails_db/table_data.rb', line 12 def initialize(table) @table = table end |
Instance Attribute Details
#current_page ⇒ Object
Returns the value of attribute current_page.
7 8 9 |
# File 'lib/rails_db/table_data.rb', line 7 def current_page @current_page end |
#offset ⇒ Object
Returns the value of attribute offset.
7 8 9 |
# File 'lib/rails_db/table_data.rb', line 7 def offset @offset end |
#per_page ⇒ Object
Returns the value of attribute per_page.
7 8 9 |
# File 'lib/rails_db/table_data.rb', line 7 def per_page @per_page end |
#sort_column ⇒ Object
Returns the value of attribute sort_column.
7 8 9 |
# File 'lib/rails_db/table_data.rb', line 7 def sort_column @sort_column end |
#sort_order ⇒ Object
Returns the value of attribute sort_order.
7 8 9 |
# File 'lib/rails_db/table_data.rb', line 7 def sort_order @sort_order end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
6 7 8 |
# File 'lib/rails_db/table_data.rb', line 6 def table @table end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
6 7 8 |
# File 'lib/rails_db/table_data.rb', line 6 def time @time end |
Instance Method Details
#count ⇒ Object
30 31 32 |
# File 'lib/rails_db/table_data.rb', line 30 def count Database.adapter.exec_query("SELECT COUNT(*) FROM #{table.name}")[0].rows.flatten.last.to_i end |
#data ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/rails_db/table_data.rb', line 16 def data @data ||= begin commands = ["SELECT * FROM #{table.name}"] if sort_column commands.push("ORDER BY #{sort_column} #{sort_order}") end if per_page && offset commands.push("LIMIT #{per_page} OFFSET #{offset}") end results, @time = Database.adapter.exec_query(commands.join(' ')) results end end |