mirror of
https://github.com/KingDuckZ/dindexer.git
synced 2025-02-16 11:35:49 +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
|
||||
add_subdirectory(src/main)
|
||||
#add_subdirectory(src/scan)
|
||||
#add_subdirectory(src/delete)
|
||||
add_subdirectory(src/delete)
|
||||
#add_subdirectory(src/query)
|
||||
#add_subdirectory(src/locate)
|
||||
#add_subdirectory(src/navigate)
|
||||
|
|
|
@ -23,10 +23,14 @@
|
|||
#include <string>
|
||||
#include <vector>
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
#include <map>
|
||||
#include <functional>
|
||||
|
||||
namespace dindb {
|
||||
using GroupIDType = uint32_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 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<std::string>& parRegexes, GroupIDType parSet ) = 0;
|
||||
|
||||
virtual void delete_group ( const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ) = 0;
|
||||
};
|
||||
} //namespace dindb
|
||||
|
||||
|
|
|
@ -2,7 +2,7 @@ project(${bare_name}-backend-postgresql CXX)
|
|||
|
||||
add_library(${PROJECT_NAME} SHARED
|
||||
tag.cpp
|
||||
#delete.cpp
|
||||
delete.cpp
|
||||
#locate.cpp
|
||||
#scan.cpp
|
||||
#dbsource.cpp
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "backend_postgresql.hpp"
|
||||
#include "backends/exposed_functions.hpp"
|
||||
#include "tag.hpp"
|
||||
#include "delete.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include <ciso646>
|
||||
#include <utility>
|
||||
|
@ -99,6 +100,10 @@ namespace dindb {
|
|||
void BackendPostgreSql::delete_all_tags (const std::vector<std::string>& parRegexes, GroupIDType 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
|
||||
|
||||
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<std::string>& parRegexes, GroupIDType parSet ) override;
|
||||
|
||||
virtual void delete_group ( const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf ) override;
|
||||
|
||||
private:
|
||||
std::unique_ptr<pq::Connection> m_conn;
|
||||
};
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
* along with "dindexer". If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "db/delete.hpp"
|
||||
#include "db/settings.hpp"
|
||||
#include "delete.hpp"
|
||||
#include "pq/connection.hpp"
|
||||
#include "helpers/infix_iterator.hpp"
|
||||
#include <sstream>
|
||||
|
@ -26,6 +25,7 @@
|
|||
#include <boost/range/adaptor/map.hpp>
|
||||
#include <boost/range/algorithm/copy.hpp>
|
||||
#include <boost/lexical_cast.hpp>
|
||||
#include <cassert>
|
||||
|
||||
namespace dindb {
|
||||
namespace {
|
||||
|
@ -50,10 +50,10 @@ namespace dindb {
|
|||
}
|
||||
} //unnamed namespace
|
||||
|
||||
void delete_group_from_db (const Settings& 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);
|
||||
conn.connect();
|
||||
const auto dele_ids = fetch_existing_ids(conn, parIDs);
|
||||
void delete_group_from_db (pq::Connection& parDB, const std::vector<uint32_t>& parIDs, ConfirmDeleCallback parConf) {
|
||||
assert(parDB.is_connected());
|
||||
|
||||
const auto dele_ids = fetch_existing_ids(parDB, parIDs);
|
||||
if (dele_ids.empty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -70,6 +70,6 @@ namespace dindb {
|
|||
boost::copy(dele_ids | boost::adaptors::map_keys, infix_ostream_iterator<uint32_t>(oss, " OR \"id\"="));
|
||||
oss << ";\nCOMMIT;";
|
||||
|
||||
conn.query(oss.str());
|
||||
parDB.query(oss.str());
|
||||
}
|
||||
} //namespace dindb
|
||||
|
|
|
@ -18,19 +18,22 @@
|
|||
#ifndef idB070B86E0E4047B1AF4144DEF2759F3C
|
||||
#define idB070B86E0E4047B1AF4144DEF2759F3C
|
||||
|
||||
#include "backends/db_backend.hpp"
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <cstdint>
|
||||
#include <map>
|
||||
|
||||
namespace dindb {
|
||||
struct Settings;
|
||||
namespace pq {
|
||||
class Connection;
|
||||
} //namespace pq
|
||||
|
||||
namespace dindb {
|
||||
using IDDescMap = std::map<uint32_t, std::string>;
|
||||
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
|
||||
|
||||
#endif
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
#include "commandline.hpp"
|
||||
#include "dindexer-common/settings.hpp"
|
||||
#include "dindexerConfig.h"
|
||||
#include "db/delete.hpp"
|
||||
#include <iostream>
|
||||
#include <ciso646>
|
||||
#include <ios>
|
||||
|
@ -69,6 +68,9 @@ int main (int parArgc, char* parArgv[]) {
|
|||
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")) {
|
||||
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>>();
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue