-
Notifications
You must be signed in to change notification settings - Fork 279
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
R::findAlike functionality #313
Comments
Answer to #309 (comment) I cannot second guess what another user may would like to do with it but have you every worked with Access or Excel? Those are utilizing Microsoft QBE http://en.wikipedia.org/wiki/Microsoft_Query_by_Example My personal use case for it is because I'm creating QBE filters for my users. Why ... well I'm too lazy to create big filter forms with tons of logic to catch every potential filter combination. Secondly my customers do not all understand SQL, so they are not capable to get the information natively. Using QBE as visual guideline already prepares the data, and having a QBE filter approach in RB would simply making programming it easier. |
@zewa666 updated main post with your example and also the QBE stuff :) |
Okay, so I have a project and I would like to query similar projects..
Of course we do not want a project with the same ID. But now the question arises,
Also what kind of comparison do we want? Just == or also projects that started later?
What about certain parts of the name, AND-OR combinations?
To me SQL seems way simpler and even more powerful:
Early version of RedBeanPHP had exactly this. R::find used to work like R::findAlike, my point is that For more details on problems regarding QBE (inspiration for RedBeanPHP comes from this article): Also, as I said we can't write SQL inside R::find() because this SQL has to be written in the Query Writers - foreach database! This is a lot of work and each additional method in the writers makes RB less portable. However, given the R::find() method we can take some steps closer to a QBE, what would you think of:
Because we have no bindings parameter we decide to scan the query string and replace the named slots with their corresponding values in the prototype bean. cheers, |
Guess QBE is not such a typical word nowadays as it used to be :) Here is a nice research about QBE itself http://pages.cs.wisc.edu/~dbbook/openAccess/thirdEdition/qbe.pdf. In short some principles:
So besides that to help users querying easier some implementations contain help words like "BETWEEN x AND y" instead of adding two conditions like "> 2013-01-01" and "< 2013-12-12" Phpmyadmin is one of the rare tools leveraging a pretty nice QBE functionallity, maybe take a quick look at this Post explaining nicely how to work with it. |
@gabordemooij R::findAlike would always skip primary key, finding a bean that has the same id as the prototype don't make sense. These use case ramifications you pointed out are the same I pointed for Rx and the main reason I started #311, by the way. Simple SQL seems more powerful because you're ignoring one factor of the example scenario: dealing with dynamic conditions. Writing SQL will always lead to messed string manipulation in userland code, like in example 1. @zewa666 how about a more detailed example? Mine is too simple. |
@marcioAlmada you mean the $conditions variable. However there is still an implementation concern: how do we keep the QBE from writing its own specific SQL? Do we have to all QBE methods to the writers or can we find a more elegant solution? Do you have a plan to approach this practical challenge? |
I have no idea. Maybe such functionality like R::findAlike could be much easier to implement on top of some helper like the one described in #311 or Rx. |
I think this functionality would work best as a plugin, that way we can build this plugin for MySQL-like databases only without having to port all functions to Postgres, CUBRID, SQLite and Oracle (and MSSQL/DB2/Firebird in the future). |
Intent
This issue intends to discuss a PROPOSITION to add a new group of methods to R facade:
Motivation
Sometimes @gabordemooij defines Redbean as "A bridge between objects and records". Find alike methods are just one more step into this direction.
This proposition has no intention of suppressing Rx or #311. It can coexist or even depend on these implementations.
Usage
These new methods would behave like a QBE (query by example) tool, receiveing bean prototypes to configure database searches. Example 1:
Let's imagine an hypothetical application with a search form with lot's of fields. Every filled form field would create a new condition for the application to find information. With R::findAlike, userland code would look like this:
Without R::findAlike, userland code would potentially look like this:
Also, sometimes you already have a loaded bean and want others that are alike. Instead of creating some voodoo to conver that bean into a new search we would simply... Example2:
Advantages
Disvantages
since more complex db interaction should fall back to SQL usage.
The text was updated successfully, but these errors were encountered: