/
Library.scala
100 lines (83 loc) · 3.29 KB
/
Library.scala
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
98
99
100
package scala.slick.ast
/**
* The standard library for query operators.
*/
object Library {
trait AggregateFunctionSymbol extends Symbol
class JdbcFunction(name: String) extends FunctionSymbol(name)
class SqlFunction(name: String) extends FunctionSymbol(name)
class SqlOperator(name: String) extends FunctionSymbol(name)
class AggregateFunction(name: String) extends FunctionSymbol(name) with AggregateFunctionSymbol
class SqlAggregateFunction(name: String) extends SqlFunction(name) with AggregateFunctionSymbol
// Boolean operators
val And = new SqlOperator("and")
val Or = new SqlOperator("or")
val Not = new SqlOperator("not")
// Numeric operators and functions
val + = new SqlOperator("+")
val - = new SqlOperator("-")
val * = new SqlOperator("*")
val / = new SqlOperator("/")
val % = new JdbcFunction("mod")
val Between = new FunctionSymbol("between")
val Abs = new JdbcFunction("abs")
val Ceiling = new JdbcFunction("ceiling")
val Floor = new JdbcFunction("floor")
val Sign = new JdbcFunction("sign")
val Degrees = new JdbcFunction("degrees")
val Radians = new JdbcFunction("radians")
// Comparison
val < = new SqlOperator("<")
val <= = new SqlOperator("<=")
val > = new SqlOperator(">")
val >= = new SqlOperator(">=")
val == = new SqlOperator("=")
// Set membership
val In = new SqlOperator("in")
// String functions
val Length = new JdbcFunction("length")
val Concat = new JdbcFunction("concat")
val UCase = new JdbcFunction("ucase")
val LCase = new JdbcFunction("lcase")
val LTrim = new JdbcFunction("ltrim")
val RTrim = new JdbcFunction("rtrim")
val Trim = new FunctionSymbol("Trim")
val Like = new FunctionSymbol("Like")
val StartsWith = new FunctionSymbol("StartsWith")
val EndsWith = new FunctionSymbol("EndsWith")
// Aggregate functions
val Min = new SqlAggregateFunction("min")
val Max = new SqlAggregateFunction("max")
val Avg = new SqlAggregateFunction("avg")
val Sum = new SqlAggregateFunction("sum")
val Count = new SqlAggregateFunction("count")
val CountAll = new AggregateFunction("count(*)")
val CountDistinct = new AggregateFunction("count distinct")
val Exists = new SqlFunction("exists")
val Cast = new FunctionSymbol("Cast")
val IfNull = new JdbcFunction("ifnull")
// Values
val User = new JdbcFunction("user")
val Database = new JdbcFunction("database")
val CurrentDate = new JdbcFunction("curdate")
val CurrentTime = new JdbcFunction("curtime")
val Pi = new JdbcFunction("pi")
// Sequence operations
val NextValue = new FunctionSymbol("NextValue")
val CurrentValue = new FunctionSymbol("CurrentValue")
}
/** A Symbol that represents a library function or operator */
class FunctionSymbol(val name: String) extends Symbol {
/** Create an untyped Apply of this Symbol */
//def apply(ch: Node*): Apply = Apply(this, ch)
/** Match an Apply of this Symbol */
def unapplySeq(n: Node) = n match {
case Apply(sym, ch) if sym eq this => Some(ch)
case _ => None
}
/** Create a typed Apply of this Symbol */
def typed(tpe: Type, ch: Node*): Apply with TypedNode = Apply(this, ch)(tpe)
/** Create a typed Apply of this Symbol */
def typed[T : ScalaBaseType](ch: Node*): Apply with TypedNode = Apply(this, ch)(implicitly[ScalaBaseType[T]])
override def toString = "Function "+name
}