winget-cli

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

CheckpointDatabase.h (3190B)


      1 // Copyright (c) Microsoft Corporation.
      2 // Licensed under the MIT License.
      3 #pragma once
      4 #include <winget/SQLiteWrapper.h>
      5 #include <winget/SQLiteStorageBase.h>
      6 #include <winget/ManagedFile.h>
      7 
      8 namespace AppInstaller::Repository::Microsoft
      9 {
     10     namespace Schema
     11     {
     12         struct ICheckpointDatabase;
     13     }
     14 
     15     struct CheckpointDatabase : SQLite::SQLiteStorageBase
     16     {
     17         // An id that refers to a specific Checkpoint.
     18         using IdType = SQLite::rowid_t;
     19 
     20         CheckpointDatabase(const CheckpointDatabase&) = delete;
     21         CheckpointDatabase& operator=(const CheckpointDatabase&) = delete;
     22 
     23         CheckpointDatabase(CheckpointDatabase&&);
     24         CheckpointDatabase& operator=(CheckpointDatabase&&);
     25 
     26         // Create a new checkpoint database.
     27         static std::shared_ptr<CheckpointDatabase> CreateNew(const std::string& filePath, SQLite::Version version = SQLite::Version::Latest());
     28 
     29         // Opens an existing checkpoint database.
     30         static std::shared_ptr<CheckpointDatabase> Open(const std::string& filePath, OpenDisposition disposition = OpenDisposition::ReadWrite, Utility::ManagedFile&& indexFile = {});
     31 
     32         // Returns a value indicating whether the database is empty.
     33         bool IsEmpty();
     34 
     35         // Adds a new checkpoint name to the checkpoint table.
     36         IdType AddCheckpoint(std::string_view checkpointName);
     37 
     38         // Returns all checkpoint ids in descending (newest at the front) order.
     39         std::vector<IdType> GetCheckpointIds();
     40 
     41         // Returns a boolean value indicating a field exists for a checkpoint data type.
     42         bool HasDataField(IdType checkpointId, int type, const std::string& name);
     43 
     44         // Returns the available data types for a checkpoint id.
     45         std::vector<int> GetDataTypes(IdType checkpointId);
     46 
     47         // Returns the available field names for a checkpoint data.
     48         std::vector<std::string> GetDataFieldNames(IdType checkpointId, int dataType);
     49 
     50         // Sets the value(s) for a data type and field.
     51         void SetDataValue(IdType checkpointId, int dataType, const std::string& field, const std::vector<std::string>& values);
     52 
     53         // Updates the value(s) for a data type and field.
     54         void UpdateDataValue(IdType checkpointId, int dataType, const std::string& field, const std::vector<std::string>& values);
     55 
     56         // Gets a single value for a data type field.
     57         std::string GetDataFieldSingleValue(IdType checkpointId, int dataType, const std::string& field);
     58 
     59         // Gets multiple values for a data type field.
     60         std::vector<std::string> GetDataFieldMultiValue(IdType checkpointId, int dataType, const std::string& field);
     61 
     62         // Removes the value(s) for a data type.
     63         void RemoveDataType(IdType checkpointId, int dataType);
     64 
     65     private:
     66         // Constructor used to open an existing index.
     67         CheckpointDatabase(const std::string& target, SQLiteStorageBase::OpenDisposition disposition, Utility::ManagedFile&& indexFile);
     68 
     69         // Constructor used to create a new index.
     70         CheckpointDatabase(const std::string& target, SQLite::Version version);
     71 
     72         std::unique_ptr<Schema::ICheckpointDatabase> m_interface;
     73     };
     74 }