Drupal Query Designer

I pretty often use the Drupal viewer to create SQL, which I embed in my code. He understands the Drupal database schema well.

Is there a module that would give me this function, or can I exclude it from Views?

+7
drupal drupal-views
source share
4 answers

It would be great if the Views module was expanded to better support the use of programs, but until then you might want to look at one of my colleagues trying to create something similar to this: http://github.com/hugowetterberg/ query_builder

A related issue might be Project Services' attempt to provide Views data as a service, the effort we are now separating from it in our own module: http://drupal.org/node/709100 It might be worth it to take some level of programmatic access to Views .

Another example of a module that accesses Views programmatically is the Development Seeds Litenode: http://developmentseed.org/blog/2009/feb/4/litenode

Update 12/15/2010: EntityFieldQuery in Drupal 7 is almost the same as using Views programmatically to create queries - the difference is that EntityQueryBuilder only works with entities and fields, and also with the bonus that it can actually create queries against any storage used fields - for example. NoSQL database such as MongoDB. An example can be found here: http://drupal4hu.com/node/267

+3
source share

Although this is not an ideal way to do something, you can get presentation results as follows:

$view = views_get_view('search'); $view->set_display('main'); $view->set_items_per_page(0); $view->execute(); $items = array(); foreach ($view->result as $row) { $items[] = $row; } 

That way, whenever you modify a view request, you do not need to copy the code again. I agree that Views needs to be divided into api request building and user interface.

+1
source share

Yes, I suppose that it’s best to know which tables are used for the current field, because many modules (and much more in the views) have hook functions that provide some information about this field, table and type of connection with other tables,

You can also read the table and table schema via: http://drupal.org/project/schema

0
source share

I am curious why you used Views to build SQL and then not use Views?

When it comes to more complex things, such as many or many relationships, GROUP BY, COUNT, SUM, subqueries, etc., whatever the function requires, it's best to write it yourself (especially if the Contrib modules do not have view support, and you need more than a node table).

For me, when the views cannot be executed, I write a simple module that calls hook_menu (to register the paths) with a callback that executes the queries I need.

0
source share

All Articles