Skip to content

question : how to reuse where clauses ? #150

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

Closed
cooljeffrey opened this issue Nov 12, 2019 · 4 comments
Closed

question : how to reuse where clauses ? #150

cooljeffrey opened this issue Nov 12, 2019 · 4 comments

Comments

@cooljeffrey
Copy link

Hello mate, thanks for this awesome lib!

I got a question trying to reuse some complex where clause between mapper.selectMany and mapepr.countByExample. With the example classes generated against runtime MyBatis3, I could reuse a built up example instance between select and count, how can I do this with runtime MyBatis3DynamicSQL ?

The purpose to reuse the where clauses is that in some situations we need to return a total count for the records matching the criteria, then do another select to return a paginated result set by setting additional offset and limit.

Looking forward to your reply, thanks!

@jeffgbutler
Copy link
Member

This is a really interesting question! I had not considered the use case of reusing where clauses, but it makes perfect sense.

I don't have a great answer for you now, but I will look into it and see if I can make something work.

@jeffgbutler
Copy link
Member

I've committed a potential solution in my branch here: https://github.com/jeffgbutler/mybatis-dynamic-sql/tree/reusable-where

There's a bit of noise in this for the implementation, but you can just pay attention to the test classes.

The Java test class is here: https://github.com/jeffgbutler/mybatis-dynamic-sql/blob/reusable-where/src/test/java/examples/simple/ReusableWhereTest.java

The Kotlin test class is here: https://github.com/jeffgbutler/mybatis-dynamic-sql/blob/reusable-where/src/test/kotlin/examples/kotlin/mybatis3/canonical/ReusableWhereTest.kt

Let me know what you think.

@cooljeffrey
Copy link
Author

This looks exactly what I need.
Thanks for the quick response! I cannot wait to see this in the next release together with MBG. Cheers ~

@jeffgbutler
Copy link
Member

Resolved via #152

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants