Audacity 3.2.0
CloudProjectsDatabase.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: GPL-2.0-or-later */
2/*!********************************************************************
3
4 Audacity: A Digital Audio Editor
5
6 CloudProjectsDatabase.h
7
8 Dmitry Vedenko
9
10**********************************************************************/
11#pragma once
12
13#include <mutex>
14#include <optional>
15#include <string>
16#include <vector>
17
19
20#include "CloudSyncDTO.h"
21
23{
24struct DBProjectData final
25{
26 std::string ProjectId;
27 std::string SnapshotId;
28 int64_t SavesCount = 0;
29 int64_t LastAudioPreview = 0;
30 std::string LocalPath;
31 int64_t LastModified = 0;
32 int64_t LastRead = 0;
33
34 bool FirstSyncDialogShown { false };
35
37 {
41 } SyncStatus = {};
42};
43
45{
46 std::string ProjectId;
47 std::string SnapshotId;
48 std::string ConfirmUrl;
49};
50
52{
53 std::string ProjectId;
54 std::string SnapshotId;
55
56 std::string UploadUrl;
57 std::string ConfirmUrl;
58 std::string FailUrl;
59
60 std::vector<uint8_t> BlobData;
61};
62
64{
65 std::string ProjectId;
66 std::string SnapshotId;
67
68 std::string UploadUrl;
69 std::string ConfirmUrl;
70 std::string FailUrl;
71
72 int64_t BlockId {};
74
75 std::string BlockHash;
76};
77
79{
82
83public:
84 static CloudProjectsDatabase& Get();
85
88
89 std::optional<DBProjectData>
90 GetProjectData(std::string_view projectId) const;
91 std::optional<DBProjectData>
92 GetProjectDataForPath(const std::string& projectPath) const;
93
94 std::vector<DBProjectData> GetCloudProjects() const;
95
96 void DeleteProject(std::string_view projectId);
97
98 bool
99 MarkProjectAsSynced(std::string_view projectId, std::string_view snapshotId);
100
102 std::string_view projectId, const SampleBlockIDSet& blockSet);
103
104 std::optional<std::string>
105 GetBlockHash(std::string_view projectId, int64_t blockId) const;
106
108 std::string_view projectId,
109 const std::vector<std::pair<int64_t, std::string>>& hashes);
110
111 bool UpdateProjectData(const DBProjectData& projectData);
112
113 bool IsFirstSyncDialogShown(std::string_view projectId) const;
114 void SetFirstSyncDialogShown(std::string_view projectId, bool shown = true);
115
116 std::string GetProjectUserSlug(std::string_view projectId);
117 void SetProjectUserSlug(std::string_view projectId, std::string_view slug);
118
119 bool IsProjectBlockLocked(std::string_view projectId, int64_t blockId) const;
120
121 void AddPendingSnapshot(const PendingSnapshotData& snapshotData);
123 std::string_view projectId, std::string_view snapshotId);
124 std::vector<PendingSnapshotData>
125 GetPendingSnapshots(std::string_view projectId) const;
126
127 void AddPendingProjectBlob(const PendingProjectBlobData& blobData);
129 std::string_view projectId, std::string_view snapshotId);
130 std::optional<PendingProjectBlobData> GetPendingProjectBlob(
131 std::string_view projectId, std::string_view snapshotId) const;
132
134 const std::vector<PendingProjectBlockData>& blockData);
136 std::string_view projectId, int64_t blockId);
138 std::string_view projectId, std::string_view snapshotId);
139 std::vector<PendingProjectBlockData> GetPendingProjectBlocks(
140 std::string_view projectId, std::string_view snapshotId);
141
142private:
143 std::optional<DBProjectData>
144 DoGetProjectData(const sqlite::Row& result) const;
145
146 std::optional<DBProjectData>
148
149 bool OpenConnection();
150 bool RunMigrations();
151
152 bool DeleteProject(sqlite::SafeConnection::Lock& connection, std::string_view projectId);
153
155 std::shared_ptr<sqlite::SafeConnection> mConnection;
156};
157} // namespace audacity::cloud::audiocom::sync
std::unordered_set< SampleBlockID > SampleBlockIDSet
Definition: CloudSyncDTO.h:27
std::optional< DBProjectData > DoGetProjectData(const sqlite::Row &result) const
void UpdateBlockHashes(std::string_view projectId, const std::vector< std::pair< int64_t, std::string > > &hashes)
std::optional< std::string > GetBlockHash(std::string_view projectId, int64_t blockId) const
bool UpdateProjectData(const DBProjectData &projectData)
void AddPendingSnapshot(const PendingSnapshotData &snapshotData)
void UpdateProjectBlockList(std::string_view projectId, const SampleBlockIDSet &blockSet)
bool MarkProjectAsSynced(std::string_view projectId, std::string_view snapshotId)
void SetProjectUserSlug(std::string_view projectId, std::string_view slug)
std::vector< PendingProjectBlockData > GetPendingProjectBlocks(std::string_view projectId, std::string_view snapshotId)
std::optional< DBProjectData > GetProjectData(std::string_view projectId) const
std::shared_ptr< sqlite::SafeConnection > mConnection
void SetFirstSyncDialogShown(std::string_view projectId, bool shown=true)
void RemovePendingProjectBlock(std::string_view projectId, int64_t blockId)
bool IsFirstSyncDialogShown(std::string_view projectId) const
void AddPendingProjectBlocks(const std::vector< PendingProjectBlockData > &blockData)
void AddPendingProjectBlob(const PendingProjectBlobData &blobData)
void RemovePendingSnapshot(std::string_view projectId, std::string_view snapshotId)
bool IsProjectBlockLocked(std::string_view projectId, int64_t blockId) const
std::vector< PendingSnapshotData > GetPendingSnapshots(std::string_view projectId) const
std::optional< DBProjectData > GetProjectDataForPath(const std::string &projectPath) const
void RemovePendingProjectBlob(std::string_view projectId, std::string_view snapshotId)
void RemovePendingProjectBlocks(std::string_view projectId, std::string_view snapshotId)
std::string GetProjectUserSlug(std::string_view projectId)
std::optional< PendingProjectBlobData > GetPendingProjectBlob(std::string_view projectId, std::string_view snapshotId) const
A class representing a row in a result set.
Definition: Statement.h:32
A class representing a result of a run operation.
Definition: Statement.h:99
enum audacity::cloud::audiocom::sync::DBProjectData::SyncStatusType SyncStatus