diff options
| author | Aotrix <[email protected]> | 2025-03-22 00:44:07 +0100 |
|---|---|---|
| committer | Aotrix <[email protected]> | 2025-03-22 00:44:07 +0100 |
| commit | 7d4660ddba59fa104f37f739f82f7f2a17de4644 (patch) | |
| tree | 38079372e60b06d6cff180b61cc65cfd7d1ffacc /src | |
| parent | e60c3f1659e79324318ed3b0b3947e023992428c (diff) | |
You can now specify the type you want for json values
Diffstat (limited to 'src')
| -rw-r--r-- | src/postgresHandler.cpp | 19 |
1 files 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 <iostream> #include <regex> +#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; } } |
