A query used to lookup packages in a database.
More...
#include <pkg-query.hh>
|
| PkgQuery (const PkgQueryArgs ¶ms) |
|
| PkgQuery (const PkgQueryArgs ¶ms, std::vector< std::string > exportedColumns) |
|
std::string | str () const |
| Produce an unbound SQL statement from various member variables.
|
|
std::shared_ptr< sqlite3pp::query > | bind (sqlite3pp::database &pdb) const |
| Create a bound SQLite query ready for execution.
|
|
std::vector< row_id > | execute (sqlite3pp::database &pdb) const |
| Query a given database returning an ordered list of satisfactory Packages.id s.
|
|
|
void | clearBuilt () |
| Clear member PkgQuery member variables of any state from past initialization runs.
|
|
void | addSelection (std::string_view column) |
| Add a new column to the inner SELECT statement.
|
|
void | addOrderBy (std::string_view order) |
| Appends the ORDER BY block.
|
|
void | addWhere (std::string_view cond) |
| Appends the WHERE block with a new AND ( <COND> ) statement.
|
|
std::unordered_set< std::string > | filterSemvers (const std::unordered_set< std::string > &versions) const |
| Filter a set of semantic version numbers by the range indicated in the semvers member variable.
|
|
void | initMatch () |
| A helper of init() which handles match filtering/ranking.
|
|
void | initSubtrees () |
| A helper of init() which handles subtrees filtering/ranking.
|
|
void | initSystems () |
| A helper of init() which handles systems filtering/ranking.
|
|
void | initOrderBy () |
| A helper of init() which constructs the ORDER BY block.
|
|
void | init () |
| Translate floco::pkgdb::PkgQueryArgs parameters to a built SQL statement held in std::stringstream member variables.
|
|
A query used to lookup packages in a database.
This uses a combination of SQL statements and post processing with node-semver
to produce a list of satisfactory packages.
◆ addSelection()
void flox::pkgdb::PkgQuery::addSelection |
( |
std::string_view |
column | ) |
|
|
private |
Add a new column to the inner SELECT
statement.
These selections may be used internally for filtering and ordering rows, and are only exported in the final result if they are also listed in exportedColumns.
- Parameters
-
column | A column SELECT statement such as v_PackagesSearch.id or 0 AS foo . |
◆ bind()
std::shared_ptr< sqlite3pp::query > flox::pkgdb::PkgQuery::bind |
( |
sqlite3pp::database & |
pdb | ) |
const |
Create a bound SQLite query ready for execution.
This does NOT perform filtering by semver
which must be performed as a post-processing step. Unlike execute() this routine allows the caller to iterate over rows.
◆ clearBuilt()
void flox::pkgdb::PkgQuery::clearBuilt |
( |
| ) |
|
|
private |
Clear member PkgQuery member variables of any state from past initialization runs.
This is called by init before translating flox::pkgdb::PkgQueryArgs members.
◆ execute()
std::vector< row_id > flox::pkgdb::PkgQuery::execute |
( |
sqlite3pp::database & |
pdb | ) |
const |
Query a given database returning an ordered list of satisfactory Packages.id
s.
This performs semver
filtering.
◆ filterSemvers()
std::unordered_set< std::string > flox::pkgdb::PkgQuery::filterSemvers |
( |
const std::unordered_set< std::string > & |
versions | ) |
const |
|
private |
Filter a set of semantic version numbers by the range indicated in the semvers member variable.
If semvers is unset, return the original set as is.
◆ init()
void flox::pkgdb::PkgQuery::init |
( |
| ) |
|
|
private |
Translate floco::pkgdb::PkgQueryArgs parameters to a built SQL statement held in std::stringstream
member variables.
This is called by constructors, and should be called manually if any flox::pkgdb::PkgQueryArgs members are manually edited.
◆ str()
std::string flox::pkgdb::PkgQuery::str |
( |
| ) |
const |
Produce an unbound SQL statement from various member variables.
This must be run after init(). The returned string still needs to be processed to bind host parameters from binds before being executed.
- Returns
- An unbound SQL query string.
◆ binds
std::unordered_map<std::string, std::string> flox::pkgdb::PkgQuery::binds |
|
private |
( <PARAM-NAME>, <VALUE> )
pairs that need to be bound by SQLite3.
◆ exportedColumns
std::vector<std::string> flox::pkgdb::PkgQuery::exportedColumns = { "id", "semver" } |
|
private |
Final set of columns to expose after all filtering and ordering has been performed on temporary fields. The value *
may be used to export all fields.
This setting is only intended for use by unit tests, any columns other than id
and semver
may be changed without being reflected in normal pkgdb
semantic version updates.
◆ firstOrder
bool flox::pkgdb::PkgQuery::firstOrder = true |
|
private |
Indicates if orders is empty so we know whether to add separator.
◆ firstSelect
bool flox::pkgdb::PkgQuery::firstSelect = true |
|
private |
Indicates if selects is empty so we know whether to add separator.
◆ firstWhere
bool flox::pkgdb::PkgQuery::firstWhere = true |
|
private |
Indicates if wheres is empty so we know whether to add separator.
◆ orders
std::stringstream flox::pkgdb::PkgQuery::orders |
|
private |
Stream used to build up the ORDER BY
block.
◆ selects
std::stringstream flox::pkgdb::PkgQuery::selects |
|
private |
Stream used to build up the SELECT
block.
◆ wheres
std::stringstream flox::pkgdb::PkgQuery::wheres |
|
private |
Stream used to build up the WHERE
block.
The documentation for this class was generated from the following files: