@@ -6,125 +6,161 @@ std::optional<EngineEntry> DatabaseService::UpsertEngine(
66 const std::string& api_key, const std::string& url,
77 const std::string& version, const std::string& variant,
88 const std::string& status, const std::string& metadata) {
9+ std::lock_guard<std::mutex> l (mtx_);
910 return cortex::db::Engines ().UpsertEngine (engine_name, type, api_key, url,
1011 version, variant, status, metadata);
1112}
1213
1314std::optional<std::vector<EngineEntry>> DatabaseService::GetEngines () const {
15+ std::lock_guard<std::mutex> l (mtx_);
1416 return cortex::db::Engines ().GetEngines ();
1517}
1618
1719std::optional<EngineEntry> DatabaseService::GetEngineById (int id) const {
20+ std::lock_guard<std::mutex> l (mtx_);
1821 return cortex::db::Engines ().GetEngineById (id);
1922}
2023
2124std::optional<EngineEntry> DatabaseService::GetEngineByNameAndVariant (
2225 const std::string& engine_name,
2326 const std::optional<std::string> variant) const {
27+ std::lock_guard<std::mutex> l (mtx_);
2428 return cortex::db::Engines ().GetEngineByNameAndVariant (engine_name, variant);
2529}
2630
2731std::optional<std::string> DatabaseService::DeleteEngineById (int id) {
32+ std::lock_guard<std::mutex> l (mtx_);
2833 return cortex::db::Engines ().DeleteEngineById (id);
2934}
3035// end engines
3136
3237// begin file
3338cpp::result<std::vector<OpenAi::File>, std::string>
3439DatabaseService::GetFileList () const {
40+ std::lock_guard<std::mutex> l (mtx_);
3541 return cortex::db::File ().GetFileList ();
3642}
3743
3844cpp::result<OpenAi::File, std::string> DatabaseService::GetFileById (
3945 const std::string& file_id) const {
46+ std::lock_guard<std::mutex> l (mtx_);
4047 return cortex::db::File ().GetFileById (file_id);
4148}
4249
4350cpp::result<void , std::string> DatabaseService::AddFileEntry (
4451 OpenAi::File& file) {
52+ std::lock_guard<std::mutex> l (mtx_);
4553 return cortex::db::File ().AddFileEntry (file);
4654}
4755
4856cpp::result<void , std::string> DatabaseService::DeleteFileEntry (
4957 const std::string& file_id) {
58+ std::lock_guard<std::mutex> l (mtx_);
5059 return cortex::db::File ().DeleteFileEntry (file_id);
5160}
5261// end file
5362
5463// begin hardware
5564cpp::result<std::vector<HardwareEntry>, std::string>
5665DatabaseService::LoadHardwareList () const {
66+ std::lock_guard<std::mutex> l (mtx_);
5767 return cortex::db::Hardware ().LoadHardwareList ();
5868}
5969
6070cpp::result<bool , std::string> DatabaseService::AddHardwareEntry (
6171 const HardwareEntry& new_entry) {
72+ std::lock_guard<std::mutex> l (mtx_);
6273 return cortex::db::Hardware ().AddHardwareEntry (new_entry);
6374}
6475
76+ bool DatabaseService::HasHardwareEntry (const std::string& id) {
77+ std::lock_guard<std::mutex> l (mtx_);
78+ return cortex::db::Hardware ().HasHardwareEntry (id);
79+ }
80+
6581cpp::result<bool , std::string> DatabaseService::UpdateHardwareEntry (
6682 const std::string& id, const HardwareEntry& updated_entry) {
83+ std::lock_guard<std::mutex> l (mtx_);
6784 return cortex::db::Hardware ().UpdateHardwareEntry (id, updated_entry);
6885}
6986
7087cpp::result<bool , std::string> DatabaseService::DeleteHardwareEntry (
7188 const std::string& id) {
89+ std::lock_guard<std::mutex> l (mtx_);
7290 return cortex::db::Hardware ().DeleteHardwareEntry (id);
7391}
92+
93+ cpp::result<bool , std::string> DatabaseService::UpdateHardwareEntry (
94+ const std::string& id, int hw_id, int sw_id) const {
95+ std::lock_guard<std::mutex> l (mtx_);
96+ return cortex::db::Hardware ().UpdateHardwareEntry (id, hw_id, sw_id);
97+ }
7498// end hardware
7599
76100// begin models
77101cpp::result<std::vector<ModelEntry>, std::string>
78102DatabaseService::LoadModelList () const {
103+ std::lock_guard<std::mutex> l (mtx_);
79104 return cortex::db::Models ().LoadModelList ();
80105}
81106
82107cpp::result<ModelEntry, std::string> DatabaseService::GetModelInfo (
83108 const std::string& identifier) const {
109+ std::lock_guard<std::mutex> l (mtx_);
84110 return cortex::db::Models ().GetModelInfo (identifier);
85111}
86112
87113cpp::result<bool , std::string> DatabaseService::AddModelEntry (
88114 ModelEntry new_entry) {
115+ std::lock_guard<std::mutex> l (mtx_);
89116 return cortex::db::Models ().AddModelEntry (new_entry);
90117}
91118
92119cpp::result<bool , std::string> DatabaseService::UpdateModelEntry (
93120 const std::string& identifier, const ModelEntry& updated_entry) {
121+ std::lock_guard<std::mutex> l (mtx_);
94122 return cortex::db::Models ().UpdateModelEntry (identifier, updated_entry);
95123}
96124
97125cpp::result<bool , std::string> DatabaseService::DeleteModelEntry (
98126 const std::string& identifier) {
127+ std::lock_guard<std::mutex> l (mtx_);
99128 return cortex::db::Models ().DeleteModelEntry (identifier);
100129}
101130
102131cpp::result<bool , std::string> DatabaseService::DeleteModelEntryWithOrg (
103132 const std::string& src) {
133+ std::lock_guard<std::mutex> l (mtx_);
104134 return cortex::db::Models ().DeleteModelEntryWithOrg (src);
105135}
106136
107137cpp::result<bool , std::string> DatabaseService::DeleteModelEntryWithRepo (
108138 const std::string& src) {
139+
140+ std::lock_guard<std::mutex> l (mtx_);
109141 return cortex::db::Models ().DeleteModelEntryWithRepo (src);
110142}
111143
112144cpp::result<std::vector<std::string>, std::string>
113145DatabaseService::FindRelatedModel (const std::string& identifier) const {
146+ std::lock_guard<std::mutex> l (mtx_);
114147 return cortex::db::Models ().FindRelatedModel (identifier);
115148}
116149
117150bool DatabaseService::HasModel (const std::string& identifier) const {
151+ std::lock_guard<std::mutex> l (mtx_);
118152 return cortex::db::Models ().HasModel (identifier);
119153}
120154
121155cpp::result<std::vector<ModelEntry>, std::string> DatabaseService::GetModels (
122156 const std::string& model_src) const {
157+ std::lock_guard<std::mutex> l (mtx_);
123158 return cortex::db::Models ().GetModels (model_src);
124159}
125160
126161cpp::result<std::vector<ModelEntry>, std::string>
127162DatabaseService::GetModelSources () const {
163+ std::lock_guard<std::mutex> l (mtx_);
128164 return cortex::db::Models ().GetModelSources ();
129165}
130166// end models
0 commit comments