mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-19 12:04:54 +00:00
Re-enable delete subcommand
This commit is contained in:
parent
df2e04a029
commit
8f51f82abc
8 changed files with 31 additions and 14 deletions
|
@ -133,7 +133,7 @@ add_subdirectory(src/backends)
|
||||||
#Actions
|
#Actions
|
||||||
add_subdirectory(src/main)
|
add_subdirectory(src/main)
|
||||||
#add_subdirectory(src/scan)
|
#add_subdirectory(src/scan)
|
||||||
#add_subdirectory(src/delete)
|
add_subdirectory(src/delete)
|
||||||
#add_subdirectory(src/query)
|
#add_subdirectory(src/query)
|
||||||
#add_subdirectory(src/locate)
|
#add_subdirectory(src/locate)
|
||||||
#add_subdirectory(src/navigate)
|
#add_subdirectory(src/navigate)
|
||||||
|
|
|
@ -23,10 +23,14 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <boost/utility/string_ref.hpp>
|
#include <boost/utility/string_ref.hpp>
|
||||||
|
#include <map>
|
||||||
|
#include <functional>
|
||||||
|
|
||||||
namespace dindb {
|
namespace dindb {
|
||||||
using GroupIDType = uint32_t;
|
using GroupIDType = uint32_t;
|
||||||
using FileIDType = uint64_t;
|
using FileIDType = uint64_t;
|
||||||
|
using IDDescMap = std::map<uint32_t, std::string>;
|
||||||
|
using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>;
|
||||||
|
|
||||||
constexpr const GroupIDType InvalidGroupID = 0;
|
constexpr const GroupIDType InvalidGroupID = 0;
|
||||||
constexpr const FileIDType InvalidFileID = 0;
|
constexpr const FileIDType InvalidFileID = 0;
|
||||||
|
@ -43,6 +47,7 @@ namespace dindb {
|
||||||
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) = 0;
|
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) = 0;
|
||||||
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) = 0;
|
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) = 0;
|
||||||
|
|
||||||
|
virtual void delete_group ( const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ) = 0;
|
||||||
};
|
};
|
||||||
} //namespace dindb
|
} //namespace dindb
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ project(${bare_name}-backend-postgresql CXX)
|
||||||
|
|
||||||
add_library(${PROJECT_NAME} SHARED
|
add_library(${PROJECT_NAME} SHARED
|
||||||
tag.cpp
|
tag.cpp
|
||||||
#delete.cpp
|
delete.cpp
|
||||||
#locate.cpp
|
#locate.cpp
|
||||||
#scan.cpp
|
#scan.cpp
|
||||||
#dbsource.cpp
|
#dbsource.cpp
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
#include "backend_postgresql.hpp"
|
#include "backend_postgresql.hpp"
|
||||||
#include "backends/exposed_functions.hpp"
|
#include "backends/exposed_functions.hpp"
|
||||||
#include "tag.hpp"
|
#include "tag.hpp"
|
||||||
|
#include "delete.hpp"
|
||||||
#include "pq/connection.hpp"
|
#include "pq/connection.hpp"
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
@ -99,6 +100,10 @@ namespace dindb {
|
||||||
void BackendPostgreSql::delete_all_tags (const std::vector<std::string>& parRegexes, GroupIDType parSet) {
|
void BackendPostgreSql::delete_all_tags (const std::vector<std::string>& parRegexes, GroupIDType parSet) {
|
||||||
dindb::delete_all_tags(*m_conn, parRegexes, parSet);
|
dindb::delete_all_tags(*m_conn, parRegexes, parSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BackendPostgreSql::delete_group (const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) {
|
||||||
|
dindb::delete_group_from_db(*m_conn, parIDs, parConf);
|
||||||
|
}
|
||||||
} //namespace dindb
|
} //namespace dindb
|
||||||
|
|
||||||
extern "C" dindb::Backend* dindexer_create_backend (const YAML::Node* parConfig) {
|
extern "C" dindb::Backend* dindexer_create_backend (const YAML::Node* parConfig) {
|
||||||
|
|
|
@ -41,6 +41,8 @@ namespace dindb {
|
||||||
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) override;
|
virtual void delete_all_tags ( const std::vector<FileIDType>& parFiles, GroupIDType parSet ) override;
|
||||||
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) override;
|
virtual void delete_all_tags ( const std::vector<std::string>& parRegexes, GroupIDType parSet ) override;
|
||||||
|
|
||||||
|
virtual void delete_group ( const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<pq::Connection> m_conn;
|
std::unique_ptr<pq::Connection> m_conn;
|
||||||
};
|
};
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "db/delete.hpp"
|
#include "delete.hpp"
|
||||||
#include "db/settings.hpp"
|
|
||||||
#include "pq/connection.hpp"
|
#include "pq/connection.hpp"
|
||||||
#include "helpers/infix_iterator.hpp"
|
#include "helpers/infix_iterator.hpp"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
@ -26,6 +25,7 @@
|
||||||
#include <boost/range/adaptor/map.hpp>
|
#include <boost/range/adaptor/map.hpp>
|
||||||
#include <boost/range/algorithm/copy.hpp>
|
#include <boost/range/algorithm/copy.hpp>
|
||||||
#include <boost/lexical_cast.hpp>
|
#include <boost/lexical_cast.hpp>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
namespace dindb {
|
namespace dindb {
|
||||||
namespace {
|
namespace {
|
||||||
|
@ -50,10 +50,10 @@ namespace dindb {
|
||||||
}
|
}
|
||||||
} //unnamed namespace
|
} //unnamed namespace
|
||||||
|
|
||||||
void delete_group_from_db (const Settings& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) {
|
void delete_group_from_db (pq::Connection& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) {
|
||||||
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
|
assert(parDB.is_connected());
|
||||||
conn.connect();
|
|
||||||
const auto dele_ids = fetch_existing_ids(conn, parIDs);
|
const auto dele_ids = fetch_existing_ids(parDB, parIDs);
|
||||||
if (dele_ids.empty()) {
|
if (dele_ids.empty()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -70,6 +70,6 @@ namespace dindb {
|
||||||
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"="));
|
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"="));
|
||||||
oss << ";\nCOMMIT;";
|
oss << ";\nCOMMIT;";
|
||||||
|
|
||||||
conn.query(oss.str());
|
parDB.query(oss.str());
|
||||||
}
|
}
|
||||||
} //namespace dindb
|
} //namespace dindb
|
||||||
|
|
|
@ -18,19 +18,22 @@
|
||||||
#ifndef idB070B86E0E4047B1AF4144DEF2759F3C
|
#ifndef idB070B86E0E4047B1AF4144DEF2759F3C
|
||||||
#define idB070B86E0E4047B1AF4144DEF2759F3C
|
#define idB070B86E0E4047B1AF4144DEF2759F3C
|
||||||
|
|
||||||
|
#include "backends/db_backend.hpp"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
namespace dindb {
|
namespace pq {
|
||||||
struct Settings;
|
class Connection;
|
||||||
|
} //namespace pq
|
||||||
|
|
||||||
|
namespace dindb {
|
||||||
using IDDescMap = std::map<uint32_t, std::string>;
|
using IDDescMap = std::map<uint32_t, std::string>;
|
||||||
using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>;
|
using ConfirmDeleCallback = std::function<bool(const IDDescMap&)>;
|
||||||
|
|
||||||
void delete_group_from_db ( const Settings& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf );
|
void delete_group_from_db ( pq::Connection& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf );
|
||||||
} //namespace dindb
|
} //namespace dindb
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -18,7 +18,6 @@
|
||||||
#include "commandline.hpp"
|
#include "commandline.hpp"
|
||||||
#include "dindexer-common/settings.hpp"
|
#include "dindexer-common/settings.hpp"
|
||||||
#include "dindexerConfig.h"
|
#include "dindexerConfig.h"
|
||||||
#include "db/delete.hpp"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <ciso646>
|
#include <ciso646>
|
||||||
#include <ios>
|
#include <ios>
|
||||||
|
@ -69,6 +68,9 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//TODO: throw if plugin loading failed
|
||||||
|
assert(settings.backend_plugin.name() == settings.backend_name);
|
||||||
|
assert(settings.backend_plugin.is_loaded());
|
||||||
|
|
||||||
if (not vm.count("groupid")) {
|
if (not vm.count("groupid")) {
|
||||||
std::cerr << "No IDs specified\n";
|
std::cerr << "No IDs specified\n";
|
||||||
|
@ -77,7 +79,7 @@ int main (int parArgc, char* parArgv[]) {
|
||||||
|
|
||||||
const auto ids = vm["groupid"].as<std::vector<uint32_t>>();
|
const auto ids = vm["groupid"].as<std::vector<uint32_t>>();
|
||||||
auto confirm_func = (vm.count("confirm") ? &always_delete : &confirm_delete);
|
auto confirm_func = (vm.count("confirm") ? &always_delete : &confirm_delete);
|
||||||
dindb::delete_group_from_db(settings.db, ids, confirm_func);
|
settings.backend_plugin.backend().delete_group(ids, confirm_func);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue