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

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

#include <write.hh>

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

Public Member Functions

 PkgDb (std::string_view dbPath)
 Opens an existing database.
 
 PkgDb (const Fingerprint &fingerprint, std::string_view dbPath)
 Opens a DB directly by its fingerprint hash.
 
 PkgDb (const Fingerprint &fingerprint)
 Opens a DB directly by its fingerprint hash.
 
 PkgDb (const nix::flake::LockedFlake &flake, std::string_view dbPath)
 Opens a DB associated with a locked flake.
 
 PkgDb (const nix::flake::LockedFlake &flake)
 Opens a DB associated with a locked flake.
 
sql_rc execute (const char *stmt)
 Execute a raw sqlite statement on the database.
 
sql_rc execute_all (const char *stmt)
 Execute raw sqlite statements on the database.
 
row_id addOrGetAttrSetId (const std::string &attrName, row_id parent=0)
 Get the AttrSet.id for a given child of the attribute set associated with parent if it exists, or insert a new row for path and return its id.
 
row_id addOrGetAttrSetId (const flox::AttrPath &path)
 Get the AttrSet.id for a given path if it exists, or insert a new row for path and return its pathId.
 
row_id addOrGetDescriptionId (const std::string &description)
 Get the Descriptions.id for a given string if it exists, or insert a new row for description and return its id.
 
row_id addPackage (row_id parentId, std::string_view attrName, const flox::Cursor &cursor, bool replace=false, bool checkDrv=true)
 Adds a package to the database.
 
void setPrefixDone (row_id prefixId, bool done)
 Update the done column for an attribute set and all of its children recursively.
 
void setPrefixDone (const flox::AttrPath &prefix, bool done)
 Update the done column for an attribute set and all of its children recursively.
 
void scrape (nix::SymbolTable &syms, const Target &target, Todos &todo)
 Scrape package definitions from an attribute set.
 
- Public Member Functions inherited from flox::pkgdb::PkgDbReadOnly
 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
 

Protected Member Functions

void initTables ()
 Create tables in database if they do not exist.
 
void initViews ()
 Create views in database if they do not exist.
 
void updateViews ()
 Update the database's VIEWs schemas.
 
void initVersions ()
 Create DbVersions rows if they do not exist.
 
void init ()
 Create/update tables/views schema in database. Create tables if they do not exist. Create views in database if they do not exist or update them. Create DbVersions rows if they do not exist.
 
void writeInput ()
 Write this PkgDb lockedRef and fingerprint fields to database metadata.
 
- Protected Member Functions inherited from flox::pkgdb::PkgDbReadOnly
void loadLockedFlake ()
 
 PkgDbReadOnly ()
 Dummy constructor required for child classes so that they can open databases in read-only mode.
 

Additional Inherited Members

- Public Attributes inherited from flox::pkgdb::PkgDbReadOnly
Fingerprint fingerprint
 
std::filesystem::path dbPath
 
SQLiteDb db
 
struct LockedFlakeRef lockedRef
 

Detailed Description

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

Constructor & Destructor Documentation

◆ PkgDb() [1/5]

flox::pkgdb::PkgDb::PkgDb ( 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.

◆ PkgDb() [2/5]

flox::pkgdb::PkgDb::PkgDb ( 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.

◆ PkgDb() [3/5]

flox::pkgdb::PkgDb::PkgDb ( 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.

◆ PkgDb() [4/5]

flox::pkgdb::PkgDb::PkgDb ( const nix::flake::LockedFlake &  flake,
std::string_view  dbPath 
)
inline

Opens a DB associated with a locked flake.

Creates database if one does not exist.

Parameters
flakeFlake associated with the db. Used to write input metadata.
dbPathAbsolute path to database file.

◆ PkgDb() [5/5]

flox::pkgdb::PkgDb::PkgDb ( const nix::flake::LockedFlake &  flake)
inlineexplicit

Opens a DB associated with a locked flake.

Creates database if one does not exist.

Parameters
flakeFlake associated with the db. Used to write input metadata.

Member Function Documentation

◆ addOrGetAttrSetId() [1/2]

row_id flox::pkgdb::PkgDb::addOrGetAttrSetId ( const flox::AttrPath path)

Get the AttrSet.id for a given path if it exists, or insert a new row for path and return its pathId.

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.

◆ addOrGetAttrSetId() [2/2]

row_id flox::pkgdb::PkgDb::addOrGetAttrSetId ( const std::string &  attrName,
row_id  parent = 0 
)

Get the AttrSet.id for a given child of the attribute set associated with parent if it exists, or insert a new row for path and return its id.

Parameters
attrNameAn attribute set field name.
parentThe AttrSet.id containing attrName. The id 0 may be used to indicate that attrName has no parent attribute set.
Returns
A unique row_id ( unsigned 64bit int ) associated with attrName under parent.

◆ addOrGetDescriptionId()

row_id flox::pkgdb::PkgDb::addOrGetDescriptionId ( const std::string &  description)

Get the Descriptions.id for a given string if it exists, or insert a new row for description and return its id.

Parameters
descriptionA string describing a package.
Returns
A unique row_id ( unsigned 64bit int ) associated with description.

◆ addPackage()

row_id flox::pkgdb::PkgDb::addPackage ( row_id  parentId,
std::string_view  attrName,
const flox::Cursor cursor,
bool  replace = false,
bool  checkDrv = true 
)

Adds a package to the database.

Parameters
parentIdThe pathId associated with the parent path.
attrNameThe name of the attribute name to be added ( last element of the attribute path ).
cursorAn attribute cursor to scrape data from.
replaceWhether to replace/ignore existing rows.
checkDrvWhether to check isDerivation for cursor. Skipping this check is a slight optimization for cases where the caller has already checked themselves.
Returns
The Packages.id value for the added package.

◆ execute()

sql_rc flox::pkgdb::PkgDb::execute ( const char *  stmt)
inline

Execute a raw sqlite statement on the database.

Parameters
stmtString statement to execute.
Returns
SQLITE_* error code.

◆ execute_all()

sql_rc flox::pkgdb::PkgDb::execute_all ( const char *  stmt)
inline

Execute raw sqlite statements on the database.

Parameters
stmtString statement to execute.
Returns
SQLITE_* error code.

◆ scrape()

void flox::pkgdb::PkgDb::scrape ( nix::SymbolTable &  syms,
const Target target,
Todos todo 
)

Scrape package definitions from an attribute set.

Adds any attributes marked with recurseForDerivatsions = true to todo list.

Parameters
symsSymbol table from cursor evaluator.
targetA tuple containing the attribute path to scrape, a cursor, and a SQLite row id.
todoQueue to add recurseForDerivations = true cursors to so they may be scraped by later invocations.

◆ setPrefixDone() [1/2]

void flox::pkgdb::PkgDb::setPrefixDone ( const flox::AttrPath prefix,
bool  done 
)

Update the done column for an attribute set and all of its children recursively.

Parameters
prefixAttribute set prefix to be updated.
doneValue to update done column to.

◆ setPrefixDone() [2/2]

void flox::pkgdb::PkgDb::setPrefixDone ( row_id  prefixId,
bool  done 
)

Update the done column for an attribute set and all of its children recursively.

Parameters
prefixIdAttrSets.id for the prefix to be updated.
doneValue to update done column to.

◆ updateViews()

void flox::pkgdb::PkgDb::updateViews ( )
protected

Update the database's VIEWs schemas.

This deletes any existing VIEWs and recreates them, and updates the DbVersions row for pkgdb_views_schema.


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