Converting to different DSL #4
Comments
@TimeToogo to be more precise (and I didn't try it myself, but I will as soon as I have time), I want to be sure if I'm grokking this correctly:
Is this the right approach or am I getting it totally wrong? It really takes a bit of creativity to follow the example with the array, as it is still very near to the iterator logic that is already implemented within Pinq. Also, the examples also directly manipulate the data, which is something that isn't happening in any query-based persistence layer. |
Not quite, the structure first:
Sorry for this, it may confuse you even further. It got out of hand rather quickly. As for the most part, I was building the concept in my head aswell Here is a rough guide to implementing SQL query provider: I would start off with an class that represents a SQL Interpreting the Scope You will also need a (probably multiple) class that extends the To interpret this part of the query you should create a class which extends the Override each segment visitor method to handle the type of segment:
The above is me just mocking how I would handle each query segment. Now this would become infinitely more complex when you apply things like multiple Interpreting the Requests To interpret the request you should create a class which extends the Again, override each method to handle every request type:
All of this would come together in an IQueryProvider::load
I am planning to add a parallel to the current online example with SQL queries as you have mentioned. |
@TimeToogo woah, this is awesome feedback! I'll read through it and see if I can make any use of it. Thanks a lot for this very detailed explanation. Paid work calls, but I'll go through it as soon as I have time. Thanks a lot! |
@Ocramius Just realising this, but there is a perfect This is also a subclass of This will avoid unnessecary queries to the DB: $someRows = $table->where(function ($row) { return $row['id'] <= 50; });
foreach($someRows as $row) {
//This will load the rows, (Values request)
}
//This will be evaluated in memory, (Maximum request)
$maxId = $someRows->maximum(function ($row) { return $row['id']; }); But note that instead of overriding |
I have just implemented This has additional capability of evaluating additional query scopes rather than just the same scope with different requests. This will even further reduce the number of unnecessary queries to the db: $someRows = $table->where(function ($row) { return $row['id'] <= 50; });
foreach($someRows as $row) {
//This will load the rows
}
//This will be evaluated in memory because the parent scope is loaded
$someOtherRows = $someRows->orderByDescending(function ($row) { return $row['id']; }); |
Well better late than never. Here is a documented demo repository containing an implementation of the DSL query provider platform. This maps a subset of the PINQ API to a MySQL database backend. |
Absolutely awesome! |
Different data-sources, such as RDBMSs or MongoDB, use different DSLs (SQL/JS queries, etc).
What I found out so far is this page in the docs, which seems to simulate usage of a visitor on different types of filtering/aggregation requests.
It is really hard for newcomers to understand how to use the visitors to lazily evaluate Pinq expressions to convert them into, for example, SQL.
A simplified SQL that appends conditionals to a given SQL string would probably be useful in those examples.
The text was updated successfully, but these errors were encountered: