MCPcopy
hub / github.com/go-gorm/gorm / Build

Method Build

clause/where.go:168–245  ·  view source on GitHub ↗
(builder Builder)

Source from the content-addressed store, hash-verified

166}
167
168func (not NotConditions) Build(builder Builder) {
169 anyNegationBuilder := false
170 for _, c := range not.Exprs {
171 if _, ok := c.(NegationExpressionBuilder); ok {
172 anyNegationBuilder = true
173 break
174 }
175 }
176
177 if anyNegationBuilder {
178 if len(not.Exprs) > 1 {
179 builder.WriteByte('(')
180 }
181
182 for idx, c := range not.Exprs {
183 if idx > 0 {
184 builder.WriteString(AndWithSpace)
185 }
186
187 if negationBuilder, ok := c.(NegationExpressionBuilder); ok {
188 negationBuilder.NegationBuild(builder)
189 } else {
190 builder.WriteString("NOT ")
191 e, wrapInParentheses := c.(Expr)
192 if wrapInParentheses {
193 sql := strings.ToUpper(e.SQL)
194 if wrapInParentheses = strings.Contains(sql, AndWithSpace) || strings.Contains(sql, OrWithSpace); wrapInParentheses {
195 builder.WriteByte('(')
196 }
197 }
198
199 c.Build(builder)
200
201 if wrapInParentheses {
202 builder.WriteByte(')')
203 }
204 }
205 }
206
207 if len(not.Exprs) > 1 {
208 builder.WriteByte(')')
209 }
210 } else {
211 builder.WriteString("NOT ")
212 if len(not.Exprs) > 1 {
213 builder.WriteByte('(')
214 }
215
216 for idx, c := range not.Exprs {
217 if idx > 0 {
218 switch c.(type) {
219 case OrConditions:
220 builder.WriteString(OrWithSpace)
221 default:
222 builder.WriteString(AndWithSpace)
223 }
224 }
225

Callers

nothing calls this directly

Calls 5

ContainsMethod · 0.80
WriteByteMethod · 0.65
WriteStringMethod · 0.65
NegationBuildMethod · 0.65
BuildMethod · 0.65

Tested by

no test coverage detected