blob: 15a27b22566b2e3092f5c420b7e209d9bbadb708 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
module Arel
class SqlLiteral < String
def relation
nil
end
def to_sql(formatter = nil)
self
end
include Attribute::Expressions
end
class Attribute
def column
original_relation.column_for(self)
end
def format(object)
object.to_sql(Sql::Attribute.new(self))
end
def to_sql(formatter = Sql::WhereCondition.new(relation))
formatter.attribute self
end
end
class Value
def inclusion_predicate_sql
value.inclusion_predicate_sql
end
def exclusion_predicate_sql
value.exclusion_predicate_sql
end
def equality_predicate_sql
value.equality_predicate_sql
end
def inequality_predicate_sql
value.inequality_predicate_sql
end
def to_sql(formatter = Sql::WhereCondition.new(relation))
formatter.value value
end
def format(object)
object.to_sql(Sql::Value.new(relation))
end
end
class Ordering
def to_sql(formatter = Sql::OrderClause.new(relation))
formatter.ordering self
end
end
class Ascending < Ordering
def direction_sql; 'ASC' end
end
class Descending < Ordering
def direction_sql; 'DESC' end
end
class Expression < Attribute
def to_sql(formatter = Sql::SelectClause.new(relation))
formatter.expression self
end
end
class Count < Expression
def function_sql; 'COUNT' end
end
class Distinct < Expression
def function_sql; 'DISTINCT' end
end
class Sum < Expression
def function_sql; 'SUM' end
end
class Maximum < Expression
def function_sql; 'MAX' end
end
class Minimum < Expression
def function_sql; 'MIN' end
end
class Average < Expression
def function_sql; 'AVG' end
end
end
|