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

Re-enable delete subcommand

This commit is contained in:
King_DuckZ 2016-05-31 10:30:16 +02:00
parent df2e04a029
commit 8f51f82abc
8 changed files with 31 additions and 14 deletions

View file

@ -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

View file

@ -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) {

View file

@ -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;
};

View file

@ -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

View file

@ -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