示例#1
0
文件: pair.go 项目: amarantha-k/query
/*
Create a key value pair using the operands of the input
expression Array construct and return.
*/
func NewPair(expr expression.Expression) (*Pair, error) {
	array, ok := expr.(*expression.ArrayConstruct)
	if !ok {
		return nil, fmt.Errorf("Invalid VALUES expression %s", expr.String())
	}

	operands := array.Operands()
	if len(operands) != 2 {
		return nil, fmt.Errorf("Invalid VALUES expression %s", expr.String())
	}

	pair := &Pair{
		Key:   operands[0],
		Value: operands[1],
	}

	return pair, nil
}