Hi!
Here is my proposal of a new libzypp API for various metadata queries.
It should be useful for YaST package managers, zypper, YaST online
update and maybe others. Pease see attached QueryBuilder.h file and
comment on the design and usability.
QueryBuilder is meant to build an sqlite query for libzypp's metadata
cache database and to be used by
ResolvableQuery::query(QueryBuilder,ProcessingFunctor) function (or
other Query class) to do complex resolvable data queries. Result of
these queries will be processed by ProcessingFunctor (read on).
The reason to create such an API is to have a convenient API for coding
various kinds of user queries, so that apps using libzypp don't have to
code the functionality by themselves by traversing the resolvable pool.
And since we (will hopefully) have the new metadata cache database,
there is another reason: to make use of the database to speed up the
search and save memory requirements (don't load the pool, just query the
database). I would have to code it once in zypper anyway, so this way it
can be reused by others as well.
CODE EXAMPLE:
//////// code START /////////////////////////////////////////
bool is_regexp; // treat the search string as regexp?
bool search_summaries; // search also in summaries?
string search_string; // user given search string
Resolvable::Kind kind; // the result will be limited to this kind
<snip>
zypp::cache::QueryBuilder builder;
builder.addName(search_string, is_regexp);
if (search_summaries)
builder.addAttribute(zypp::cache::attrResObjectSummary(),
search_string, is_regexp);
builder.addKind(kind);
zypp::cache::ResolvableQuery resquery;
resquery.query(builder, processing_functor);
//////// code END /////////////////////////////////////////
(the functor is
function