Files
chaisql/internal/expr/param.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

50 lines
1.5 KiB
Go

package expr
import (
"github.com/genjidb/genji/internal/environment"
"github.com/genjidb/genji/internal/stringutil"
"github.com/genjidb/genji/types"
)
// NamedParam is an expression which represents the name of a parameter.
type NamedParam string
// Eval looks up for the parameters in the env for the one that has the same name as p
// and returns the value.
func (p NamedParam) Eval(env *environment.Environment) (types.Value, error) {
return env.GetParamByName(string(p))
}
// IsEqual compares this expression with the other expression and returns
// true if they are equal.
func (p NamedParam) IsEqual(other Expr) bool {
o, ok := other.(NamedParam)
return ok && p == o
}
// String implements the stringutil.Stringer interface.
func (p NamedParam) String() string {
return stringutil.Sprintf("$%s", string(p))
}
// PositionalParam is an expression which represents the position of a parameter.
type PositionalParam int
// Eval looks up for the parameters in the env for the one that is has the same position as p
// and returns the value.
func (p PositionalParam) Eval(env *environment.Environment) (types.Value, error) {
return env.GetParamByIndex(int(p))
}
// IsEqual compares this expression with the other expression and returns
// true if they are equal.
func (p PositionalParam) IsEqual(other Expr) bool {
o, ok := other.(PositionalParam)
return ok && p == o
}
// String implements the stringutil.Stringer interface.
func (p PositionalParam) String() string {
return "?"
}