How to emulate FQL (Facebook Query Language) in your app
I program heavily in the Symfony framework under PHP, and I required more flexibility in my ORM (Object Relational Model), since the default ORM included with Symfony, Propel, doesn’t play very nice with Oracle. Reading the Symfony forums on the main ORMs for use with Symfony, I came across the Doctrine Project, of which the syntax is inspired by Java Hibernate’s HQL called DQL (Doctrine Query Language).
I’ve never worked with HQL/DQL before, but I found myself loving it because I can write (almost) natural SQL-like query statements that act on my object model. Lately, I’ve been thinking about how to bring about a FQL-like (Facebook Query Language) platform to a project I’m working on at work, and had this sudden realization: I can bring a SQL-like syntax to platform developers through the use of DQL.
DQL is by no means efficient like FQL in terms of how it performs its data mining and (possibly) hydration, but if you want to give developers the power to select from tables in your database without giving full or just read-only access, using Doctrine’s DQL is the way to go.
My reasoning is this:
Let’s assume that I want developers to be able to access some basic information from a table where I store users, but that users table might also have information such as a password, which I do not want to expose to developers. However, on our code backend, we of course need access to the password field, but on our developer end, restrict completely.
In my Doctrine ORM, I would define two objects, one that corresponds with internal access, and another with external. Here’s a sample:
intUser: tableName: users columns: user_id: type: integer(12) primary: true username: type: string(20) password: type: string(20)extUser: tableName: users columns: user_id: type: integer(12) primary: true username: type: string(20)
I run this schema definition through Doctrine to generate the models for both objects. I would never let developers know about the intUser definition as that means they would have access to the password, so I tell them about extUser and the fields that are accessible.
For example, let’s assume I have a REST gateway set up at http://www.mywebsite.com/query
I send a DQL statement in a parameter to that URL:
http://www.mywebsite.com/query?q=SELECT * FROM extUser
And have it pass q to Doctrine, where would parse that query and return the appropriate records (only the username and id in this case). You can also employ Doctrine named queries to get closer to an actual FQL-like syntax.
Anyways, this is my theory on how I think I can quickly implement FQL-like functionality into my project, but I actually have not tested it yet.
What I also love about Doctrine is it has a really complex, but nice Backus-Nour Form definition on its website.
I’m really curious about how the Doctrine lexer works, and will probably explore more about how it parses the BNF later on as implanting languages in another languages is pretty neat.
Finally, yes, it works extremely well with Oracle (and MySQL as well; using it in another project), and the developers are extremely active in terms of getting bugs fixed. Compare this to Propel, where there’s only one or two devs and it takes forever to get things fixed.
Pathway Decision Making
This question has been in my mind for years. Where I used to live, there used to be a forked path that led to my car. Both paths were the same in terms of length, and both offered no additional benefits in terms of travel time or inconvenience. Both paths were exactly the same.
Think of a diamond, and you cannot cut straight through the middle of it, but must walk along side one of the sides. One vertex has me, then the opposite vertex has my car. I choose left, but why? Or, I choose to walk right, why?
There was this seminar I went to years back when I was at NASA, a neurobiologist who explained how our eyes and its visual acuity has an influence in decision making processes. When I think of this problem, I always think back to that lecture (although I barely remember most of the details about it now).
But what if our eyes lacked that bias? What exactly goes into a bias towards the left or right when both paths are opportunisticly the same?
Hi, I create problems.
For the past month, on and off, I’ve been thinking about problem-solving – there’s too much of it. Everyone’s a problem solver, but since when did you hear someone openly say that they create problems? I think the relationship between a problem and solution is cyclical – a problem is a consequence of a solution, and a solution is a consequence of a problem. The relationship is symbiotic, they cannot exist without each other.
When did problems become… a problem? How did the word carry such a negative connotation? I’ve thought of problem-making as a form of opportunity – because the problem exists or is created, there will more-than-likely be someone devoted to finding the solution. Without the problem, the need for a solution wouldn’t exist.
The entire thought about problems came to me one day when I was thinking about outrageous ideas for a novel (which I would never write due to my lack of ability to properly describe scenarios). I thought about having a villain as the main character. Following that, I thought about the cruelest and evilest villain possible, and came up with a person who had the ability to solve any kind of problem without regard to the possible consequences of the solution.
At first, the reader would have the impression that this was a wonderful gift to have – solving any kind of problem, and that the main character is this righteous person who wants to help the world. However, as the main character begins to solve every kind of problem, s/he fails to realize the consequences of the act – people begin to lose meaning within their lives because the problems they lived and existed to solve, were no longer available.
What happens is the world sees an increase in suicide rates. I know someone will call plot hole because those people can find other problems to work with. No. The main character is out to solve EVERYTHING, and is able to do it with extreme ease. The world populace deems the main character as a threat to humanity, and the story ends with his him solving this problem with his own death. I never decided what happened to the world after that, but I’d imagine anarchy as if the idea is to promote problem generation as a ’solution’, then the world would have to turn onto itself for people to strive to find solutions.
But that brings me to the question, why would a problem have to be chaotic, negative, so consequential?
That’s why I’m inclined to say that I’m a problem creator. There’s too many problem solvers out there already. I want to be the one that creates problems so opportunity lends itself to another’s future.
Or, I could be wrong completely. I recall situations where I have to solve a problem, and after solving that problem, there is no additional problems generated from the resolution. Maybe its kind of like division and multiplication:
Problem x Solution = Problem_New
Solution / Problem = undefined (in certain cases)
Facelist Improved: Facebook Autocompletion JQuery Plugin
I was evaluating all the available JQuery plugins to get a Facebook-like contact autocompletion functionality, and deemed the one by Ian Tearle to be the most complete available. However, most complete does not mean fully done, or bug free, and I learned this the hard way doing an initial implementation on a project I’m doing at work.
Spending all day with the lovely Firebug debugger and testing in both Firefox 3 and IE7, I can say I have it working the way I need it to. My version fixes the following issues:
- Not all results that are returned are displayed
- Duplicate contacts can be inserted
- When searching, the user is not notified that a search is being performed
- The ID was being displayed with the search results, this has now been removed
There is still one lingering issue: the values stored in the hidden field… the plugin needs the trailing comma at the end of the values in order to properly perform backspace deletion. It’s really a minor issue as long as you remember in your code that parses the value, that when exploding the commas, you’ll have to ignore the final array row as it will be blank or null.
I do not provide any support for my modified plugin, but feel free to leave comments if you hit bugs, and if I have time, I will fix them. I’m also hoping Ian will accept my changes so that I can just do a link to his page for the fix.
Ian Tearle’s Page for the Plugin
Edit: Yay, Ian accepted the changes, and they are now updated on the JQuery Plugin project page! I’ve updated my download link to point to the page.
