Implementing subqueries in FROM section #4476
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
I am waiting feedback of the community, so I see no reason to add tests and descriptions to UG right now.
Added BaseConnection::raw() method.
It expects a raw SQL subquery as an argument and returns an instance of the SqlExpression class.
This is to prevent processing subqueries as a simple string.
BaseConnection::table() and BaseBuilder::from() methods.
Now takes as an argument Closure, BaseBuilder, SqlExpression, array, string, null.
This solution makes it possible to use a wrapper for the main query.
and will allow better implementation of support for UNION queries.
Query builder methods that previously took Closure as an argument now take BaseBuilder and SqlExpression.
Help wanted
I also want to ask about this "problem".
The problem starts with tests (SQLSRV). We get an instance of the query builder.
If
$this->db->table(null)
is called inside the query builder, then theMockBuilder
instance will be retrieved, not theSQLSRVBuilder
instance.And the subquery will not be generated correctly.
There are several solutions.
Use
new static(null, $this->db)
instead of$this->db->table(null)
, but phpstan says:Unsafe usage of new static()
.Or use the SQLSRV driver's Coonnection class instead of the MockConnection class for testing.
But I'm not sure if replacing the connection class is correct.
Checklist: