8000 NamedQuery 支持嵌套 map[string]interface{}, 实现过滤条件 · Issue #116 · didi/gendry · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

NamedQuery 支持嵌套 map[string]interface{}, 实现过滤条件 #116

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

Open
xiao-xiao-xiao opened this issue May 11, 2021 · 0 comments
Open

Comments

@xiao-xiao-xiao
Copy link
xiao-xiao-xiao commented May 11, 2021
/*
{
    sql: `select {{foo}},{{bar}} from tb where address in {{addr}} and {{where}}`,
        data: map[string]interface{}{
		"foo":  "f1",
		"bar":  "f2",
		"addr": []string{"beijing", "shanghai", "chengdu"},
		"where": map[string]interface{}{
			"name in": []string{"1", "2"},
                         "age": 10,
		 },
	},
	cond: `select ?,? from tb where address in (?,?,?) and (age=? AND name IN (?,?))`,,
	vals: []interface{}{"f1", "f2", "beijing", "shanghai", "chengdu", 10, "1", "2"},
}
*/

where := map[string]interface{}{
		"foo":  "f1",
		"bar":  "f2",
		"addr": []string{"beijing", "shanghai", "chengdu"},
		"where": map[string]interface{}{
			"name in": []string{"1", "2"},
                          "age": 10,
		 },
	},

where["where"] = builder.Omity(where["where"],  []string{"age"})
// 使用此种方式来实现,复杂SQL, 部分条件需要过滤
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

1 participant
0