PinTable.h (1852B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 #pragma once 4 #include <winget/SQLiteWrapper.h> 5 #include <winget/SQLiteStatementBuilder.h> 6 #include "Microsoft/Schema/IPinningIndex.h" 7 #include <string_view> 8 9 namespace AppInstaller::Repository::Microsoft::Schema::Pinning_V1_0 10 { 11 struct PinTable 12 { 13 // Get the table name. 14 static std::string_view TableName(); 15 16 // Creates the table with named indices. 17 static void Create(SQLite::Connection& connection); 18 19 // Gets the row ID for the pin, if it exists. 20 static std::optional<SQLite::rowid_t> GetIdByPinKey(SQLite::Connection& connection, const Pinning::PinKey& pinKey); 21 22 // Adds a new pin. Returns the row ID of the added pin. 23 static SQLite::rowid_t AddPin(SQLite::Connection& connection, const Pinning::Pin& pin); 24 25 // Updates an existing pin. 26 // Returns a value indicating whether there were any changes. 27 static bool UpdatePinById(SQLite::Connection& connection, SQLite::rowid_t pinId, const Pinning::Pin& pin); 28 29 // Removes a pin given its row ID. 30 static void RemovePinById(SQLite::Connection& connection, SQLite::rowid_t pinId); 31 32 // Gets a pin by its row ID if it exists. 33 // Used for testing 34 static std::optional<Pinning::Pin> GetPinById(SQLite::Connection& connection, const SQLite::rowid_t pinId); 35 36 // Gets all the currently existing pins. 37 static std::vector<Pinning::Pin> GetAllPins(SQLite::Connection& connection); 38 39 // Resets all pins from a given source, or from all sources if none is specified. 40 // Returns a value indicating whether there were any changes. 41 static bool ResetAllPins(SQLite::Connection& connection, std::string_view sourceId = {}); 42 }; 43 }