sqlboiler icon indicating copy to clipboard operation
sqlboiler copied to clipboard

Minor query builder improvements

Open ccakes opened this issue 3 years ago • 5 comments

This PR implements the following:

  • Added queries.BuildSubquery() which does the same thing as BuildQuery() except doesn't append a semicolon so query builder results can be embedded in other queries
  • Added `qm.WithSubquery() which allows generating a CTE using a query object built by sqlboiler

The WithSubquery() modifier is interesting imo because if there's interest, there are a number of query mods that could be added to work with subqueries to allow building pretty complex, type-checked queries without horrible code.

ccakes avatar Feb 15 '22 10:02 ccakes

This is quite interesting and it makes complete sense. If everything checks out and it is completely backward compatible, it would make sense to merge now (or wait till v5 if not).

Just so you know, we are thinking of making the query builder more driver-specific, so that each driver could potentially support more specific things. This will likely happen in v5.

The base one will still exist for others to extend if they want so of course, this will still be useful.

stephenafamo avatar Feb 15 '22 11:02 stephenafamo

This should be fully backwards compatible. If it's not, I'll make changes so that it is 👍

Just so you know, we are thinking of making the query builder more driver-specific, so that each driver could potentially support more specific things. This will likely happen in v5.

Interesting.. that makes sense. Looking forward to seeing what's coming!

ccakes avatar Feb 15 '22 11:02 ccakes

I just noticed that this will not be backward compatible since the function signature of AppendWith changed.

In its current state, we will only be able to merge it into v5.

stephenafamo avatar Feb 17 '22 10:02 stephenafamo

At some point over the next few days I'll see if I can come up with a change here to resolve this, will comment back either way

ccakes avatar Feb 17 '22 22:02 ccakes

Come on merge it please!

sn0rk64 avatar Nov 01 '22 12:11 sn0rk64