Class: Influxdb::Arel::SelectManager
Constant Summary
collapse
- DIRECTIONS =
[:asc, :desc].freeze
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
#initialize_copy, #to_sql, #visitor, #where, #where!, #where_values, #where_values=
Constructor Details
#initialize(*tables, &block) ⇒ SelectManager
Returns a new instance of SelectManager.
6
7
8
9
10
|
# File 'lib/influxdb/arel/select_manager.rb', line 6
def initialize(*tables, &block)
super()
@ast = Nodes::SelectStatement.new
from(*tables, &block)
end
|
Instance Method Details
104
105
106
107
|
# File 'lib/influxdb/arel/select_manager.rb', line 104
def asc
ast.order = Nodes::Ordering.new('asc')
self
end
|
136
137
138
139
140
141
142
143
|
# File 'lib/influxdb/arel/select_manager.rb', line 136
def delete
raise 'IllegalSQLConstruct: Ambiguous deletion operation' if ast.tables.size != 1
DeleteManager.new.tap do |manager|
manager.tables = ast.tables
manager.regexp = ast.regexp
manager.where_values = where_values
end
end
|
99
100
101
102
|
# File 'lib/influxdb/arel/select_manager.rb', line 99
def desc
ast.order = Nodes::Ordering.new('desc')
self
end
|
#fill(value) ⇒ Object
40
41
42
43
|
# File 'lib/influxdb/arel/select_manager.rb', line 40
def fill(value)
ast.fill = Nodes::Fill.new(value)
self
end
|
#fill_value ⇒ Object
45
46
47
|
# File 'lib/influxdb/arel/select_manager.rb', line 45
def fill_value
ast.fill
end
|
#from(*new_tables, &block) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
# File 'lib/influxdb/arel/select_manager.rb', line 49
def from(*new_tables, &block)
new_tables = new_tables.compact
return self if new_tables.empty? && !block_given?
expr = Clauses::FromClause.new(*new_tables, &block).to_arel
case expr
when Array
regexps, merges, joins, others = separate_tables(expr.to_a)
ast.regexp = Nodes::Table.new(regexps.first) if regexps
ast.join = joins.first if joins
ast.merge = merges.first if merges
ast.tables = others if others
when Nodes::Join
ast.join = expr
when Nodes::Merge
ast.merge = expr
when Regexp
ast.regexp = expr
else
ast.tables = Array(expr)
end
self
end
|
#group(*attributes, &block) ⇒ Object
12
13
14
15
|
# File 'lib/influxdb/arel/select_manager.rb', line 12
def group(*attributes, &block)
ast.groups |= Clauses::GroupClause.new(*attributes, &block).to_arel
self
end
|
#group!(*attributes, &block) ⇒ Object
17
18
19
20
|
# File 'lib/influxdb/arel/select_manager.rb', line 17
def group!(*attributes, &block)
ast.groups = process_value_with_bang(Clauses::GroupClause, attributes, &block)
self
end
|
#group_values ⇒ Object
22
23
24
|
# File 'lib/influxdb/arel/select_manager.rb', line 22
def group_values
ast.groups
end
|
#into(table) ⇒ Object
127
128
129
130
|
# File 'lib/influxdb/arel/select_manager.rb', line 127
def into(table)
ast.into = Nodes::Into.new(Arel.arelize(table))
self
end
|
#into_value ⇒ Object
132
133
134
|
# File 'lib/influxdb/arel/select_manager.rb', line 132
def into_value
ast.into
end
|
#invert_order ⇒ Object
109
110
111
112
|
# File 'lib/influxdb/arel/select_manager.rb', line 109
def invert_order
ast.order = (ast.order && ast.order.invert) || Nodes::Ordering.new('asc')
self
end
|
#join(*joining_tables) ⇒ Object
79
80
81
82
|
# File 'lib/influxdb/arel/select_manager.rb', line 79
def join(*joining_tables)
ast.join = process_value_for_tables_union(Nodes::Join, joining_tables, :joining)
self
end
|
#limit(limit) ⇒ Object
118
119
120
121
|
# File 'lib/influxdb/arel/select_manager.rb', line 118
def limit(limit)
ast.limit = limit ? Nodes::Limit.new(limit) : nil
self
end
|
#limit_value ⇒ Object
123
124
125
|
# File 'lib/influxdb/arel/select_manager.rb', line 123
def limit_value
ast.limit
end
|
#merge(*merging_tables) ⇒ Object
84
85
86
87
|
# File 'lib/influxdb/arel/select_manager.rb', line 84
def merge(*merging_tables)
ast.merge = process_value_for_tables_union(Nodes::Merge, merging_tables, :merging)
self
end
|
#order(expr) ⇒ Object
89
90
91
92
93
94
95
96
97
|
# File 'lib/influxdb/arel/select_manager.rb', line 89
def order(expr)
case
when Nodes::Ordering === expr
ast.order = expr
when DIRECTIONS.include?(expr.to_sym)
send(expr)
end
self
end
|
#order_value ⇒ Object
114
115
116
|
# File 'lib/influxdb/arel/select_manager.rb', line 114
def order_value
ast.order
end
|
#select(*attributes, &block) ⇒ Object
26
27
28
29
|
# File 'lib/influxdb/arel/select_manager.rb', line 26
def select(*attributes, &block)
ast.attributes |= Clauses::SelectClause.new(*attributes, &block).to_arel
self
end
|
#select!(*attributes, &block) ⇒ Object
31
32
33
34
|
# File 'lib/influxdb/arel/select_manager.rb', line 31
def select!(*attributes, &block)
ast.attributes = process_value_with_bang(Clauses::SelectClause, attributes, &block)
self
end
|
#select_values ⇒ Object
36
37
38
|
# File 'lib/influxdb/arel/select_manager.rb', line 36
def select_values
ast.attributes
end
|
75
76
77
|
# File 'lib/influxdb/arel/select_manager.rb', line 75
def tables
[ast.regexp] || ast.tables
end
|