24using Target = std::tuple<flox::AttrPath, flox::Cursor, row_id>;
27using Todos = std::queue<Target, std::list<Target>>;
104 if ( ! std::filesystem::exists( this->dbPath ) )
109 this->
db.connect( this->dbPath.c_str(),
110 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE );
126 if ( ! std::filesystem::exists( this->dbPath ) )
131 this->
db.connect( this->dbPath.c_str(),
132 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE );
154 PkgDb(
const nix::flake::LockedFlake & flake, std::string_view
dbPath )
158 this->
db.connect( this->dbPath.c_str(),
159 SQLITE_OPEN_READWRITE | SQLITE_OPEN_CREATE );
162 = { flake.flake.lockedRef.to_string(),
163 nix::fetchers::attrsToJSON( flake.flake.lockedRef.toAttrs() ) };
173 explicit PkgDb(
const nix::flake::LockedFlake & flake )
193 sqlite3pp::command cmd( this->
db, stmt );
194 return cmd.execute();
205 sqlite3pp::command cmd( this->
db, stmt );
206 return cmd.execute_all();
265 std::string_view attrName,
267 bool replace =
false,
268 bool checkDrv =
true );
A SQLite3 database used to cache derivation/package information about a single locked flake.
Definition: read.hh:135
Fingerprint fingerprint
Definition: read.hh:141
void loadLockedFlake()
Definition: read.cc:101
std::filesystem::path dbPath
Definition: read.hh:142
struct LockedFlakeRef lockedRef
Definition: read.hh:152
SQLiteDb db
Definition: read.hh:143
A SQLite3 database used to cache derivation/package information about a single locked flake.
Definition: write.hh:37
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.
Definition: write.cc:267
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 retu...
Definition: write.cc:226
PkgDb(const nix::flake::LockedFlake &flake, std::string_view dbPath)
Opens a DB associated with a locked flake.
Definition: write.hh:154
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,...
Definition: write.cc:182
void scrape(nix::SymbolTable &syms, const Target &target, Todos &todo)
Scrape package definitions from an attribute set.
Definition: write.cc:406
PkgDb(const Fingerprint &fingerprint)
Opens a DB directly by its fingerprint hash.
Definition: write.hh:143
PkgDb(std::string_view dbPath)
Opens an existing database.
Definition: write.hh:101
void initVersions()
Create DbVersions rows if they do not exist.
Definition: write.cc:122
void writeInput()
Write this PkgDb lockedRef and fingerprint fields to database metadata.
Definition: write.cc:159
void setPrefixDone(row_id prefixId, bool done)
Update the done column for an attribute set and all of its children recursively.
Definition: write.cc:365
void initViews()
Create views in database if they do not exist.
Definition: write.cc:26
PkgDb(const nix::flake::LockedFlake &flake)
Opens a DB associated with a locked flake.
Definition: write.hh:173
void init()
Create/update tables/views schema in database. Create tables if they do not exist....
Definition: write.cc:144
PkgDb(const Fingerprint &fingerprint, std::string_view dbPath)
Opens a DB directly by its fingerprint hash.
Definition: write.hh:122
sql_rc execute_all(const char *stmt)
Execute raw sqlite statements on the database.
Definition: write.hh:203
void initTables()
Create tables in database if they do not exist.
Definition: write.cc:83
sql_rc execute(const char *stmt)
Execute a raw sqlite statement on the database.
Definition: write.hh:191
void updateViews()
Update the database's VIEWs schemas.
Definition: write.cc:40
Interfaces for caching package metadata in SQLite3 databases.
Definition: command.cc:44
std::filesystem::path genPkgDbName(const Fingerprint &fingerprint, const std::filesystem::path &cacheDir)
Get an absolute path to the ‘PkgDb’ for a given fingerprint hash.
Definition: read.cc:76
std::tuple< flox::AttrPath, flox::Cursor, row_id > Target
A set of arguments used by flox::pkgdb::PkgDb::scrape.
Definition: write.hh:24
nix::flake::Fingerprint Fingerprint
Definition: read.hh:93
uint64_t row_id
Definition: pkg-query.hh:48
int sql_rc
Definition: read.hh:95
std::queue< Target, std::list< Target > > Todos
A queue of flox::pkgdb::Target to be completed.
Definition: write.hh:27
nix::ref< nix::eval_cache::AttrCursor > Cursor
A non-nullptr std::shared_ptr<nix::eval_cache::AttrCursor>.
Definition: types.hh:50
std::vector< std::string > AttrPath
A list of key names addressing a location in a nested JSON-like object.
Definition: types.hh:33
Interfaces for reading a SQLite3 package set database.
Thrown when a database is not found.
Definition: read.hh:161