fix: renaming the field 'value' (of type 'int') to 'text' (of type 'text') in the database

This commit is contained in:
Andrey Kutin 2026-10-15 21:31:24 +03:00
parent d8c3a16852
commit 07f571dbc9
2 changed files with 9 additions and 9 deletions

View File

@ -66,7 +66,7 @@ install(FILES LICENSE DESTINATION /usr/share/doc/cards)
# ─── Packaging (CPack) ────────────────────────────────────────────────
set(CPACK_PACKAGE_NAME "cards")
set(CPACK_PACKAGE_VERSION "1.0.0")
set(CPACK_PACKAGE_VERSION "1.0.1")
set(CPACK_PACKAGE_VENDOR "cards")
set(CPACK_PACKAGE_MAINTAINER "adwet")
set(CPACK_PACKAGE_CONTACT "adwet@yandex.ru")

View File

@ -15,7 +15,7 @@ Database::Database(const DatabaseConfig& cfg, int workers)
"CREATE TABLE IF NOT EXISTS random_data ("
" id SERIAL PRIMARY KEY,"
" name VARCHAR(100) NOT NULL,"
" value INTEGER NOT NULL,"
" text TEXT NOT NULL,"
" description TEXT,"
" created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
")"
@ -104,14 +104,14 @@ json Database::getRandomRecord(pqxx::connection& conn, std::mt19937& rng) {
pqxx::work txn(conn);
auto result = txn.exec(
"SELECT id, name, value, description, created_at "
"SELECT id, name, text, description, created_at "
"FROM random_data "
"WHERE id = $1",
pqxx::params{randomId}
);
if (result.empty()) {
result = txn.exec("SELECT id, name, value, description, created_at FROM random_data LIMIT 1");
result = txn.exec("SELECT id, name, text, description, created_at FROM random_data LIMIT 1");
}
if (result.empty()) {
@ -126,7 +126,7 @@ json Database::getRandomRecord(pqxx::connection& conn, std::mt19937& rng) {
json response = {
{"id", row[0].as<int>()},
{"name", row[1].as<std::string>()},
{"value", row[2].as<int>()},
{"text", row[2].as<std::string>()},
{"description", row[3].as<std::string>()},
{"created_at", row[4].as<std::string>()},
{"timestamp", std::chrono::system_clock::now().time_since_epoch().count()}
@ -182,7 +182,7 @@ json Database::getRandomRecordsFast(pqxx::connection& conn, const int count) {
"SELECT"
" rd.id,"
" rd.name,"
" rd.value,"
" rd.text,"
" rd.description,"
" rd.created_at"
"FROM random_selection AS rs"
@ -203,7 +203,7 @@ json Database::getRandomRecordsFast(pqxx::connection& conn, const int count) {
response.push_back({
{"id", row[0].as<int>()},
{"name", row[1].as<std::string>()},
{"value", row[2].as<int>()},
{"text", row[2].as<std::string>()},
{"description", row[3].as<std::string>()},
{"created_at", row[4].as<std::string>()}
});
@ -252,7 +252,7 @@ json Database::getRandomRecordsSlow(pqxx::connection& conn, std::mt19937& rng, c
response.push_back({
{"id", row[0].as<int>()},
{"name", row[1].as<std::string>()},
{"value", row[2].as<int>()},
{"text", row[2].as<std::string>()},
{"description", row[3].as<std::string>()},
{"created_at", row[4].as<std::string>()}
});
@ -319,7 +319,7 @@ int Database::getTotalCount(pqxx::connection& conn) {
std::string Database::getQueryRandomIds(const int count) {
std::string query =
"SELECT id, name, value, description, created_at "
"SELECT id, name, text, description, created_at "
"FROM random_data WHERE id IN (";
for (size_t i = 0; i < count; ++i) {