-
Notifications
You must be signed in to change notification settings - Fork 208
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
Add range clauses ([NOT] BETWEEN) support #25
Conversation
if err := me.Literal(buf, rhs1); err != nil { | ||
return err | ||
} | ||
buf.WriteString(" AND ") |
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.
I think you can use the default_and_fragment
here
//The left hand side of the expression (e.g. I("a") | ||
Lhs() Expression | ||
//The right hand side of the expression could be a primitive value, dataset, or expression | ||
Rhs1() 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.
So Im torn on this you could go a couple of different ways
- I think Rhs1 and 2 could be joined into a single slice of what would always be two values here and you could keep with the pattern on Lhs and Rhs and change the between methods to take variadic args but that could get messy.
- Create a new Range type
I("a").Between(Range(1,2))
which could still allow you to get the single Rhs and allow you to include between and notbetween in thegoqu.Ex
code which was commented out above.
What do you think? I lean towards option 2.
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.
Yeah, option 2 looks cleaner and less error prone :D
Hello @doug-martin, is there anything missing to merge this? Thanks! |
} | ||
ranged struct { | ||
lhs Expression | ||
rhs1 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.
I think we can replace the rhs1, rhs2 with a single RangeVal
@denisvm sorry I didnt notice that you had pushed up your changes to address that comment. I think the only thing is merging your rhs1/2 to a single RHS since you have added the RangeVal. Comment once that is done and Ill merge this. Great work! |
@@ -748,6 +770,10 @@ func (me *datasetTest) TestLiteralExpressionMap() { | |||
assert.Equal(t, buf.String(), `("a" NOT IN ('a', 'b', 'c'))`) | |||
assert.NoError(t, ds.Literal(me.Truncate(buf), Ex{"a": Op{"is": nil, "eq": 10}})) | |||
assert.Equal(t, buf.String(), `(("a" = 10) OR ("a" IS NULL))`) | |||
assert.NoError(t, ds.Literal(me.Truncate(buf), Ex{"a": Op{"between": RangeVal{1,10}}})) |
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.
golint
gripes about using RangeVal{1,10}
this way. I would specify the Start
and End
like you do in https://github.com/doug-martin/goqu/pull/25/files#diff-7101a3ea121adf8d5b0acb5a2c520ca3R1524
@doug-martin I've merged both rhs1 and rhs2 values into a single RangeVal struct as you've suggested |
bd7d9bf
to
482d3b5
Compare
Thanks again for the PR. I have published under v3.2 |
Implementation of range clauses for BETWEEN and NOT BETWEEN.
PS: I've not found a clean way yet to implement the expression mapping in
mapToExpressionList
function.