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

A RegistryInput that opens a PkgDb associated with a flake. More...

#include <input.hh>

Inheritance diagram for flox::pkgdb::PkgDbInput:
flox::FloxFlakeInput flox::RegistryInput flox::InputPreferences

Classes

struct  db_path_tag
 Tag used to disambiguate construction with database path and cache directory path. More...
 

Public Member Functions

 PkgDbInput (nix::ref< nix::Store > &store, const RegistryInput &input, std::filesystem::path dbPath, const db_path_tag &, const std::string &name="")
 Construct a PkgDbInput from a RegistryInput and a path to the database.
 
 PkgDbInput (nix::ref< nix::Store > &store, const RegistryInput &input, const std::filesystem::path &cacheDir=getPkgDbCachedir(), const std::string &name="")
 Construct a PkgDbInput from a RegistryInput and a path to the directory where the database should be cached.
 
nix::ref< PkgDbReadOnlygetDbReadOnly () const
 
nix::ref< PkgDbgetDbReadWrite ()
 Open a read/write database connection if one is not open, and return a handle.
 
void closeDbReadWrite ()
 Close the read/write database connection if it is open.
 
std::filesystem::path getDbPath () const
 
void scrapePrefix (const flox::AttrPath &prefix)
 Ensure that an attribute path prefix has been scraped.
 
void scrapeSystems (const std::vector< System > &systems)
 Scrape all prefixes indicated by InputPreferences for systems.
 
void setName (std::string_view name)
 Add/set a shortname for this input.
 
std::string getNameOrURL ()
 Get an identifier for this input.
 
nlohmann::json getRowJSON (row_id row)
 Get a JSON representation of a row in the database.
 
- Public Member Functions inherited from flox::FloxFlakeInput
 FloxFlakeInput (const nix::ref< nix::Store > &store, const RegistryInput &input)
 Construct a flox::FloxFlakeInput from a nix store connection and flox::RegistryInput.
 
nix::ref< FloxFlakegetFlake ()
 Get a handle for a flake with a nix evaluator.
 
const std::vector< Subtree > & getSubtrees ()
 Get a list of enabled subtrees.
 
RegistryInput getLockedInput ()
 
- Public Member Functions inherited from flox::RegistryInput
 RegistryInput (const std::optional< std::vector< Subtree > > &subtrees, const nix::FlakeRef &from)
 
 RegistryInput (const nix::FlakeRef &from)
 
nix::ref< nix::FlakeRef > getFlakeRef () const
 Get the flake reference associated with this input.
 
bool operator== (const RegistryInput &other) const
 
bool operator!= (const RegistryInput &other) const
 
- Public Member Functions inherited from flox::InputPreferences
 InputPreferences (const InputPreferences &)=default
 
 InputPreferences (InputPreferences &&)=default
 
InputPreferencesoperator= (const InputPreferences &)=default
 
InputPreferencesoperator= (InputPreferences &&)=default
 
 InputPreferences (const std::optional< std::vector< Subtree > > &subtrees)
 
virtual void clear ()
 Reset to default state.
 
pkgdb::PkgQueryArgs & fillPkgQueryArgs (pkgdb::PkgQueryArgs &pqa) const
 Fill a flox::pkgdb::PkgQueryArgs struct with preferences to lookup packages filtered by InputPreferences requirements.
 
void merge (const InputPreferences &overrides)
 Merges this flox::InputPreferences with another InputPreferences, overriding values in this InputPreferences with those from the other InputPreferences.
 
bool operator== (const InputPreferences &other) const
 
bool operator!= (const InputPreferences &other) const
 

Private Member Functions

void init ()
 Prepare database handles for use.
 

Private Attributes

std::filesystem::path dbPath
 
std::shared_ptr< PkgDbReadOnlydbRO
 
std::shared_ptr< PkgDbdbRW
 
std::optional< std::string > name
 

Additional Inherited Members

- Public Attributes inherited from flox::RegistryInput
std::shared_ptr< nix::FlakeRef > from
 
- Public Attributes inherited from flox::InputPreferences
std::optional< std::vector< Subtree > > subtrees
 

Detailed Description

A RegistryInput that opens a PkgDb associated with a flake.

Constructor & Destructor Documentation

◆ PkgDbInput() [1/2]

flox::pkgdb::PkgDbInput::PkgDbInput ( nix::ref< nix::Store > &  store,
const RegistryInput input,
std::filesystem::path  dbPath,
const db_path_tag ,
const std::string &  name = "" 
)
inline

Construct a PkgDbInput from a RegistryInput and a path to the database.

Parameters
storeA nix store connection.
inputA RegistryInput.
dbPathPath to the database.
db_path_tagTag used to disambiguate this constructor from other constructor which takes a cache directory.
nameName of the input ( empty implies N/A ).

◆ PkgDbInput() [2/2]

flox::pkgdb::PkgDbInput::PkgDbInput ( nix::ref< nix::Store > &  store,
const RegistryInput input,
const std::filesystem::path &  cacheDir = getPkgDbCachedir(),
const std::string &  name = "" 
)
inline

Construct a PkgDbInput from a RegistryInput and a path to the directory where the database should be cached.

Parameters
storeA nix store connection.
inputA RegistryInput.
cacheDirPath to the directory where the database should be cached.
nameName of the input ( empty implies N/A ).

Member Function Documentation

◆ getDbPath()

std::filesystem::path flox::pkgdb::PkgDbInput::getDbPath ( ) const
inline
Returns
Filesystem path to the flake's package database.

◆ getDbReadOnly()

nix::ref< PkgDbReadOnly > flox::pkgdb::PkgDbInput::getDbReadOnly ( ) const
inline
Returns
The read-only database connection handle.

◆ getNameOrURL()

std::string flox::pkgdb::PkgDbInput::getNameOrURL ( )
inline

Get an identifier for this input.

Returns
The shortname of this input, or its locked flake-ref.

◆ init()

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

Prepare database handles for use.

Upon exiting a compatible read-only database connection will be open with the LockedFlake and DbVersions tables created.

If the database does not exist it will be created.

If the database VIEWs schemas are out of date they will be updated.

If the database TABLEs schemas are out of date the database will be deleted and recreated.

◆ scrapePrefix()

void flox::pkgdb::PkgDbInput::scrapePrefix ( const flox::AttrPath prefix)

Ensure that an attribute path prefix has been scraped.

If the prefix has been scraped no writes are performed, but if the prefix has not been scraped a read/write connection will be used.

If a read/write connection is already open when scrapePrefix is called it will remain open, but if the connection is opened by scrapePrefix it will be closed after scraping is completed.

Parameters
prefixAttribute path to scrape.

◆ scrapeSystems()

void flox::pkgdb::PkgDbInput::scrapeSystems ( const std::vector< System > &  systems)

Scrape all prefixes indicated by InputPreferences for systems.

Parameters
systemsSystems to be scraped.

Member Data Documentation

◆ dbPath

std::filesystem::path flox::pkgdb::PkgDbInput::dbPath
private

Path to the flake's pkgdb SQLite3 file.

◆ dbRO

std::shared_ptr<PkgDbReadOnly> flox::pkgdb::PkgDbInput::dbRO
private

A read-only database connection that remains open for the lifetime of this object.

◆ dbRW

std::shared_ptr<PkgDb> flox::pkgdb::PkgDbInput::dbRW
private

A read/write database connection that may be opened and closed as needed using getDbReadWrite and closeDbReadWrite.

◆ name

std::optional<std::string> flox::pkgdb::PkgDbInput::name
private

The name of the input, used to emit output with shortnames.


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