function collection($model, $clause, $duration = null)
{
    $key = "aql:get:{$model}:" . substr(md5(serialize($clause)), 0, 250);
    $collection = mem($key);
    if (!$collection) {
        $aql = aql::get_aql($model);
        // make minimal sql
        $aql_array = aql2array($aql);
        foreach ($aql_array as $i => $block) {
            unset($aql_array[$i]['objects']);
            unset($aql_array[$i]['fields']);
            unset($aql_array[$i]['subqueries']);
        }
        $sql_array = aql::make_sql_array($aql_array, aql::check_clause_array($aql_array, $clause));
        $minimal_sql = $sql_array['sql'];
        $r = sql($minimal_sql);
        $collection = array();
        while (!$r->EOF) {
            $collection[] = $r->Fields(0);
            $r->MoveNext();
        }
        #print_a($collection);
        mem($key, $collection, $duration);
    }
    if (is_array($collection)) {
        //print_a($collection);
        foreach ($collection as $id) {
            $obj = Model::get($model, $id);
            $ret[] = $obj->dataToArray();
        }
        return $ret;
    } else {
        return false;
    }
}