Flox Package Database 1
CRUD Operations on Nix Package Metadata
|
A SQLite3 database used to cache derivation/package information about a single locked flake. More...
#include <write.hh>
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. | |
![]() | |
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_id > | getPackages (const PkgQueryArgs ¶ms) |
Return a list of Packages.id s 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 VIEW s 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. | |
![]() | |
void | loadLockedFlake () |
PkgDbReadOnly () | |
Dummy constructor required for child classes so that they can open databases in read-only mode. | |
Additional Inherited Members | |
![]() | |
Fingerprint | fingerprint |
std::filesystem::path | dbPath |
SQLiteDb | db |
struct LockedFlakeRef | lockedRef |
A SQLite3 database used to cache derivation/package information about a single locked flake.
|
inlineexplicit |
Opens an existing database.
Does NOT attempt to create a database if one does not exist.
dbPath | Absolute path to database file. |
|
inline |
Opens a DB directly by its fingerprint hash.
Does NOT attempt to create a database if one does not exist.
fingerprint | Unique hash associated with locked flake. |
dbPath | Absolute path to database file. |
|
inlineexplicit |
Opens a DB directly by its fingerprint hash.
Does NOT attempt to create a database if one does not exist.
fingerprint | Unique hash associated with locked flake. |
|
inline |
Opens a DB associated with a locked flake.
Creates database if one does not exist.
flake | Flake associated with the db. Used to write input metadata. |
dbPath | Absolute path to database file. |
|
inlineexplicit |
Opens a DB associated with a locked flake.
Creates database if one does not exist.
flake | Flake associated with the db. Used to write input metadata. |
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
.
path | An attribute path prefix such as packages.x86_64-linux or legacyPackages.aarch64-darwin.python3Packages . |
row_id
( unsigned 64bit int ) associated with path. 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
.
attrName | An attribute set field name. |
parent | The AttrSet.id containing attrName. The id 0 may be used to indicate that attrName has no parent attribute set. |
row_id
( unsigned 64bit int ) associated with attrName under parent. 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
.
description | A string describing a package. |
row_id
( unsigned 64bit int ) associated with description. 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.
parentId | The pathId associated with the parent path. |
attrName | The name of the attribute name to be added ( last element of the attribute path ). |
cursor | An attribute cursor to scrape data from. |
replace | Whether to replace/ignore existing rows. |
checkDrv | Whether to check isDerivation for cursor. Skipping this check is a slight optimization for cases where the caller has already checked themselves. |
Packages.id
value for the added package.
|
inline |
Execute a raw sqlite statement on the database.
stmt | String statement to execute. |
SQLITE_*
error code.
|
inline |
Execute raw sqlite statements on the database.
stmt | String statement to execute. |
SQLITE_*
error code. Scrape package definitions from an attribute set.
Adds any attributes marked with recurseForDerivatsions = true
to todo list.
syms | Symbol table from cursor evaluator. |
target | A tuple containing the attribute path to scrape, a cursor, and a SQLite row id. |
todo | Queue to add recurseForDerivations = true cursors to so they may be scraped by later invocations. |
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.
prefix | Attribute set prefix to be updated. |
done | Value to update done column to. |
void flox::pkgdb::PkgDb::setPrefixDone | ( | row_id | prefixId, |
bool | done | ||
) |
Update the done
column for an attribute set and all of its children recursively.
prefixId | AttrSets.id for the prefix to be updated. |
done | Value to update done column to. |
|
protected |
Update the database's VIEW
s schemas.
This deletes any existing VIEW
s and recreates them, and updates the DbVersions
row for pkgdb_views_schema
.