Gold SQL
From RedBean
Gold SQL
Gold SQL is an extension to the SQL language for RedBean. You might find this a little frightning because often SQL language adpations tend to be completely new query languages; for instance like HQL or DQL. But that is no the case here. Gold SQL is pretty simple to learn and very useful. Imagine you are going to write a guestbook with RedBean. The guestbook contains a column for the message but not yet a title column, because that is a new feature you have come up with. Because RedBean is all about dynamic column generation, a query like:
Finder::where("guestbook"," title LIKE '%funny%' ");
Will not crash; instead it will simply return an empty record set. However consider the following query:
Finder::where("guestbook"," title LIKE '%funny%' OR message LIKE '%funny%'");
Once again the query will not fail, but because there is an OR-clause the query fails to return guestbook entries that have the word funny in their message content. To eliminate this inconsistency RedBean offers Gold SQL. By adding an @ in front of a column (or table-column combination) RedBean will first check whether the column exists; if not it will replace the column with NULL in fluid mode. The Gold SQL variant:
Finder::where("guestbook"," title LIKE '%funny%' OR @message LIKE '%funny%'");
will therefore work perfectly. Of course another solution is to change the code to add entries first, then test it and then alter the find-code. But if you are not sure just prefix columns with a @.

