1
0
Fork 0
mirror of https://github.com/KingDuckZ/dindexer.git synced 2024-11-25 00:53:43 +00:00

Implement tagging files by database id

This commit is contained in:
King_DuckZ 2016-05-13 20:48:03 +02:00
parent 537023dbfa
commit 0f308455ca
4 changed files with 79 additions and 3 deletions

View file

@ -4,6 +4,7 @@ add_executable(${PROJECT_NAME}
main.cpp main.cpp
commandline.cpp commandline.cpp
split_tags.cpp split_tags.cpp
tag_postgres.cpp
) )
target_include_directories(${PROJECT_NAME} target_include_directories(${PROJECT_NAME}

View file

@ -16,6 +16,9 @@
*/ */
#include "commandline.hpp" #include "commandline.hpp"
#include "dindexer-common/settings.hpp"
#include "dindexerConfig.h"
#include "tag_postgres.hpp"
#include "split_tags.hpp" #include "split_tags.hpp"
#include <iostream> #include <iostream>
#include <ciso646> #include <ciso646>
@ -42,6 +45,15 @@ int main (int parArgc, char* parArgv[]) {
return 2; return 2;
} }
dinlib::Settings settings;
{
const bool loaded = dinlib::load_settings(CONFIG_FILE_PATH, settings);
if (not loaded) {
std::cerr << "Can't load settings from " << CONFIG_FILE_PATH << ", quitting\n";
return 1;
}
}
const auto ids = vm["ids"].as<std::vector<uint64_t>>(); const auto ids = vm["ids"].as<std::vector<uint64_t>>();
for (auto id : ids) { for (auto id : ids) {
std::cout << id << '\n'; std::cout << id << '\n';
@ -50,8 +62,6 @@ int main (int parArgc, char* parArgv[]) {
const auto master_tags_string = vm["tags"].as<std::string>(); const auto master_tags_string = vm["tags"].as<std::string>();
std::vector<boost::string_ref> tags = din::split_tags(master_tags_string); std::vector<boost::string_ref> tags = din::split_tags(master_tags_string);
for (auto tag : tags) { din::tag_files(settings.db, ids, tags);
std::cout << '"' << tag << "\"\n";
}
return 0; return 0;
} }

32
src/tag/tag_postgres.cpp Normal file
View file

@ -0,0 +1,32 @@
/* 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/>.
*/
#include "tag_postgres.hpp"
#include "pq/connection.hpp"
#include "dindexer-common/settings.hpp"
namespace din {
void tag_files (const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags) {
pq::Connection conn(std::string(parDB.username), std::string(parDB.password), std::string(parDB.dbname), std::string(parDB.address), parDB.port);
conn.connect();
const std::string query =
"UPDATE \"files\" SET \"tags\" = ARRAY(SELECT DISTINCT UNNEST(\"tags\" || $1) ORDER BY 1) WHERE \"id\"=ANY($2);";
conn.query(query, parTags, parFiles);
}
} //namespace din

33
src/tag/tag_postgres.hpp Normal file
View file

@ -0,0 +1,33 @@
/* 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 idE1E1650A8CAA4949BD6D4D58BF2599F5
#define idE1E1650A8CAA4949BD6D4D58BF2599F5
#include <vector>
#include <boost/utility/string_ref.hpp>
#include <cstdint>
namespace dinlib {
struct SettingsDB;
} //namespace dinlib
namespace din {
void tag_files ( const dinlib::SettingsDB& parDB, const std::vector<uint64_t>& parFiles, const std::vector<boost::string_ref>& parTags );
} //namespace din
#endif