fix: renaming the field 'value' (of type 'int') to 'text' (of type 'text') in the database
This commit is contained in:
parent
d8c3a16852
commit
07f571dbc9
|
|
@ -66,7 +66,7 @@ install(FILES LICENSE DESTINATION /usr/share/doc/cards)
|
||||||
|
|
||||||
# ─── Packaging (CPack) ────────────────────────────────────────────────
|
# ─── Packaging (CPack) ────────────────────────────────────────────────
|
||||||
set(CPACK_PACKAGE_NAME "cards")
|
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_VENDOR "cards")
|
||||||
set(CPACK_PACKAGE_MAINTAINER "adwet")
|
set(CPACK_PACKAGE_MAINTAINER "adwet")
|
||||||
set(CPACK_PACKAGE_CONTACT "adwet@yandex.ru")
|
set(CPACK_PACKAGE_CONTACT "adwet@yandex.ru")
|
||||||
|
|
|
||||||
|
|
@ -15,7 +15,7 @@ Database::Database(const DatabaseConfig& cfg, int workers)
|
||||||
"CREATE TABLE IF NOT EXISTS random_data ("
|
"CREATE TABLE IF NOT EXISTS random_data ("
|
||||||
" id SERIAL PRIMARY KEY,"
|
" id SERIAL PRIMARY KEY,"
|
||||||
" name VARCHAR(100) NOT NULL,"
|
" name VARCHAR(100) NOT NULL,"
|
||||||
" value INTEGER NOT NULL,"
|
" text TEXT NOT NULL,"
|
||||||
" description TEXT,"
|
" description TEXT,"
|
||||||
" created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
|
" created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP"
|
||||||
")"
|
")"
|
||||||
|
|
@ -104,14 +104,14 @@ json Database::getRandomRecord(pqxx::connection& conn, std::mt19937& rng) {
|
||||||
pqxx::work txn(conn);
|
pqxx::work txn(conn);
|
||||||
|
|
||||||
auto result = txn.exec(
|
auto result = txn.exec(
|
||||||
"SELECT id, name, value, description, created_at "
|
"SELECT id, name, text, description, created_at "
|
||||||
"FROM random_data "
|
"FROM random_data "
|
||||||
"WHERE id = $1",
|
"WHERE id = $1",
|
||||||
pqxx::params{randomId}
|
pqxx::params{randomId}
|
||||||
);
|
);
|
||||||
|
|
||||||
if (result.empty()) {
|
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()) {
|
if (result.empty()) {
|
||||||
|
|
@ -126,7 +126,7 @@ json Database::getRandomRecord(pqxx::connection& conn, std::mt19937& rng) {
|
||||||
json response = {
|
json response = {
|
||||||
{"id", row[0].as<int>()},
|
{"id", row[0].as<int>()},
|
||||||
{"name", row[1].as<std::string>()},
|
{"name", row[1].as<std::string>()},
|
||||||
{"value", row[2].as<int>()},
|
{"text", row[2].as<std::string>()},
|
||||||
{"description", row[3].as<std::string>()},
|
{"description", row[3].as<std::string>()},
|
||||||
{"created_at", row[4].as<std::string>()},
|
{"created_at", row[4].as<std::string>()},
|
||||||
{"timestamp", std::chrono::system_clock::now().time_since_epoch().count()}
|
{"timestamp", std::chrono::system_clock::now().time_since_epoch().count()}
|
||||||
|
|
@ -182,7 +182,7 @@ json Database::getRandomRecordsFast(pqxx::connection& conn, const int count) {
|
||||||
"SELECT"
|
"SELECT"
|
||||||
" rd.id,"
|
" rd.id,"
|
||||||
" rd.name,"
|
" rd.name,"
|
||||||
" rd.value,"
|
" rd.text,"
|
||||||
" rd.description,"
|
" rd.description,"
|
||||||
" rd.created_at"
|
" rd.created_at"
|
||||||
"FROM random_selection AS rs"
|
"FROM random_selection AS rs"
|
||||||
|
|
@ -203,7 +203,7 @@ json Database::getRandomRecordsFast(pqxx::connection& conn, const int count) {
|
||||||
response.push_back({
|
response.push_back({
|
||||||
{"id", row[0].as<int>()},
|
{"id", row[0].as<int>()},
|
||||||
{"name", row[1].as<std::string>()},
|
{"name", row[1].as<std::string>()},
|
||||||
{"value", row[2].as<int>()},
|
{"text", row[2].as<std::string>()},
|
||||||
{"description", row[3].as<std::string>()},
|
{"description", row[3].as<std::string>()},
|
||||||
{"created_at", row[4].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({
|
response.push_back({
|
||||||
{"id", row[0].as<int>()},
|
{"id", row[0].as<int>()},
|
||||||
{"name", row[1].as<std::string>()},
|
{"name", row[1].as<std::string>()},
|
||||||
{"value", row[2].as<int>()},
|
{"text", row[2].as<std::string>()},
|
||||||
{"description", row[3].as<std::string>()},
|
{"description", row[3].as<std::string>()},
|
||||||
{"created_at", row[4].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 Database::getQueryRandomIds(const int count) {
|
||||||
std::string query =
|
std::string query =
|
||||||
"SELECT id, name, value, description, created_at "
|
"SELECT id, name, text, description, created_at "
|
||||||
"FROM random_data WHERE id IN (";
|
"FROM random_data WHERE id IN (";
|
||||||
|
|
||||||
for (size_t i = 0; i < count; ++i) {
|
for (size_t i = 0; i < count; ++i) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue