From 7d4660ddba59fa104f37f739f82f7f2a17de4644 Mon Sep 17 00:00:00 2001 From: Aotrix Date: Sat, 22 Mar 2025 00:44:07 +0100 Subject: You can now specify the type you want for json values --- src/postgresHandler.cpp | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/src/postgresHandler.cpp b/src/postgresHandler.cpp index f5b603b..84776fe 100644 --- a/src/postgresHandler.cpp +++ b/src/postgresHandler.cpp @@ -2,6 +2,11 @@ #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); @@ -21,14 +26,18 @@ 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)"); // TODO: - // write - // correct - // 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).str() << std::endl; + std::cout << (*it)[INT_INDEX].str() << std::endl; } } -- cgit v1.2.3