#include "postgresHandler.h" #include #include #define INT_INDEX 2 #define STRING_INDEX 3 #define LIST_OF_INT_INDEX 4 #define NULL_INDEX 5 const pqxx::result execute_query(pqxx::work &t_transaction, std::string_view t_query) { return t_transaction.exec(t_query); } void display_query_result(const pqxx::result &t_r) { const int nb_columns = t_r.columns(); for (const auto &row : t_r) { for (int i = 0; i < nb_columns; i++) { std::cout << row[i].c_str() << " | "; } std::cout << std::endl; } } void add_cards_to_database(const std::string &t_cards, pqxx::work &t_tx) { // TODO: to complete std::cout << "adding cards..." << std::endl; std::regex key_regex( "\"[^\"?]+\":(([0-9]+)|(\"[^\"?]*\")|(\\[[0-9,]*\\])|(null))"); // (*it)[x] type? // for x = 2: integers // 3: string // 4: list of ints // 5: null auto words_begin = std::sregex_iterator(t_cards.begin(), t_cards.end(), key_regex); auto words_end = std::sregex_iterator(); for (auto it = words_begin; it != words_end; ++it) { std::cout << (*it)[INT_INDEX].str() << std::endl; } }