mirror of
https://github.com/chaisql/chai.git
synced 2025-10-28 17:51:48 +08:00
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.
55 lines
976 B
Go
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()
|
|
}
|