1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2025-07-03 14:14:11 +00:00

Move db dbsource files to the postgresql backend lib and rename namespace.

This commit is contained in:
King_DuckZ 2016-05-23 19:28:50 +02:00
parent baa67138eb
commit 70caa9e26c
24 changed files with 166 additions and 131 deletions

View file

@ -0,0 +1,151 @@
/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef id63F35BA8B3C94A129291D963ABE66018
#define id63F35BA8B3C94A129291D963ABE66018
#include "dindexer-machinery/recorddata.hpp"
#include "helpers/flatinsertin2dlist.hpp"
#include "helpers/MaxSizedArray.hpp"
#include <memory>
#include <cstdint>
#include <vector>
#include <array>
#include <map>
#include <boost/range/algorithm/copy.hpp>
#include <algorithm>
#include <functional>
#include <boost/utility/string_ref.hpp>
namespace pq {
class Connection;
} //namespace pq
namespace dinbpostgres {
using dinhelp::MaxSizedArray;
struct Settings;
enum SetDetails {
SetDetail_Desc = 0x01,
SetDetail_Type = 0x02,
SetDetail_CreeationDate = 0x04,
SetDetail_AppName = 0x08,
SetDetail_ID = 0x10
};
enum FileDetails {
FileDetail_ID = 0x0001,
FileDetail_Path = 0x0002,
FileDetail_Level = 0x0004,
FileDetail_GroupID = 0x0008,
FileDetail_IsDir = 0x0010,
FileDetail_IsSymLink = 0x0020,
FileDetail_Size = 0x0040,
FileDetail_Hash = 0x0080,
FileDetail_IsHashValid = 0x0100,
FileDetail_ATime = 0x0200,
FileDetail_MTime = 0x0400,
FileDetail_Unreadable = 0x800,
FileDetail_MimeType = 0x1000,
FileDetail_Charset = 0x2000
};
class DBSource {
public:
explicit DBSource ( const Settings& parDBSettings );
~DBSource ( void ) noexcept;
void disconnect ( void );
std::vector<uint32_t> sets ( void );
template <SetDetails... D>
auto set_details ( const std::vector<uint32_t>& parIDs ) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>>;
template <FileDetails... D>
auto file_details ( uint32_t parSetID, uint16_t parLevel, boost::string_ref parDir ) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>>;
std::vector<std::string> paths_starting_by ( uint32_t parGroupID, uint16_t parLevel, boost::string_ref parPath );
private:
struct LocalData;
typedef std::map<SetDetails, std::string> SetDetailsMap;
typedef std::map<FileDetails, std::string> FileDetailsMap;
typedef std::vector<std::string> ColumnList;
typedef std::function<void(std::string&&)> QueryCallback;
pq::Connection& get_conn ( void );
void query_no_conditions ( const ColumnList& parCols, boost::string_ref parTable, const std::vector<uint32_t>& parIDs, QueryCallback parCallback );
void query_files_in_dir ( const ColumnList& parCols, boost::string_ref parDir, uint16_t parLevel, uint32_t parGroupID, QueryCallback parCallback );
static const SetDetailsMap m_set_details_map;
static const FileDetailsMap m_file_details_map;
std::unique_ptr<LocalData> m_local_data;
};
namespace implem {
template <class M, M... Details>
inline
std::vector<std::string> make_columns_vec (const std::map<M, std::string>& parDic) {
//typedef const std::string&(SetDetailsMap::*AtFunc)(const SetDetails&) const;
std::vector<std::string> columns;
columns.reserve(sizeof...(Details));
const std::array<M, sizeof...(Details)> details { {Details...} };
//AtFunc at_func = &SetDetailsMap::at;
//std::generate(details.begin(), details.end(), columns.begin(), std::bind(at_func, &details_dic, std::placeholders::_1));
for (auto detail : details) {
columns.push_back(parDic.at(detail));
}
return columns;
}
} //namespace implem
template <SetDetails... D>
auto DBSource::set_details (const std::vector<uint32_t>& parIDs) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>> {
using dinhelp::FlatInsertIn2DList;
typedef std::vector<MaxSizedArray<std::string, sizeof...(D)>> ReturnType;
typedef void(FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(std::string&&);
const auto columns = implem::make_columns_vec<SetDetails, D...>(m_set_details_map);
ReturnType list;
FlatInsertIn2DList<ReturnType> flat_list(&list, sizeof...(D));
FlatPushBackFunc pback_func = &FlatInsertIn2DList<ReturnType>::push_back;
this->query_no_conditions(columns, "sets", parIDs, std::bind(pback_func, &flat_list, std::placeholders::_1));
return list;
}
template <FileDetails... D>
auto DBSource::file_details (uint32_t parSetID, uint16_t parLevel, boost::string_ref parDir) -> std::vector<MaxSizedArray<std::string, sizeof...(D)>> {
using dinhelp::FlatInsertIn2DList;
typedef std::vector<MaxSizedArray<std::string, sizeof...(D)>> ReturnType;
typedef void(FlatInsertIn2DList<ReturnType>::*FlatPushBackFunc)(std::string&&);
const auto columns = implem::make_columns_vec<FileDetails, D...>(m_file_details_map);
ReturnType list;
FlatInsertIn2DList<ReturnType> flat_list(&list, sizeof...(D));
FlatPushBackFunc pback_func = &FlatInsertIn2DList<ReturnType>::push_back;
this->query_files_in_dir(columns, parDir, parLevel, parSetID, std::bind(pback_func, &flat_list, std::placeholders::_1));
return list;
}
} //namespace dinbpostgres
#endif

View file

@ -24,15 +24,13 @@
#include <cstdint>
#include <map>
namespace dinlib {
struct SettingsDB;
} //namespace dinlib
namespace dinbpostgres {
struct Settings;
namespace din {
using IDDescMap = std::map<uint32_t, std::string>;
using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>;
void delete_group_from_db ( const dinlib::SettingsDB& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf );
} //namespace din
void delete_group_from_db ( const Settings& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf );
} //namespace dinbpostgres
#endif

View file

@ -18,7 +18,6 @@
#ifndef id1AE05A59AE0E4A4490040FD85D9AF665
#define id1AE05A59AE0E4A4490040FD85D9AF665
#include "dindexer-common/settings.hpp"
#include <vector>
#include <string>
#include <cstdint>
@ -28,7 +27,9 @@ namespace mchlib {
struct TigerHash;
} //namespace mchlib
namespace din {
namespace dinbpostgres {
struct Settings;
struct LocatedItem {
std::string path;
uint64_t id;
@ -44,10 +45,10 @@ namespace din {
using TagList = std::vector<boost::string_ref>;
std::vector<LocatedItem> locate_in_db ( const dinlib::SettingsDB& parDB, const std::string& parSearch, const TagList& parTags );
std::vector<LocatedItem> locate_in_db ( const dinlib::SettingsDB& parDB, const mchlib::TigerHash& parSearch, const TagList& parTags );
std::vector<LocatedSet> locate_sets_in_db ( const dinlib::SettingsDB& parDB, const std::string& parSearch, bool parCaseInsensitive );
std::vector<LocatedSet> locate_sets_in_db ( const dinlib::SettingsDB& parDB, const std::string& parSearch, const std::vector<uint32_t>& parSets, bool parCaseInsensitive );
} //namespace din
std::vector<LocatedItem> locate_in_db ( const Settings& parDB, const std::string& parSearch, const TagList& parTags );
std::vector<LocatedItem> locate_in_db ( const Settings& parDB, const mchlib::TigerHash& parSearch, const TagList& parTags );
std::vector<LocatedSet> locate_sets_in_db ( const Settings& parDB, const std::string& parSearch, bool parCaseInsensitive );
std::vector<LocatedSet> locate_sets_in_db ( const Settings& parDB, const std::string& parSearch, const std::vector<uint32_t>& parSets, bool parCaseInsensitive );
} //namespace dinbpostgres
#endif

View file

@ -22,10 +22,6 @@
#include <vector>
#include <cstdint>
namespace dinlib {
struct SettingsDB;;
} //namespace dinlib
namespace mchlib {
struct FileRecordData;
struct SetRecordData;
@ -33,9 +29,11 @@ namespace mchlib {
struct TigerHash;
} //namespace mchlib
namespace din {
void write_to_db ( const dinlib::SettingsDB& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature );
bool read_from_db ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const dinlib::SettingsDB& parDB, const mchlib::TigerHash& parHash );
} //namespace din
namespace dinbpostgres {
struct Settings;;
void write_to_db ( const Settings& parDB, const std::vector<mchlib::FileRecordData>& parData, const mchlib::SetRecordData& parSetData, const std::string& parSignature );
bool read_from_db ( mchlib::FileRecordData& parItem, mchlib::SetRecordDataFull& parSet, const Settings& parDB, const mchlib::TigerHash& parHash );
} //namespace dinbpostgres
#endif

View file

@ -0,0 +1,34 @@
/* Copyright 2015, 2016, Michele Santullo
* This file is part of "dindexer".
*
* "dindexer" is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* "dindexer" is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef idC895D12FEB324387A37FF631E0C09560
#define idC895D12FEB324387A37FF631E0C09560
#include <string>
#include <cstdint>
namespace dinbpostgres {
struct Settings {
std::string address;
std::string username;
std::string password;
std::string dbname;
uint16_t port;
};
} //namespace dinbpostgres
#endif

View file

@ -22,23 +22,21 @@
#include <boost/utility/string_ref.hpp>
#include <cstdint>
namespace dinlib {
struct SettingsDB;
} //namespace dinlib
namespace dinbpostgres {
struct Settings;
namespace din {
struct OwnerSetInfo {
uint32_t group_id;
bool is_valid;
};
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void tag_files ( const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void tag_files ( const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void delete_tags ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void delete_tags ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void delete_all_tags ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet );
void delete_all_tags ( const dinlib::SettingsDB& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet );
} //namespace din
void delete_tags ( const Settings& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void delete_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, const std::vector<boost::string_ref>& parTags, OwnerSetInfo parSet );
void delete_all_tags ( const Settings& parDB, const std::vector<uint64_t>& parFiles, OwnerSetInfo parSet );
void delete_all_tags ( const Settings& parDB, const std::vector<std::string>& parRegexes, OwnerSetInfo parSet );
} //namespace dinbpostgres
#endif