File indexing completed on 2024-05-19 05:42:12
0001 // ct_lvtmdb_soci_writer.h -*-C++-*- 0002 0003 /* 0004 // Copyright 2023 Codethink Ltd <codethink@codethink.co.uk> 0005 // SPDX-License-Identifier: Apache-2.0 0006 // 0007 // Licensed under the Apache License, Version 2.0 (the "License"); 0008 // you may not use this file except in compliance with the License. 0009 // You may obtain a copy of the License at 0010 // 0011 // http://www.apache.org/licenses/LICENSE-2.0 0012 // 0013 // Unless required by applicable law or agreed to in writing, software 0014 // distributed under the License is distributed on an "AS IS" BASIS, 0015 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 0016 // See the License for the specific language governing permissions and 0017 // limitations under the License. 0018 */ 0019 0020 #ifndef CT_LVTMDB_SOCI_WRITER_H 0021 #define CT_LVTMDB_SOCI_WRITER_H 0022 0023 #include <filesystem> 0024 #include <lvtmdb_export.h> 0025 #include <result/result.hpp> 0026 #include <soci/soci.h> 0027 0028 namespace Codethink::lvtmdb { 0029 class ObjectStore; 0030 0031 /* Usage: 0032 * LvtMDb::ObjectStore obj; // populated with information. 0033 * SociWriter writer; 0034 * writer.createOrOpen("/some/path.db"); 0035 * obj.writeToDatabase(writer); 0036 */ 0037 class LVTMDB_EXPORT SociWriter { 0038 public: 0039 friend class ObjectStore; 0040 0041 SociWriter(); 0042 0043 bool updateDbSchema(const std::string& db, const std::string& schemaPath); 0044 bool createOrOpen(const std::string& path, const std::string& schemaPath = "codebase_db.sql"); 0045 /* this needs to be std::string because the 0046 * path can also be ":memory:" - we transform 0047 * it to an actual std::filesystem::path when 0048 * it's not. 0049 */ 0050 0051 private: 0052 void writeFrom(const ObjectStore& store); 0053 // Acessor to the object store. 0054 0055 std::filesystem::path d_path; 0056 soci::session d_db; 0057 }; 0058 } // namespace Codethink::lvtmdb 0059 0060 #endif