-
Notifications
You must be signed in to change notification settings - Fork 1
/
selector.go
54 lines (42 loc) · 1.41 KB
/
selector.go
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
package cuckle
import (
"fmt"
"strings"
)
// Selector selects the result row values.
type Selector string
// Simple selectors.
const (
// SelectorAll selects all columns.
SelectorAll Selector = "*"
// SelectorCount selects the count of all result rows.
SelectorCount Selector = "count(*)"
)
// SelectorAlias returns a Selector for aliasing a Selector.
func SelectorAlias(s Selector, alias Identifier) Selector {
return Selector(fmt.Sprintf("%v as %v", s, alias))
}
// SelectorFunc returns a Selector for calling a function with argumnets.
func SelectorFunc(function Identifier, arguments ...Selector) Selector {
var ss []string
for _, a := range arguments {
ss = append(ss, string(a))
}
return Selector(fmt.Sprintf("%v(%v)", function, strings.Join(ss, ", ")))
}
// SelectorIdentifier returns a Selector for a column.
func SelectorIdentifier(column Identifier) Selector {
return Selector(fmt.Sprint(column))
}
// SelectorIndex returns a Selector for indexing a column.
func SelectorIndex(column Identifier, index Term) Selector {
return Selector(fmt.Sprintf("%v[%v]", column, index))
}
// SelectorTTL returns a Selector for the time-to-live of a column.
func SelectorTTL(i Identifier) Selector {
return Selector(fmt.Sprintf("ttl(%v)", i))
}
// SelectorWriteTime returns a Selector for the write time of a column.
func SelectorWriteTime(i Identifier) Selector {
return Selector(fmt.Sprintf("writetime(%v)", i))
}