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

support fields linked with ops#135

Open
Guojunzhou-git wants to merge1 commit intodidi:master
base:master
Choose a base branch
Loading
fromdriving-home:master

Conversation

Guojunzhou-git
Copy link

@Guojunzhou-gitGuojunzhou-git commentedFeb 13, 2023
edited
Loading

map with keyfoo> instead offoo > gotfield="foo>"operator="=", then where condition isfoo>=.

builder.BuildSelect(map[string]interface{}{"foo>":"bar"})

got

SELECT*FROM tbWHERE (foo>=?)"

when no space inkey, not defaultfield=key andoperator="=", but try to parsefileds linked with ops, such asfoo>,foo>=,foo<,foo<=,foo<>,foo!=,foo=

@caibirdme
Copy link
Contributor

可以讨论下必要性,我个人觉得这个没多大必要:

  1. 大多数时候用的都是等于比较,即 "a": 1。如果合入这个pr之后,所有的等于比较都要增加额外的负担来检查key里是否包涵比较符号,对性能有一定影响
  2. 用户只要知道中间要打个空格,是不是以后就完全用不到这个feature了

@Guojunzhou-git
Copy link
Author

可以讨论下必要性,我个人觉得这个没多大必要:

  1. 大多数时候用的都是等于比较,即 "a": 1。如果合入这个pr之后,所有的等于比较都要增加额外的负担来检查key里是否包涵比较符号,对性能有一定影响
  2. 用户只要知道中间要打个空格,是不是以后就完全用不到这个feature了

个人建议哈:

  1. 比起a>= 解析为a>== 的 sql 错误来讲,b>解析为b>= 的表现会比较难以发现。引入此 pr 后,使用起来会更友好些。
  2. opCanLinkedWithField涉及此问题的运算符只有7个:4个2字符运算符(将导致sql错误)和3个1字符运算符(将导致语义上的变化),对性能的影响不是很大。

综上,还是建议能更多的考虑易用和友好

@Guojunzhou-git
Copy link
Author

funcsplitKey(keystring,valinterface{}) (fieldstring,operatorstring,errerror) {key=strings.Trim(key," ")if""==key {err=errSplitEmptyKeyreturn}idx:=strings.IndexByte(key,' ')ifidx==-1 {field=keyoperator="="ifisFieldContainOp(field) {field,operator=splitKeyNoSpace(field)}ifreflect.ValueOf(val).Kind()==reflect.Slice {operator="in"}}else {field=key[:idx]operator=strings.Trim(key[idx+1:]," ")operator=removeInnerSpace(operator)}return}funcisFieldContainOp(fieldstring) (containsbool) {iffield=="" {return}ecof:=field[len(field)-1:]contains=ecof==opEq||ecof==opLt||ecof==opGtreturn}`

@Guojunzhou-git
Copy link
Author

可以尝试isFieldContainOp 判定下是否需要

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.

2 participants
@Guojunzhou-git@caibirdme

[8]ページ先頭

©2009-2025 Movatter.jp