forked from ravendb/ravendb-go-client
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfields_to_fetch_token.go
67 lines (52 loc) · 1.75 KB
/
fields_to_fetch_token.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
55
56
57
58
59
60
61
62
63
64
65
66
67
package ravendb
import "strings"
var _ queryToken = &fieldsToFetchToken{}
type fieldsToFetchToken struct {
fieldsToFetch []string
projections []string
customFunction bool
sourceAlias string
}
func newFieldsToFetchToken(fieldsToFetch []string, projections []string, customFunction bool, sourceAlias string) *fieldsToFetchToken {
return &fieldsToFetchToken{
fieldsToFetch: fieldsToFetch,
projections: projections,
customFunction: customFunction,
sourceAlias: sourceAlias,
}
}
func createFieldsToFetchToken(fieldsToFetch []string, projections []string, customFunction bool, sourceAlias string) *fieldsToFetchToken {
if len(fieldsToFetch) == 0 {
panicIf(true, "fieldToFetch cannot be null")
//return newIllegalArgumentError("fieldToFetch cannot be null");
}
if !customFunction && len(projections) != len(fieldsToFetch) {
panicIf(true, "Length of projections must be the same as length of field to fetch")
// return newIllegalArgumentError("Length of projections must be the same as length of field to fetch");
}
return newFieldsToFetchToken(fieldsToFetch, projections, customFunction, sourceAlias)
}
func (t *fieldsToFetchToken) writeTo(writer *strings.Builder) error {
for i, fieldToFetch := range t.fieldsToFetch {
if i > 0 {
writer.WriteString(", ")
}
if fieldToFetch == "" {
writeQueryTokenField(writer, "null")
} else {
writeQueryTokenField(writer, fieldToFetch)
}
if t.customFunction {
continue
}
// Note: Java code has seemingly unnecessary checks (conditions that would
// be rejected in createFieldsToFetchToken)
projection := t.projections[i]
if projection == "" || projection == fieldToFetch {
continue
}
writer.WriteString(" as ")
writer.WriteString(projection)
}
return nil
}