DependenciesTable.h (2911B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include "pch.h" 5 #include <winget/SQLiteWrapper.h> 6 #include <winget/SQLiteStatementBuilder.h> 7 #include <winget/Manifest.h> 8 9 namespace AppInstaller::Repository::Microsoft::Schema::V1_4 10 { 11 using namespace AppInstaller; 12 13 struct DependenciesTableColumnInfo 14 { 15 std::string_view Name; 16 }; 17 18 struct DependenciesTable 19 { 20 // Get the table name. 21 static std::string_view TableName(); 22 23 // Creates the table with named indices. 24 static void Create(SQLite::Connection& connection); 25 26 // Drops the table. 27 static void Drop(SQLite::Connection& connection); 28 29 static bool Exists(const SQLite::Connection& connection); 30 31 // Add the dependencies for the specific manifest. 32 static void AddDependencies(SQLite::Connection& connection, const Manifest::Manifest& manifest, SQLite::rowid_t manifestRowId); 33 34 // update the dependencies for the specific manifest. 35 static bool UpdateDependencies(SQLite::Connection& connection, const Manifest::Manifest& manifest, SQLite::rowid_t manifestRowId); 36 37 // Remove the dependencies by manifest id 38 static void RemoveDependencies(SQLite::Connection& connection, SQLite::rowid_t manifestRowId); 39 40 // Get dependencies the dependencies 41 static std::set<std::pair<SQLite::rowid_t, Utility::NormalizedString>> GetDependenciesByManifestRowId(const SQLite::Connection& connection, SQLite::rowid_t manifestRowId); 42 43 // Get dependencies by package id. 44 static std::vector<std::pair<SQLite::rowid_t, Utility::NormalizedString>> GetDependentsById(const SQLite::Connection& connection, AppInstaller::Manifest::string_t packageId); 45 46 // Check dependencies table consistency. 47 static bool CheckConsistency(const SQLite::Connection& connection, bool log); 48 49 // Checks if the row id is present in the column denoted by the value supplied. 50 static bool IsValueReferenced(const SQLite::Connection& connection, std::string_view valueName, SQLite::rowid_t valueRowId); 51 52 // The dependencies table and corresponding index are dropped. 53 static void PrepareForPackaging(SQLite::Connection& connection); 54 55 // Get all min version values of the given manifest's dependencies, used for VersionTable cleanup when updating or removing a manifest. 56 static std::vector<SQLite::rowid_t> GetDependenciesMinVersionsRowIdByManifestId(const SQLite::Connection& connection, SQLite::rowid_t manifestRowId); 57 58 // Get all dependencies with min versions in the dependencies table, used during consistency check. Returning a list of <PackageRowId, VersionString> pair. 59 static std::vector<std::pair<SQLite::rowid_t, Utility::NormalizedString>> GetAllDependenciesWithMinVersions(const SQLite::Connection& connection); 60 }; 61 }