A better way to play with HQL in Orchard

In previous posts, I’ve shown how to query Orchard with straight HQL. However, I haven’t provided a good environment to run and debug these queries so far, because I didn’t have one. As a matter of facts, my method to build new queries has consisted in building queries from the projection module, putting a breakpoint at the end of the “DefaultHqlQuery.ToHql” method, and previewing the query in order to steal the query string built by the projection module. To debug, I’ve put the code in custom controller actions, and debugged the exceptions from VS. Not super-convenient.

Fortunately, this is over, thanks to a dirty little module I built yesterday night. It’s not exactly Sql Query Analyzer or NHProf, but it’s a convenient way to build and test your HQL queries within the context of Orchard.

Once you’ve installed the module and enabled the feature, a new “HQL Playground” menu entry appears in the admin. If you go there, you’ll see a text area where you can enter your query, some radio buttons to choose the type of results for the query, and a “Run”button:The HQL Playground

The result type choices are:

  • content ids: if you are building a query with a first column that consists of content item ids, choose this option, and the query results will be presented as a list of links to the content items.
  • records: if your query returns a list of columns, use this to present them in a table.
  • number: if the query is returning a count, or any scalar integer, use this options.

If your query causes an error, the module will do its best to present it in a legible manner:An error message

And that’s pretty much it. Nothing fancy here, but I hope it helps. I’m taking contributions by the way, so if you want to implement some nicer features, such as proper pagination, please do, I’ll be glad to take pull requests.

The module is available from the gallery:
http://gallery.orchardproject.net/List/Modules/Orchard.Module.Bleroy.HqlPlayground/1.8

And the pull-request-accepting Github repo is here:
https://github.com/bleroy/OrchardHqlPlayground

1 Comment

Comments have been disabled for this content.