Class: Influxdb::Arel::SelectManager

Inherits:
TreeManager show all
Defined in:
lib/influxdb/arel/select_manager.rb

Constant Summary

Constants inherited from TreeManager

TreeManager::STRING_OR_SYMBOL_CLASS

Instance Attribute Summary

Attributes inherited from TreeManager

#ast

Instance Method Summary collapse

Methods inherited from TreeManager

#to_sql, #visitor, #where

Constructor Details

#initialize(*tables) ⇒ SelectManager

Returns a new instance of SelectManager.



4
5
6
7
8
# File 'lib/influxdb/arel/select_manager.rb', line 4

def initialize(*tables)
  super()
  @ast = Nodes::SelectStatement.new
  from(*tables)
end

Instance Method Details

#ascObject



102
103
104
105
# File 'lib/influxdb/arel/select_manager.rb', line 102

def asc
  ast.order = Nodes::Ordering.new('asc')
  self
end

#column(*columns) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/influxdb/arel/select_manager.rb', line 74

def column(*columns)
  columns.each do |column|
    column = STRING_OR_SYMBOL_CLASS.include?(column.class) ? Arel.sql(column.to_s) : column
    ast.columns.push(column)
  end

  self
end

#columnsObject



83
84
85
# File 'lib/influxdb/arel/select_manager.rb', line 83

def columns
  ast.columns
end

#columns=(columns) ⇒ Object



87
88
89
# File 'lib/influxdb/arel/select_manager.rb', line 87

def columns=(columns)
  self.column(*columns)
end

#descObject



97
98
99
100
# File 'lib/influxdb/arel/select_manager.rb', line 97

def desc
  ast.order = Nodes::Ordering.new('desc')
  self
end

#fill(value) ⇒ Object



33
34
35
36
# File 'lib/influxdb/arel/select_manager.rb', line 33

def fill(value)
  ast.fill = Nodes::Fill.new(value)
  self
end

#from(*series) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/influxdb/arel/select_manager.rb', line 38

def from(*series)
  series = series.map do |table|
    case table
    when String, Symbol
      Arel.sql(table.to_s)
    when Regexp
      Arel.sql(table.inspect)
    else
      table
    end
  end.compact

  ast.series = series unless series.empty?
  self
end

#group(*columns) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/influxdb/arel/select_manager.rb', line 24

def group(*columns)
  columns.each do |column|
    column = STRING_OR_SYMBOL_CLASS.include?(column.class) ? Arel.sql(column.to_s) : column
    ast.groups.push(Nodes::Group.new(column))
  end

  self
end

#initialize_copy(other) ⇒ Object



10
11
12
# File 'lib/influxdb/arel/select_manager.rb', line 10

def initialize_copy(other)
  super
end

#into(table) ⇒ Object



118
119
120
121
122
# File 'lib/influxdb/arel/select_manager.rb', line 118

def into(table)
  table = STRING_OR_SYMBOL_CLASS.include?(table.class) ? Arel.sql(table.to_s) : table
  ast.into = Nodes::Into.new(table)
  self
end

#join(table = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
# File 'lib/influxdb/arel/select_manager.rb', line 54

def join(table = nil)
  if table && !series.empty?
    table = STRING_OR_SYMBOL_CLASS.include?(table.class) ? Arel.sql(table.to_s) : table
    ast.join = Nodes::Join.new(series[0], table)
  elsif series.size > 1
    ast.join = Nodes::Join.new(series[0], series[1])
  end
  self
end

#limitObject Also known as: taken



14
15
16
# File 'lib/influxdb/arel/select_manager.rb', line 14

def limit
  ast.limit
end

#merge(table = nil) ⇒ Object



64
65
66
67
68
69
70
71
72
# File 'lib/influxdb/arel/select_manager.rb', line 64

def merge(table = nil)
  if table && !series.empty?
    table = STRING_OR_SYMBOL_CLASS.include?(table.class) ? Arel.sql(table.to_s) : table
    ast.merge = Nodes::Merge.new(series[0].unalias, table.unalias)
  elsif series.size > 1
    ast.merge = Nodes::Merge.new(series[0].unalias, series[1].unalias)
  end
  self
end

#order(expr) ⇒ Object



91
92
93
94
95
# File 'lib/influxdb/arel/select_manager.rb', line 91

def order(expr)
  expr = STRING_OR_SYMBOL_CLASS.include?(expr.class) ? Nodes::Ordering.new(expr.to_s) : expr
  ast.order = expr
  self
end

#orderingObject



107
108
109
# File 'lib/influxdb/arel/select_manager.rb', line 107

def ordering
  ast.order
end

#seriesObject



124
125
126
# File 'lib/influxdb/arel/select_manager.rb', line 124

def series
  ast.series
end

#take(limit) ⇒ Object Also known as: limit=



111
112
113
114
# File 'lib/influxdb/arel/select_manager.rb', line 111

def take(limit)
  ast.limit = limit ? Nodes::Limit.new(limit) : nil
  self
end

#wheresObject



20
21
22
# File 'lib/influxdb/arel/select_manager.rb', line 20

def wheres
  ast.wheres
end