-
Notifications
You must be signed in to change notification settings - Fork 11
fixing the IN operator syntax and adding ANY, SOME, ALL operators to where clause #13
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add some docs on operators section in README about these new supported operators.
Add some tests for these new operators.
i requested some changes in your code.
@tarnowsc thank you for the PR 🎉 🎉 🎉
postgres/postgres.go
Outdated
|
||
case "ANY", "SOME", "ALL": | ||
whereKey = append(whereKey, fmt.Sprintf(`%s = %s ($%d)`, key, op, pid)) | ||
whereValues = append(whereValues, pq.Array(strings.Split(value, ","))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
please use our function FormatArray instead pq.Array
postgres/postgres.go
Outdated
@@ -129,7 +130,7 @@ func chkInvalidIdentifier(identifer ...string) bool { | |||
// WhereByRequest create interface for queries + where | |||
func WhereByRequest(r *http.Request, initialPlaceholderID int) (whereSyntax string, values []interface{}, err error) { | |||
whereKey := []string{} | |||
whereValues := []string{} | |||
whereValues := []interface{}{} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if you use our function FormatArray instead pq.Array this variable don't need to be []interface{} can be []string
Sure, I will do that after Monday.
…On Aug 23, 2017 15:07, "Felipe Oliveira" ***@***.***> wrote:
***@***.**** requested changes on this pull request.
Add some docs on operators section in README about these new supported
operators.
Add some tests for these new operators.
i requested some changes in your code.
@tarnowsc <https://github.com/tarnowsc> thank you for the PR 🎉 🎉 🎉
------------------------------
In postgres/postgres.go
<#13 (comment)>:
>
+ switch op {
+ case "IN", "NOT IN":
+ v := strings.Split(value, ",")
+ keyParams := make([]string, len(v))
+ for i := 0; i < len(v); i++ {
+ whereValues = append(whereValues, v[i])
+ keyParams[i] = fmt.Sprintf(`$%d`, pid+i)
+ }
+ pid += len(v)
+ whereKey = append(whereKey, fmt.Sprintf(`%s %s (%s)`, key, op, strings.Join(keyParams, ",")))
+
+ case "ANY", "SOME", "ALL":
+ whereKey = append(whereKey, fmt.Sprintf(`%s = %s ($%d)`, key, op, pid))
+ whereValues = append(whereValues, pq.Array(strings.Split(value, ",")))
please use our function FormatArray instead pq.Array
------------------------------
In postgres/postgres.go
<#13 (comment)>:
> @@ -129,7 +130,7 @@ func chkInvalidIdentifier(identifer ...string) bool {
// WhereByRequest create interface for queries + where
func WhereByRequest(r *http.Request, initialPlaceholderID int) (whereSyntax string, values []interface{}, err error) {
whereKey := []string{}
- whereValues := []string{}
+ whereValues := []interface{}{}
if you use FormatArray instead pq.Array this variable don't need to be
[]interface{} can be []string
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#13 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABA1P_14dSINWBbTD8nyMRGi_eVJ5VsQks5sbCQdgaJpZM4O_nQS>
.
|
Is this PR still alive? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
travis not working, review pls
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just a little change
postgres/postgres.go
Outdated
whereKey = append(whereKey, fmt.Sprintf(`%s %s`, key, op)) | ||
case "=", "!=", ">", ">=", "<", "<=": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use this as default case
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Hi,
I couldn't make $in. operator to work as it was producing malformed sql query.
The problem with pq lib is that the IN clause is not really properly supported and it is better to use arrays with ANY operator. Therefore I've added support for $any. $some. and $all.
The syntax to pass multiple values is as follows:
http://127.0.0.1:8000/DATABASE/SCHEMA/TABLE?id=$any.14,2,5
http://127.0.0.1:8000/DATABASE/SCHEMA/TABLE?string_id=$any.'14','2','5'
Best Regards
Cezary