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

A SQLite3 database used to cache derivation/package information about a single locked flake. More...

#include <read.hh>

Inheritance diagram for flox::pkgdb::PkgDbReadOnly:
flox::pkgdb::PkgDb

Classes

struct  LockedFlakeRef
 Locked flake reference for database's flake. More...
 
struct  NoSuchDatabase
 Thrown when a database is not found. More...
 

Public Member Functions

 PkgDbReadOnly (std::string_view dbPath)
 Opens an existing database.
 
 PkgDbReadOnly (const Fingerprint &fingerprint, std::string_view dbPath)
 Opens a DB directly by its fingerprint hash.
 
 PkgDbReadOnly (const Fingerprint &fingerprint)
 Opens a DB directly by its fingerprint hash.
 
SqlVersions getDbVersion ()
 
row_id getAttrSetId (const flox::AttrPath &path)
 Get the AttrSet.id for a given path.
 
bool hasAttrSet (const flox::AttrPath &path)
 Check to see if database has and attribute set at path.
 
bool completedAttrSet (row_id row)
 Check to see if database has a complete list of packages under the prefix path.
 
bool completedAttrSet (const flox::AttrPath &path)
 Check to see if database has a complete list of packages under the prefix path.
 
flox::AttrPath getAttrSetPath (row_id row)
 Get the attribute path for a given AttrSet.id.
 
row_id getPackageId (const flox::AttrPath &path)
 Get the Packages.id for a given path.
 
flox::AttrPath getPackagePath (row_id row)
 Get the attribute path for a given Packages.id.
 
bool hasPackage (const flox::AttrPath &path)
 Check to see if database has a package at the attribute path path.
 
std::string getDescription (row_id descriptionId)
 Get the Description.description for a given Description.id.
 
std::vector< row_idgetPackages (const PkgQueryArgs &params)
 Return a list of Packages.ids for packages which satisfy a given set of requirements.
 
nlohmann::json getPackage (row_id row)
 Get metadata about a single package.
 
nlohmann::json getPackage (const flox::AttrPath &path)
 Get metadata about a single package.
 
nix::FlakeRef getLockedFlakeRef () const
 

Public Attributes

Fingerprint fingerprint
 
std::filesystem::path dbPath
 
SQLiteDb db
 
struct LockedFlakeRef lockedRef
 

Protected Member Functions

void loadLockedFlake ()
 
 PkgDbReadOnly ()
 Dummy constructor required for child classes so that they can open databases in read-only mode.
 

Private Member Functions

void init ()
 Open SQLite3 db connection at dbPath.
 

Detailed Description

A SQLite3 database used to cache derivation/package information about a single locked flake.

Constructor & Destructor Documentation

◆ PkgDbReadOnly() [1/4]

flox::pkgdb::PkgDbReadOnly::PkgDbReadOnly ( )
inlineprotected

Dummy constructor required for child classes so that they can open databases in read-only mode.

Does NOT attempt to create a database if one does not exist.

◆ PkgDbReadOnly() [2/4]

flox::pkgdb::PkgDbReadOnly::PkgDbReadOnly ( std::string_view  dbPath)
inlineexplicit

Opens an existing database.

Does NOT attempt to create a database if one does not exist.

Parameters
dbPathAbsolute path to database file.

◆ PkgDbReadOnly() [3/4]

flox::pkgdb::PkgDbReadOnly::PkgDbReadOnly ( const Fingerprint fingerprint,
std::string_view  dbPath 
)
inline

Opens a DB directly by its fingerprint hash.

Does NOT attempt to create a database if one does not exist.

Parameters
fingerprintUnique hash associated with locked flake.
dbPathAbsolute path to database file.

◆ PkgDbReadOnly() [4/4]

flox::pkgdb::PkgDbReadOnly::PkgDbReadOnly ( const Fingerprint fingerprint)
inlineexplicit

Opens a DB directly by its fingerprint hash.

Does NOT attempt to create a database if one does not exist.

Parameters
fingerprintUnique hash associated with locked flake.

Member Function Documentation

◆ completedAttrSet() [1/2]

bool flox::pkgdb::PkgDbReadOnly::completedAttrSet ( const flox::AttrPath path)

Check to see if database has a complete list of packages under the prefix path.

Parameters
pathAn attribute path prefix such as packages.x86_64-linux or legacyPackages.aarch64-darwin.python3Packages.
Returns
true iff the database has completely scraped the AttrSet at path.

◆ completedAttrSet() [2/2]

bool flox::pkgdb::PkgDbReadOnly::completedAttrSet ( row_id  row)

Check to see if database has a complete list of packages under the prefix path.

Parameters
rowThe AttrSets.id to lookup.
Returns
true iff the database has completely scraped the AttrSet at path.

◆ getAttrSetId()

row_id flox::pkgdb::PkgDbReadOnly::getAttrSetId ( const flox::AttrPath path)

Get the AttrSet.id for a given path.

Parameters
pathAn attribute path prefix such as packages.x86_64-linux or legacyPackages.aarch64-darwin.python3Packages.
Returns
A unique row_id ( unsigned 64bit int ) associated with path.

◆ getAttrSetPath()

flox::AttrPath flox::pkgdb::PkgDbReadOnly::getAttrSetPath ( row_id  row)

Get the attribute path for a given AttrSet.id.

Parameters
rowA unique row_id ( unsigned 64bit int ).
Returns
An attribute path prefix such as packages.x86_64-linux or legacyPackages.aarch64-darwin.python3Packages.

◆ getDbVersion()

SqlVersions flox::pkgdb::PkgDbReadOnly::getDbVersion ( )
Returns
The Package Database schema version.

◆ getDescription()

std::string flox::pkgdb::PkgDbReadOnly::getDescription ( row_id  descriptionId)

Get the Description.description for a given Description.id.

Parameters
descriptionIdThe row id to lookup.
Returns
A string describing a package.

◆ getPackage() [1/2]

nlohmann::json flox::pkgdb::PkgDbReadOnly::getPackage ( const flox::AttrPath path)

Get metadata about a single package.

Returns pname, version, description, broken, unfree, and license columns.

Parameters
rowAn attribute path to a package.
Returns
A JSON object containing information about a package.

◆ getPackage() [2/2]

nlohmann::json flox::pkgdb::PkgDbReadOnly::getPackage ( row_id  row)

Get metadata about a single package.

Returns pname, version, description, broken, unfree, and license columns.

Parameters
rowA Packages.id to lookup.
Returns
A JSON object containing information about a package.

◆ getPackageId()

row_id flox::pkgdb::PkgDbReadOnly::getPackageId ( const flox::AttrPath path)

Get the Packages.id for a given path.

Parameters
pathAn attribute path prefix such as packages.x86_64-linux.hello or legacyPackages.aarch64-darwin.python3Packages.pip.
Returns
A unique row_id ( unsigned 64bit int ) associated with path.

◆ getPackagePath()

flox::AttrPath flox::pkgdb::PkgDbReadOnly::getPackagePath ( row_id  row)

Get the attribute path for a given Packages.id.

Parameters
rowA unique row_id ( unsigned 64bit int ).
Returns
An attribute path such as packages.x86_64-linux.hello or legacyPackages.aarch64-darwin.python3Packages.pip.

◆ getPackages()

std::vector< row_id > flox::pkgdb::PkgDbReadOnly::getPackages ( const PkgQueryArgs &  params)

Return a list of Packages.ids for packages which satisfy a given set of requirements.

These results may be ordered flexibly based on various query parameters. TODO: document parameters effected by ordering.

◆ hasAttrSet()

bool flox::pkgdb::PkgDbReadOnly::hasAttrSet ( const flox::AttrPath path)

Check to see if database has and attribute set at path.

Parameters
pathAn attribute path prefix such as packages.x86_64-linux or legacyPackages.aarch64-darwin.python3Packages.
Returns
true iff the database has an AttrSet at path.

◆ hasPackage()

bool flox::pkgdb::PkgDbReadOnly::hasPackage ( const flox::AttrPath path)

Check to see if database has a package at the attribute path path.

Parameters
pathAn attribute path such as packages.x86_64-linux.hello or legacyPackages.aarch64-darwin.python3Packages.pip.
Returns
true iff the database has a rows in the Packages table with path as the absolute path.

◆ init()

void flox::pkgdb::PkgDbReadOnly::init ( )
private

Open SQLite3 db connection at dbPath.

Throw an error if no database exists.

◆ loadLockedFlake()

void flox::pkgdb::PkgDbReadOnly::loadLockedFlake ( )
protected

Set this PkgDb lockedRef fields from database metadata.

Member Data Documentation

◆ db

SQLiteDb flox::pkgdb::PkgDbReadOnly::db

SQLite3 database handle.

◆ dbPath

std::filesystem::path flox::pkgdb::PkgDbReadOnly::dbPath

Absolute path to database.

◆ fingerprint

Fingerprint flox::pkgdb::PkgDbReadOnly::fingerprint

Unique hash of associated flake.

◆ lockedRef

struct LockedFlakeRef flox::pkgdb::PkgDbReadOnly::lockedRef

Locked flake reference.


The documentation for this class was generated from the following files: