MCPcopy Index your code
hub / github.com/ent/ent / evalBinary

Method evalBinary

dialect/sql/sqlgraph/entql.go:206–240  ·  view source on GitHub ↗

evalBinary evaluates binary expressions.

(expr *entql.BinaryExpr)

Source from the content-addressed store, hash-verified

204
205// evalBinary evaluates binary expressions.
206func (e *state) evalBinary(expr *entql.BinaryExpr) *sql.Predicate {
207 switch expr.Op {
208 case entql.OpOr:
209 return sql.Or(e.evalExpr(expr.X), e.evalExpr(expr.Y))
210 case entql.OpAnd:
211 return sql.And(e.evalExpr(expr.X), e.evalExpr(expr.Y))
212 case entql.OpEQ, entql.OpNEQ:
213 if expr.Y == (*entql.Value)(nil) {
214 f, ok := expr.X.(*entql.Field)
215 expect(ok, "*entql.Field, got %T", expr.Y)
216 return nullFunc[expr.Op](e.field(f))
217 }
218 fallthrough
219 default:
220 field, ok := expr.X.(*entql.Field)
221 expect(ok, "expr.X to be *entql.Field (got %T)", expr.X)
222 _, ok = expr.Y.(*entql.Field)
223 if !ok {
224 _, ok = expr.Y.(*entql.Value)
225 }
226 expect(ok, "expr.Y to be *entql.Field or *entql.Value (got %T)", expr.X)
227 switch x := expr.Y.(type) {
228 case *entql.Field:
229 return sql.ColumnsOp(e.field(field), e.field(x), binary[expr.Op])
230 case *entql.Value:
231 c := e.field(field)
232 return sql.P(func(b *sql.Builder) {
233 b.Ident(c).WriteOp(binary[expr.Op])
234 args(b, x)
235 })
236 default:
237 panic("unreachable")
238 }
239 }
240}
241
242// evalEdge evaluates has-edge and has-edge-with calls.
243func (e *state) evalEdge(name string, exprs ...entql.Expr) *sql.Predicate {

Callers 1

evalExprMethod · 0.95

Implementers 2

Wrapperdialect/sql/builder.go
Builderdialect/sql/builder.go

Calls 10

evalExprMethod · 0.95
fieldMethod · 0.95
OrFunction · 0.92
AndFunction · 0.92
ColumnsOpFunction · 0.92
PStruct · 0.92
argsFunction · 0.85
WriteOpMethod · 0.80
IdentMethod · 0.80
expectFunction · 0.70

Tested by

no test coverage detected