Files
chaisql/internal/expr/constraint.go
Asdine El Hrychy f966172cee Introduce Value interface (#422)
This replaces the Value struct by an interface to allow us to override some
values behavior in the future.
It also introduces a new package types, which contains type definitions, comparison,
and arithmetics.
Concerning encoding, Genji now only uses on type of encoding for values. This simplifies
indexing logic as well as table access in general.
2021-07-21 22:05:44 +04:00

55 lines
976 B
Go

package expr
import (
"errors"
"github.com/genjidb/genji/internal/database"
"github.com/genjidb/genji/internal/environment"
"github.com/genjidb/genji/types"
)
type ConstraintExpr struct {
Expr Expr
Catalog database.Catalog
}
func Constraint(e Expr) *ConstraintExpr {
return &ConstraintExpr{
Expr: e,
}
}
func (t *ConstraintExpr) Eval(tx *database.Transaction) (types.Value, error) {
var env environment.Environment
env.Catalog = t.Catalog
env.Tx = tx
if t.Expr == nil {
return NullLiteral, errors.New("missing expression")
}
return t.Expr.Eval(&env)
}
func (t *ConstraintExpr) Bind(catalog database.Catalog) {
t.Catalog = catalog
}
func (t *ConstraintExpr) IsEqual(other database.TableExpression) bool {
if t == nil {
return other == nil
}
if other == nil {
return false
}
o, ok := other.(*ConstraintExpr)
if !ok {
return false
}
return Equal(t.Expr, o.Expr)
}
func (t *ConstraintExpr) String() string {
return t.Expr.String()
}