Class: RailsDb::SqlQueryData

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_db/sql_query_data.rb

Direct Known Subclasses

SqlExplain

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#columnsObject (readonly)

Returns the value of attribute columns.



4
5
6
# File 'lib/rails_db/sql_query_data.rb', line 4

def columns
  @columns
end

#errorObject (readonly)

Returns the value of attribute error.



4
5
6
# File 'lib/rails_db/sql_query_data.rb', line 4

def error
  @error
end

#rowsObject (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_queryObject (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

#timeObject (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

#countObject



23
24
25
# File 'lib/rails_db/sql_query_data.rb', line 23

def count
  rows.count
end

#is_error?Boolean

Returns:

  • (Boolean)


27
28
29
# File 'lib/rails_db/sql_query_data.rb', line 27

def is_error?
  error.present?
end

#load_dataObject



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

#sqlObject



31
32
33
# File 'lib/rails_db/sql_query_data.rb', line 31

def sql
  sql_query.query
end