Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

NamedQuery support map#117

Open
xiao-xiao-xiao wants to merge1 commit intodidi:master
base:master
Choose a base branch
Loading
fromxiao-xiao-xiao:issue#116

Conversation

xiao-xiao-xiao
Copy link

No description provided.

@caibirdme
Copy link
Contributor

感谢你的PR,但是经过考虑,觉得这个特性不适合合入主干,主要原因:

  • NamedQuery希望用户直接写sql,而支持map展开其实和这个目的是相悖的
  • where map的namedquery里支持其实很复杂,map套map怎么办呢?

所以还是希望大家可以合理使用工具,namedquery手写,其它用where map

@xiao-xiao-xiao
Copy link
Author

感谢你的PR,但是经过考虑,觉得这个特性不适合合入主干,主要原因:

  • NamedQuery希望用户直接写sql,而支持map展开其实和这个目的是相悖的
  • where map的namedquery里支持其实很复杂,map套map怎么办呢?

所以还是希望大家可以合理使用工具,namedquery手写,其它用where map

  1. 这个理解,不过能不能支持下复杂SQL参数不固定的情况呢? 目前仅仅使用map是不够用的。 类似提供where 条件的导出BuildWhere(where map[string]interface{})(query string, args []interface{}, err error)
  2. map 嵌套map 从目前看, 仅仅只有_or 条件有这个嵌套, 其它情况报错或者不处理也行;

@caibirdme

@caibirdme
Copy link
Contributor

什么情况下需要到处where呢

@xiao-xiao-xiao
Copy link
Author

xiao-xiao-xiao commentedJun 18, 2021
edited
Loading

什么情况下需要到处where呢

一些场景下,需要使用动态参数,再加一些gendry不支持的条件, 譬如
select a from table where {{动态字段}} and find_in_set {{set}}; 像这种场景,用单纯的NamedQuery 写起来太复杂了。解决这种情况如果 NamedQuery 支持 map 解析,会简单很多, 使用导出where 也能解决此问题,而且更加灵活。
@caibirdme

@twz915
Copy link
Contributor

这个问题我遇到过,我在内部提供了 BuildWhere版本,类似于部分条件是动态的

@caibirdme
Copy link
Contributor

可以给一些期望的input和output吗

@twz915
Copy link
Contributor

可以自己实现一个 BuildWhere,这样可以避免拼上有一部分动态的条件。@xiao-xiao-xiao
示例如下:

// BuildWhere 生成 where 条件,避免手动拼sqlfunc BuildWhere(where map[string]any, addAnd bool) (cond string, vals []any, err error) {cond, vals, err = BuildSelect("x", where, nil)parts := strings.SplitN(cond, "WHERE", 2)if len(parts) == 2 {cond = strings.TrimSpace(parts[1])} else {cond = ""}if cond != "" && addAnd {cond = " AND " + cond}return}

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@xiao-xiao-xiao@caibirdme@twz915

[8]ページ先頭

©2009-2025 Movatter.jp