Skip to content
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

Support subqueries #12

Merged
merged 1 commit into from Oct 5, 2013
Merged

Support subqueries #12

merged 1 commit into from Oct 5, 2013

Conversation

@uranusjr
Copy link
Contributor

uranusjr commented Oct 5, 2013

Based on the discussion in #9.

I added an extra layer _query between str and raw to use internally. Statement-based callables and identifier now both return a _query object instead of str. This difference is used in identifier to avoid applying unintended processing to _query objects that represent subqueries.

Now you can do this:

subquery = select('person', select=('last_name',))
print select('person', where={'first_name': paren(subquery)})

And get:

SELECT * FROM "person" WHERE "first_name" = (SELECT "last_name" FROM "person")

The above test has been added to build.select.

I added an extra layer "_query" between str and raw to use internally.
Statement-based callables and "identifier" now both return a _query
object
instead of str. This difference is used in "identifier" to avoid
applying
unintended processing to _query objects that represent subqueries.

Now you can do this:

>>> subquery = select('person', select=('last_name',))
>>> print select('person', where={'first_name': paren(subquery)})

And get:

SELECT * FROM "person" WHERE "first_name" = (SELECT "last_name" FROM
"person")

The above test has been added to build.select.
moskytw added a commit that referenced this pull request Oct 5, 2013
Support subqueries
@moskytw moskytw merged commit 8f1da98 into moskytw:dev Oct 5, 2013
1 check passed
1 check passed
default The Travis CI build passed
Details
@moskytw
Copy link
Owner

moskytw commented Oct 13, 2013

I did some changes basing on your code:

  1. The mosql.build is deprecated, so I removed the doctests. I will re-added them in query.rst. (see 9141715)
  2. Actually, supporting subquery doesn't need so much code, so I removed some. (see 679f758)
  3. Finally, I use another approach instead of _query. It is simpler but slower I think, so I am not sure it is better or not. (see 36c1ae9)

Maybe you will want to make sure the functionality is still correct.

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

Successfully merging this pull request may close these issues.

None yet

2 participants
You can’t perform that action at this time.