MCPcopy Create free account
hub / github.com/go-pg/pg / AppendQuery

Method AppendQuery

orm/select.go:55–213  ·  view source on GitHub ↗
(fmter QueryFormatter, b []byte)

Source from the content-addressed store, hash-verified

53}
54
55func (q *SelectQuery) AppendQuery(fmter QueryFormatter, b []byte) (_ []byte, err error) { //nolint:gocyclo
56 b = appendComment(b, q.q.comment)
57 if q.q.stickyErr != nil {
58 return nil, q.q.stickyErr
59 }
60
61 cteCount := q.count != "" && (len(q.q.group) > 0 || q.isDistinct())
62 if cteCount {
63 b = append(b, `WITH "_count_wrapper" AS (`...)
64 }
65
66 if len(q.q.with) > 0 {
67 b, err = q.q.appendWith(fmter, b)
68 if err != nil {
69 return nil, err
70 }
71 }
72
73 if len(q.q.union) > 0 {
74 b = append(b, '(')
75 }
76
77 b = append(b, "SELECT "...)
78
79 if len(q.q.distinctOn) > 0 {
80 b = append(b, "DISTINCT ON ("...)
81 for i, app := range q.q.distinctOn {
82 if i > 0 {
83 b = append(b, ", "...)
84 }
85 b, err = app.AppendQuery(fmter, b)
86 }
87 b = append(b, ") "...)
88 } else if q.q.distinctOn != nil {
89 b = append(b, "DISTINCT "...)
90 }
91
92 if q.count != "" && !cteCount {
93 b = append(b, q.count...)
94 } else {
95 b, err = q.appendColumns(fmter, b)
96 if err != nil {
97 return nil, err
98 }
99 }
100
101 if q.q.hasTables() {
102 b = append(b, " FROM "...)
103 b, err = q.appendTables(fmter, b)
104 if err != nil {
105 return nil, err
106 }
107 }
108
109 err = q.q.forEachHasOneJoin(func(j *join) error {
110 b = append(b, ' ')
111 b, err = j.appendHasOneJoin(fmter, b, q.q)
112 return err

Callers 2

StringMethod · 0.95
AppendTemplateMethod · 0.95

Calls 11

isDistinctMethod · 0.95
appendColumnsMethod · 0.95
appendTablesMethod · 0.95
appendCommentFunction · 0.85
appendWithMethod · 0.80
hasTablesMethod · 0.80
forEachHasOneJoinMethod · 0.80
appendHasOneJoinMethod · 0.80
isSoftDeleteMethod · 0.80
appendWhereMethod · 0.80
AppendQueryMethod · 0.65

Tested by

no test coverage detected