Query Builder

From OpenPSA Wiki

(Redirected from Midgard Query Builder)
Jump to: navigation, search

Query Builder is a feature in the Midgard Framework which is used to unify queries to the Midgard MySQL Database for optimization purposes. It only works with data structures based on MgdSchema. Under Midgard2, it is superseded by the QuerySelect API.

In MidCOM, Query Builder functionality is available via the MidCOM Database Abstraction Layer. Its individual classes provide a new_query_builder() method, and the class midcom_helper__dbfactory (accessible via the MidCOM PHP Superglobal) allows for generic access.

Query Builder always returns MgdSchema objects. If only specific bits of information are needed, Midgard Collector can be used instead.

Aside from attributes, Midgard Metadata, Attachment and Parameter constraints can be used when querying objects.

[edit] Example

// Instantiate Query Builder for an Article object
$qb = new MidgardQueryBuilder('midgard_article');
 
// List articles only in topic 123
$qb->add_constraint('topic', '=', 123);
 
// Run the query
$articles = $qb->execute();
 
// Show the articles
foreach ($articles as $article)
{
    echo $article->title . "<br />\n";
}

I hate my life but at least this makes it baerbale.

Personal tools