Files
ent/entc/gen/predicate.go
Ariel Mashraki 56656dfcb6 ent/entc: configure storage driver in codegen
Summary: Pull Request resolved: https://github.com/facebookexternal/fbc/pull/1229

Reviewed By: alexsn

Differential Revision: D16539934

fbshipit-source-id: b3a8bf1f1be6f65ad3f649cd921ea20fc24182bf
2019-07-30 02:49:22 -07:00

70 lines
1.5 KiB
Go

package gen
// Op is a predicate for the where clause.
type Op int
// List of all builtin predicates.
const (
EQ Op = iota // =
NEQ // <>
GT // >
GTE // >=
LT // <
LTE // <=
In // within
NotIn // without
Contains // containing
HasPrefix // startingWith
HasSuffix // endingWith
)
// Name returns the string representation of an operator.
func (o Op) Name() string {
if int(o) < len(opText) {
return opText[o]
}
return "Unknown"
}
// Gremlin returns the gremlin code representation of an operator.
func (o Op) Gremlin() string {
if code := gremlinCode[o]; code != "" {
return code
}
return o.Name()
}
// Variadic reports if the predicate is a variadic function.
func (o Op) Variadic() bool {
return o == In || o == NotIn
}
var (
// operations text.
opText = [...]string{
EQ: "EQ",
NEQ: "NEQ",
GT: "GT",
GTE: "GTE",
LT: "LT",
LTE: "LTE",
Contains: "Contains",
HasPrefix: "HasPrefix",
HasSuffix: "HasSuffix",
In: "In",
NotIn: "NotIn",
}
// operations code in gremlin.
gremlinCode = [...]string{
In: "Within",
NotIn: "Without",
Contains: "Containing",
HasPrefix: "StartingWith",
HasSuffix: "EndingWith",
}
// operations per type.
boolOps = []Op{EQ, NEQ}
numericOps = append(boolOps[:], GT, GTE, LT, LTE, In, NotIn)
stringOps = append(numericOps[:], Contains, HasPrefix, HasSuffix)
)