Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

希望可以支持一下JSONQuery("key").NotEquals(...) #254

Open
siriusa51 opened this issue Apr 28, 2024 · 0 comments
Open

希望可以支持一下JSONQuery("key").NotEquals(...) #254

siriusa51 opened this issue Apr 28, 2024 · 0 comments
Assignees

Comments

@siriusa51
Copy link

我尝试着复制JSONQuery代码自己修改NotEquals,发现gorm框架里面有各种各样的类型限制,导致我没法直接设计自己的NotEquals
所以希望架构能支持JSONQuery.NotEquals, 或者说至少支持我自定义实现JSONQuery等部类型的相关Condition接口

func exprToCondition(exprs ...clause.Expression) []Condition {
	conds := make([]Condition, 0, len(exprs))
	for _, e := range exprs {
		switch e := e.(type) {
		case *datatypes.JSONQueryExpression, *datatypes.JSONOverlapsExpression:
			conds = append(conds, &condContainer{value: e})
		default:
			conds = append(conds, &condContainer{err: fmt.Errorf("unsupported Expression %T to converted to Condition", e)})
		}
	}
	return conds
}


func condToExpression(conds []Condition) ([]clause.Expression, error) {
	if len(conds) == 0 {
		return nil, nil
	}
	exprs := make([]clause.Expression, 0, len(conds))
	for _, cond := range conds {
		if cond == nil {
			continue
		}
		if err := cond.CondError(); err != nil {
			return nil, err
		}

		switch cond.(type) {
		case *condContainer, field.Expr, SubQuery:
		default:
			return nil, fmt.Errorf("unsupported condition: %+v", cond)
		}

		switch e := cond.BeCond().(type) {
		case []clause.Expression:
			exprs = append(exprs, e...)
		case clause.Expression:
			exprs = append(exprs, e)
		}
	}
	return exprs, nil
}

Motivation

Related Issues

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants