Skip to content
This repository has been archived by the owner on Jul 29, 2020. It is now read-only.

fixing the IN operator syntax and adding ANY, SOME, ALL operators to where clause #13

Merged
merged 5 commits into from
Sep 19, 2017

Conversation

tarnowsc
Copy link
Contributor

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

@marioidival marioidival requested a review from a team August 23, 2017 12:46
Copy link
Member

@felipeweb felipeweb left a 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 🎉 🎉 🎉


case "ANY", "SOME", "ALL":
whereKey = append(whereKey, fmt.Sprintf(`%s = %s ($%d)`, key, op, pid))
whereValues = append(whereValues, pq.Array(strings.Split(value, ",")))
Copy link
Member

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

@@ -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{}{}
Copy link
Member

@felipeweb felipeweb Aug 23, 2017

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

@tarnowsc
Copy link
Contributor Author

tarnowsc commented Aug 23, 2017 via email

@crgimenes
Copy link
Contributor

Is this PR still alive?
@tarnowsc @felipeweb

Copy link
Member

@avelino avelino left a 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

Copy link
Member

@felipeweb felipeweb left a 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

whereKey = append(whereKey, fmt.Sprintf(`%s %s`, key, op))
case "=", "!=", ">", ">=", "<", "<=":
Copy link
Member

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

Copy link
Member

@felipeweb felipeweb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@crgimenes crgimenes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@felipeweb felipeweb merged commit 13ede17 into prest:master Sep 19, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
4 participants