1 parent
d146f11f02
commit
5c036d91fb
72 files changed
+5875
-1243
No files matched your search
+404
-9
@@ -2,6 +2,7 @@
|
||||
#include <Void/Log/Log.hpp>
|
||||
#include <Void/Math/Random.hpp>
|
||||
#include <Void/Sqlite/Sqlite.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <format>
|
||||
#include <shared_mutex>
|
||||
@@ -312,7 +313,115 @@ namespace Echoion::Api
|
||||
"Database migration 6 applied: track_short_url columns added");
|
||||
}
|
||||
|
||||
impl_->version = 6;
|
||||
// Migration 7: aggregate-stats support — skip tracking on history and
|
||||
// a queue-addition log (daily counters + top requesters for the web
|
||||
// dashboard).
|
||||
if (currentVersion < 7) {
|
||||
const char* migration7 = R"(
|
||||
ALTER TABLE playback_history ADD COLUMN skipped INTEGER DEFAULT 0;
|
||||
CREATE TABLE IF NOT EXISTS queue_log (
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
uid TEXT,
|
||||
nickname TEXT,
|
||||
added_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
CREATE INDEX IF NOT EXISTS idx_queue_log_date ON queue_log(added_at);
|
||||
)";
|
||||
|
||||
if (auto r = impl_->voidDb.exec(migration7); !r) {
|
||||
return fail(ErrorCode::DatabaseError, r.error().message());
|
||||
}
|
||||
|
||||
[[maybe_unused]] auto ins = impl_->voidDb.exec(
|
||||
"INSERT INTO schema_migrations (version) VALUES (7)");
|
||||
|
||||
Void::Log::info("Database", "{}",
|
||||
"Database migration 7 applied: skip tracking and queue log");
|
||||
}
|
||||
|
||||
// Migration 8: persist track thumbnails with history and favorites so
|
||||
// the web UI can show original artwork for reconstructed tracks
|
||||
// (playlist_tracks already stores track_thumbnail since v1).
|
||||
if (currentVersion < 8) {
|
||||
const char* migration8 = R"(
|
||||
ALTER TABLE playback_history ADD COLUMN track_thumbnail TEXT;
|
||||
ALTER TABLE user_favorites ADD COLUMN track_thumbnail TEXT;
|
||||
)";
|
||||
|
||||
if (auto r = impl_->voidDb.exec(migration8); !r) {
|
||||
return fail(ErrorCode::DatabaseError, r.error().message());
|
||||
}
|
||||
|
||||
[[maybe_unused]] auto ins = impl_->voidDb.exec(
|
||||
"INSERT INTO schema_migrations (version) VALUES (8)");
|
||||
|
||||
Void::Log::info("Database", "{}",
|
||||
"Database migration 8 applied: track_thumbnail columns added");
|
||||
}
|
||||
|
||||
// Migration 9: custom emojis for the web UI (admin-managed image
|
||||
// emotes, referenced by :name: shortcodes in watch chat/reactions).
|
||||
if (currentVersion < 9) {
|
||||
const char* migration9 = R"(
|
||||
CREATE TABLE IF NOT EXISTS custom_emojis (
|
||||
name TEXT PRIMARY KEY,
|
||||
mime TEXT NOT NULL,
|
||||
data TEXT NOT NULL, -- base64-encoded image bytes
|
||||
added_by TEXT,
|
||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
)";
|
||||
|
||||
if (auto r = impl_->voidDb.exec(migration9); !r) {
|
||||
return fail(ErrorCode::DatabaseError, r.error().message());
|
||||
}
|
||||
|
||||
[[maybe_unused]] auto ins = impl_->voidDb.exec(
|
||||
"INSERT INTO schema_migrations (version) VALUES (9)");
|
||||
|
||||
Void::Log::info("Database", "{}",
|
||||
"Database migration 9 applied: custom_emojis table added");
|
||||
}
|
||||
|
||||
// Migration 10: cached TeamSpeak avatars for the web UI, keyed by uid,
|
||||
// so avatars survive the client going offline/out-of-view.
|
||||
if (currentVersion < 10) {
|
||||
const char* migration10 = R"(
|
||||
CREATE TABLE IF NOT EXISTS cached_avatars (
|
||||
uid TEXT PRIMARY KEY,
|
||||
mime TEXT NOT NULL,
|
||||
data TEXT NOT NULL, -- base64-encoded image bytes
|
||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
|
||||
);
|
||||
)";
|
||||
|
||||
if (auto r = impl_->voidDb.exec(migration10); !r) {
|
||||
return fail(ErrorCode::DatabaseError, r.error().message());
|
||||
}
|
||||
|
||||
[[maybe_unused]] auto ins = impl_->voidDb.exec(
|
||||
"INSERT INTO schema_migrations (version) VALUES (10)");
|
||||
|
||||
Void::Log::info("Database", "{}",
|
||||
"Database migration 10 applied: cached_avatars table added");
|
||||
}
|
||||
|
||||
// Migration 11: remember the source avatar URL alongside the cached
|
||||
// bytes, so an offline user's avatar can be re-fetched from it.
|
||||
if (currentVersion < 11) {
|
||||
// ADD COLUMN is a no-op-safe schema bump; ignore "duplicate column"
|
||||
// if a prior partial run already added it.
|
||||
[[maybe_unused]] auto alt = impl_->voidDb.exec(
|
||||
"ALTER TABLE cached_avatars ADD COLUMN url TEXT;");
|
||||
|
||||
[[maybe_unused]] auto ins = impl_->voidDb.exec(
|
||||
"INSERT INTO schema_migrations (version) VALUES (11)");
|
||||
|
||||
Void::Log::info("Database", "{}",
|
||||
"Database migration 11 applied: cached_avatars.url added");
|
||||
}
|
||||
|
||||
impl_->version = 11;
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -576,8 +685,8 @@ namespace Echoion::Api
|
||||
|
||||
const char* sql = R"(
|
||||
INSERT INTO playback_history
|
||||
(track_url, track_title, track_artist, played_by, duration_ms, completed, track_short_url)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?);
|
||||
(track_url, track_title, track_artist, played_by, duration_ms, completed, track_short_url, track_thumbnail)
|
||||
VALUES (?, ?, ?, ?, ?, ?, ?, ?);
|
||||
)";
|
||||
|
||||
auto stmtRes = impl_->voidDb.prepare(sql);
|
||||
@@ -591,7 +700,53 @@ namespace Echoion::Api
|
||||
.bind(4, static_cast<std::int64_t>(playedBy))
|
||||
.bind(5, static_cast<std::int64_t>(duration.count()))
|
||||
.bind(6, completed ? 1 : 0)
|
||||
.bind(7, track.shortenedUrl.value_or(""));
|
||||
.bind(7, track.shortenedUrl.value_or(""))
|
||||
.bind(8, track.thumbnailUrl.value_or(""));
|
||||
[[maybe_unused]] auto stepRes = stmt.step();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> Database::recordSkip(const TrackInfo& track, uint64_t playedBy)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
const char* sql = R"(
|
||||
INSERT INTO playback_history
|
||||
(track_url, track_title, track_artist, played_by, duration_ms, completed, track_short_url, track_thumbnail, skipped)
|
||||
VALUES (?, ?, ?, ?, 0, 0, ?, ?, 1);
|
||||
)";
|
||||
|
||||
auto stmtRes = impl_->voidDb.prepare(sql);
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, track.originalUrl)
|
||||
.bind(2, track.title)
|
||||
.bind(3, track.artist)
|
||||
.bind(4, static_cast<std::int64_t>(playedBy))
|
||||
.bind(5, track.shortenedUrl.value_or(""))
|
||||
.bind(6, track.thumbnailUrl.value_or(""));
|
||||
[[maybe_unused]] auto stepRes = stmt.step();
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> Database::logQueueAddition(const std::string& uid,
|
||||
const std::string& nickname)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||
|
||||
const char* sql =
|
||||
"INSERT INTO queue_log (uid, nickname) VALUES (?, ?);";
|
||||
|
||||
auto stmtRes = impl_->voidDb.prepare(sql);
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, uid).bind(2, nickname);
|
||||
[[maybe_unused]] auto stepRes = stmt.step();
|
||||
|
||||
return {};
|
||||
@@ -606,7 +761,7 @@ namespace Echoion::Api
|
||||
std::vector<PlaybackHistoryEntry> history;
|
||||
|
||||
const char* sql = R"(
|
||||
SELECT id, track_url, track_title, track_artist, played_at, duration_ms, completed, track_short_url
|
||||
SELECT id, track_url, track_title, track_artist, played_at, duration_ms, completed, track_short_url, track_thumbnail
|
||||
FROM playback_history
|
||||
WHERE played_by = ?
|
||||
ORDER BY played_at DESC
|
||||
@@ -635,6 +790,9 @@ namespace Echoion::Api
|
||||
if (auto shortUrl = stmt.column_text(7); !shortUrl.empty()) {
|
||||
entry.track.shortenedUrl = shortUrl;
|
||||
}
|
||||
if (auto thumb = stmt.column_text(8); !thumb.empty()) {
|
||||
entry.track.thumbnailUrl = thumb;
|
||||
}
|
||||
history.push_back(entry);
|
||||
}
|
||||
|
||||
@@ -647,8 +805,8 @@ namespace Echoion::Api
|
||||
std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||
const char* sql = R"(
|
||||
INSERT OR REPLACE INTO user_favorites
|
||||
(user_id, track_url, track_title, track_artist, track_short_url)
|
||||
VALUES (?, ?, ?, ?, ?);
|
||||
(user_id, track_url, track_title, track_artist, track_short_url, track_thumbnail)
|
||||
VALUES (?, ?, ?, ?, ?, ?);
|
||||
)";
|
||||
|
||||
auto stmtRes = impl_->voidDb.prepare(sql);
|
||||
@@ -662,6 +820,7 @@ namespace Echoion::Api
|
||||
stmt.bind(3, track.title);
|
||||
stmt.bind(4, track.artist);
|
||||
stmt.bind(5, track.shortenedUrl.value_or(""));
|
||||
stmt.bind(6, track.thumbnailUrl.value_or(""));
|
||||
|
||||
[[maybe_unused]] auto stepRes = stmt.step();
|
||||
|
||||
@@ -716,7 +875,7 @@ namespace Echoion::Api
|
||||
std::vector<FavoriteTrack> favorites;
|
||||
|
||||
const char* sql = R"(
|
||||
SELECT track_url, track_title, track_artist, added_at, track_short_url
|
||||
SELECT track_url, track_title, track_artist, added_at, track_short_url, track_thumbnail
|
||||
FROM user_favorites
|
||||
WHERE user_id = ?
|
||||
ORDER BY added_at DESC;
|
||||
@@ -741,6 +900,9 @@ namespace Echoion::Api
|
||||
if (auto shortUrl = stmt.column_text(4); !shortUrl.empty()) {
|
||||
fav.track.shortenedUrl = shortUrl;
|
||||
}
|
||||
if (auto thumb = stmt.column_text(5); !thumb.empty()) {
|
||||
fav.track.thumbnailUrl = thumb;
|
||||
}
|
||||
fav.userId = userId;
|
||||
favorites.push_back(fav);
|
||||
}
|
||||
@@ -1052,7 +1214,7 @@ namespace Echoion::Api
|
||||
|
||||
// userId 0 = global history. Deduplicate by URL, newest first.
|
||||
const char* sql = R"(
|
||||
SELECT track_url, track_title, track_artist, MAX(played_at), MAX(track_short_url)
|
||||
SELECT track_url, track_title, track_artist, MAX(played_at), MAX(track_short_url), MAX(track_thumbnail)
|
||||
FROM playback_history
|
||||
WHERE (?1 = 0 OR played_by = ?1)
|
||||
GROUP BY track_url
|
||||
@@ -1076,6 +1238,9 @@ namespace Echoion::Api
|
||||
if (auto shortUrl = stmt.column_text(4); !shortUrl.empty()) {
|
||||
track.shortenedUrl = shortUrl;
|
||||
}
|
||||
if (auto thumb = stmt.column_text(5); !thumb.empty()) {
|
||||
track.thumbnailUrl = thumb;
|
||||
}
|
||||
tracks.push_back(std::move(track));
|
||||
}
|
||||
return tracks;
|
||||
@@ -1169,6 +1334,90 @@ namespace Echoion::Api
|
||||
return result;
|
||||
}
|
||||
|
||||
Result<AggregateStats> Database::getAggregateStats()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
AggregateStats stats;
|
||||
|
||||
// played_at/added_at are CURRENT_TIMESTAMP (UTC); "today" follows the
|
||||
// same clock.
|
||||
{
|
||||
const char* sql = R"(
|
||||
SELECT
|
||||
SUM(CASE WHEN completed = 1 AND date(played_at) = date('now') THEN 1 ELSE 0 END),
|
||||
SUM(CASE WHEN completed = 1 AND date(played_at) = date('now') THEN duration_ms ELSE 0 END),
|
||||
SUM(CASE WHEN skipped = 1 AND date(played_at) = date('now') THEN 1 ELSE 0 END),
|
||||
SUM(CASE WHEN completed = 1 THEN 1 ELSE 0 END),
|
||||
SUM(CASE WHEN skipped = 1 THEN 1 ELSE 0 END),
|
||||
SUM(CASE WHEN track_url LIKE '%youtu%' THEN 1 ELSE 0 END),
|
||||
SUM(CASE WHEN track_url LIKE '%yandex%' THEN 1 ELSE 0 END),
|
||||
COUNT(*)
|
||||
FROM playback_history;
|
||||
)";
|
||||
auto stmtRes = impl_->voidDb.prepare(sql);
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError,
|
||||
stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
if (stmt.step().value_or(false)) {
|
||||
stats.tracksToday = static_cast<uint64_t>(stmt.column_int(0));
|
||||
stats.listeningMsToday =
|
||||
static_cast<uint64_t>(stmt.column_int(1));
|
||||
stats.skipsToday = static_cast<uint64_t>(stmt.column_int(2));
|
||||
stats.playsTotal = static_cast<uint64_t>(stmt.column_int(3));
|
||||
stats.skipsTotal = static_cast<uint64_t>(stmt.column_int(4));
|
||||
stats.youtubeCount = static_cast<uint64_t>(stmt.column_int(5));
|
||||
stats.yandexCount = static_cast<uint64_t>(stmt.column_int(6));
|
||||
const auto total = static_cast<uint64_t>(stmt.column_int(7));
|
||||
stats.otherCount =
|
||||
total - std::min(total, stats.youtubeCount +
|
||||
stats.yandexCount);
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char* sql = R"(
|
||||
SELECT COUNT(*) FROM queue_log WHERE date(added_at) = date('now');
|
||||
)";
|
||||
auto stmtRes = impl_->voidDb.prepare(sql);
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError,
|
||||
stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
if (stmt.step().value_or(false)) {
|
||||
stats.queueAdditionsToday =
|
||||
static_cast<uint64_t>(stmt.column_int(0));
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
const char* sql = R"(
|
||||
SELECT nickname, COUNT(*) AS adds, MAX(uid) AS uid
|
||||
FROM queue_log
|
||||
WHERE nickname IS NOT NULL AND nickname != ''
|
||||
GROUP BY nickname
|
||||
ORDER BY adds DESC
|
||||
LIMIT 5;
|
||||
)";
|
||||
auto stmtRes = impl_->voidDb.prepare(sql);
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError,
|
||||
stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
while (stmt.step().value_or(false)) {
|
||||
stats.topRequesters.push_back(AggregateStats::TopRequester{
|
||||
.uid = stmt.column_text(2),
|
||||
.nickname = stmt.column_text(0),
|
||||
.count = static_cast<uint64_t>(stmt.column_int(1))});
|
||||
}
|
||||
}
|
||||
|
||||
return stats;
|
||||
}
|
||||
|
||||
Result<std::optional<std::string>> Database::getKv(const std::string& key)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
@@ -1202,6 +1451,152 @@ namespace Echoion::Api
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<std::vector<Database::CustomEmoji>> Database::getCustomEmojis()
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
auto stmtRes = impl_->voidDb.prepare(
|
||||
"SELECT name, mime, data, added_by FROM custom_emojis "
|
||||
"ORDER BY name;");
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
std::vector<CustomEmoji> out;
|
||||
while (stmt.step().value_or(false)) {
|
||||
out.push_back(CustomEmoji{.name = stmt.column_text(0),
|
||||
.mime = stmt.column_text(1),
|
||||
.dataBase64 = stmt.column_text(2),
|
||||
.addedBy = stmt.column_text(3)});
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Result<std::optional<Database::CustomEmoji>>
|
||||
Database::getCustomEmoji(const std::string& name)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
auto stmtRes = impl_->voidDb.prepare(
|
||||
"SELECT name, mime, data, added_by FROM custom_emojis "
|
||||
"WHERE name = ?;");
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, name);
|
||||
if (stmt.step().value_or(false)) {
|
||||
return std::optional<CustomEmoji>{
|
||||
CustomEmoji{.name = stmt.column_text(0),
|
||||
.mime = stmt.column_text(1),
|
||||
.dataBase64 = stmt.column_text(2),
|
||||
.addedBy = stmt.column_text(3)}};
|
||||
}
|
||||
return std::optional<CustomEmoji>{};
|
||||
}
|
||||
|
||||
Result<void> Database::addCustomEmoji(const std::string& name,
|
||||
const std::string& mime,
|
||||
const std::string& dataBase64,
|
||||
const std::string& addedBy)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||
auto stmtRes = impl_->voidDb.prepare(R"(
|
||||
INSERT OR REPLACE INTO custom_emojis (name, mime, data, added_by)
|
||||
VALUES (?, ?, ?, ?);
|
||||
)");
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, name).bind(2, mime).bind(3, dataBase64).bind(4, addedBy);
|
||||
if (auto stepRes = stmt.step(); !stepRes) {
|
||||
return fail(ErrorCode::DatabaseError, stepRes.error().message());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> Database::removeCustomEmoji(const std::string& name)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||
auto stmtRes =
|
||||
impl_->voidDb.prepare("DELETE FROM custom_emojis WHERE name = ?;");
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, name);
|
||||
[[maybe_unused]] auto stepRes = stmt.step();
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<std::optional<Database::CachedAvatar>>
|
||||
Database::getCachedAvatar(const std::string& uid)
|
||||
{
|
||||
std::shared_lock<std::shared_mutex> lock(mutex_);
|
||||
auto stmtRes = impl_->voidDb.prepare(
|
||||
"SELECT uid, mime, data, COALESCE(url, '') FROM cached_avatars "
|
||||
"WHERE uid = ?;");
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, uid);
|
||||
if (stmt.step().value_or(false)) {
|
||||
return std::optional<CachedAvatar>{
|
||||
CachedAvatar{.uid = stmt.column_text(0),
|
||||
.mime = stmt.column_text(1),
|
||||
.dataBase64 = stmt.column_text(2),
|
||||
.url = stmt.column_text(3)}};
|
||||
}
|
||||
return std::optional<CachedAvatar>{};
|
||||
}
|
||||
|
||||
Result<void> Database::putCachedAvatar(const std::string& uid,
|
||||
const std::string& mime,
|
||||
const std::string& dataBase64)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||
// Upsert the image but keep any url already recorded for this uid.
|
||||
auto stmtRes = impl_->voidDb.prepare(R"(
|
||||
INSERT INTO cached_avatars (uid, mime, data, updated_at)
|
||||
VALUES (?, ?, ?, CURRENT_TIMESTAMP)
|
||||
ON CONFLICT(uid) DO UPDATE SET
|
||||
mime = excluded.mime,
|
||||
data = excluded.data,
|
||||
updated_at = CURRENT_TIMESTAMP;
|
||||
)");
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, uid).bind(2, mime).bind(3, dataBase64);
|
||||
if (auto stepRes = stmt.step(); !stepRes) {
|
||||
return fail(ErrorCode::DatabaseError, stepRes.error().message());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> Database::putCachedAvatarUrl(const std::string& uid,
|
||||
const std::string& url)
|
||||
{
|
||||
std::unique_lock<std::shared_mutex> lock(mutex_);
|
||||
// Insert a url-only row (empty mime/data satisfy NOT NULL) or update the
|
||||
// url on an existing one, without touching cached bytes.
|
||||
auto stmtRes = impl_->voidDb.prepare(R"(
|
||||
INSERT INTO cached_avatars (uid, mime, data, url)
|
||||
VALUES (?, '', '', ?)
|
||||
ON CONFLICT(uid) DO UPDATE SET url = excluded.url;
|
||||
)");
|
||||
if (!stmtRes) {
|
||||
return fail(ErrorCode::DatabaseError, stmtRes.error().message());
|
||||
}
|
||||
auto& stmt = *stmtRes;
|
||||
stmt.bind(1, uid).bind(2, url);
|
||||
if (auto stepRes = stmt.step(); !stepRes) {
|
||||
return fail(ErrorCode::DatabaseError, stepRes.error().message());
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
Result<void> Database::executeQuery(const std::string& sql,
|
||||
RowCallback callback)
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user