Storing queries for later - adampatterson/Tentacle GitHub Wiki

It is possible to store SELECT, UPDATE, and DELETE queries for use at a later time:

// Select the table
$table = db('mytable');

// Construct the query
$query = $table->select('*')
           ->where('id','<=',10)
           ->order_by('id','DESC');

// Later... Execute the query
$query->execute();

Notice that we left the execute() method off of the query when we constructed it. Then later to run that query we simply use the execute() method on the $query object.

Note that you cannot store shorthand SELECT and DELETE queries for later use. For example you could not store this query:

// Select the table
$table = db('mytable');

$table->select('name','!=','Evan');

But you could store the full sized version of that query:

// Select the table
$table = db('mytable');

$query = $table->select('*')
    ->where('name','!=','Evan');