Flox Package Database 1
CRUD Operations on Nix Package Metadata
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes | List of all members
flox::pkgdb::PkgQuery Class Reference

A query used to lookup packages in a database. More...

#include <pkg-query.hh>

Inheritance diagram for flox::pkgdb::PkgQuery:

Public Member Functions

 PkgQuery (const PkgQueryArgs &params)
 
 PkgQuery (const PkgQueryArgs &params, 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_idexecute (sqlite3pp::database &pdb) const
 Query a given database returning an ordered list of satisfactory Packages.ids.
 

Private Member Functions

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.
 

Private Attributes

std::stringstream selects
 
bool firstSelect = true
 
std::stringstream orders
 
bool firstOrder = true
 
std::stringstream wheres
 
bool firstWhere = true
 
std::unordered_map< std::string, std::string > binds
 
std::vector< std::string > exportedColumns = { "id", "semver" }
 

Detailed Description

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.

Member Function Documentation

◆ 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
columnA 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.ids.

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.

Member Data Documentation

◆ 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: