github.com/ravendb/ravendb-go-client@v0.0.0-20240229102137-4474ee7aa0fa/fields_to_fetch_token.go (about) 1 package ravendb 2 3 import "strings" 4 5 var _ queryToken = &fieldsToFetchToken{} 6 7 type fieldsToFetchToken struct { 8 fieldsToFetch []string 9 projections []string 10 customFunction bool 11 sourceAlias string 12 } 13 14 func newFieldsToFetchToken(fieldsToFetch []string, projections []string, customFunction bool, sourceAlias string) *fieldsToFetchToken { 15 return &fieldsToFetchToken{ 16 fieldsToFetch: fieldsToFetch, 17 projections: projections, 18 customFunction: customFunction, 19 sourceAlias: sourceAlias, 20 } 21 } 22 23 func createFieldsToFetchToken(fieldsToFetch []string, projections []string, customFunction bool, sourceAlias string) *fieldsToFetchToken { 24 if len(fieldsToFetch) == 0 { 25 panicIf(true, "fieldToFetch cannot be null") 26 //return newIllegalArgumentError("fieldToFetch cannot be null"); 27 } 28 29 if !customFunction && len(projections) != len(fieldsToFetch) { 30 panicIf(true, "Length of projections must be the same as length of field to fetch") 31 // return newIllegalArgumentError("Length of projections must be the same as length of field to fetch"); 32 } 33 34 return newFieldsToFetchToken(fieldsToFetch, projections, customFunction, sourceAlias) 35 } 36 37 func (t *fieldsToFetchToken) writeTo(writer *strings.Builder) error { 38 for i, fieldToFetch := range t.fieldsToFetch { 39 40 if i > 0 { 41 writer.WriteString(", ") 42 } 43 44 if fieldToFetch == "" { 45 writeQueryTokenField(writer, "null") 46 } else { 47 writeQueryTokenField(writer, fieldToFetch) 48 49 } 50 51 if t.customFunction { 52 continue 53 } 54 55 // Note: Java code has seemingly unnecessary checks (conditions that would 56 // be rejected in createFieldsToFetchToken) 57 projection := t.projections[i] 58 59 if projection == "" || projection == fieldToFetch { 60 continue 61 } 62 63 writer.WriteString(" as ") 64 writer.WriteString(projection) 65 } 66 return nil 67 }