Class: RailsDb::SqlQueryData
- Inherits:
-
Object
- Object
- RailsDb::SqlQueryData
- Defined in:
- lib/rails_db/sql_query_data.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#rows ⇒ Object
readonly
Returns the value of attribute rows.
-
#sql_query ⇒ Object
readonly
Returns the value of attribute sql_query.
-
#time ⇒ Object
readonly
Returns the value of attribute time.
Instance Method Summary collapse
- #count ⇒ Object
-
#initialize(sql_query) ⇒ SqlQueryData
constructor
A new instance of SqlQueryData.
- #is_error? ⇒ Boolean
- #load_data ⇒ Object
- #sql ⇒ Object
Constructor Details
#initialize(sql_query) ⇒ SqlQueryData
Returns a new instance of SqlQueryData.
6 7 8 9 10 |
# File 'lib/rails_db/sql_query_data.rb', line 6 def initialize(sql_query) @rows = [] @columns = [] @sql_query = sql_query end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
4 5 6 |
# File 'lib/rails_db/sql_query_data.rb', line 4 def columns @columns end |
#error ⇒ Object (readonly)
Returns the value of attribute error.
4 5 6 |
# File 'lib/rails_db/sql_query_data.rb', line 4 def error @error end |
#rows ⇒ Object (readonly)
Returns the value of attribute rows.
4 5 6 |
# File 'lib/rails_db/sql_query_data.rb', line 4 def rows @rows end |
#sql_query ⇒ Object (readonly)
Returns the value of attribute sql_query.
4 5 6 |
# File 'lib/rails_db/sql_query_data.rb', line 4 def sql_query @sql_query end |
#time ⇒ Object (readonly)
Returns the value of attribute time.
4 5 6 |
# File 'lib/rails_db/sql_query_data.rb', line 4 def time @time end |
Instance Method Details
#count ⇒ Object
23 24 25 |
# File 'lib/rails_db/sql_query_data.rb', line 23 def count rows.count end |
#is_error? ⇒ Boolean
27 28 29 |
# File 'lib/rails_db/sql_query_data.rb', line 27 def is_error? error.present? end |
#load_data ⇒ Object
12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rails_db/sql_query_data.rb', line 12 def load_data result, @time = Database.adapter.exec_query(sql) @columns = result.columns @rows = result.rows self rescue ActiveRecord::StatementInvalid => e @columns, @rows = [], [] @error = e self end |
#sql ⇒ Object
31 32 33 |
# File 'lib/rails_db/sql_query_data.rb', line 31 def sql sql_query.query end |