Add relative seeks to results, improve query API.

We now have a new query API for the database. The existing query
function has not yet been removed but will be in the future when the
changes fully migrate over.

We also have stored procedures for the new query functions, which are
highly optimized due to the new indexes built for the traits. Queries
should be extremely fast in most cases. The new query function also
support sorting by an attribute (both ascending and descending). All
comparisons are string-based.