keep working on the like button
This commit is contained in:
@@ -154,6 +154,22 @@ void Database::addPost(const Post& post) {
|
||||
sqlite3_finalize(stmt);
|
||||
}
|
||||
|
||||
void Database::addLike(uint64_t postId, uint64_t userId) {
|
||||
std::stringstream sql;
|
||||
sql << R"(
|
||||
UPDATE posts
|
||||
SET likes = likes + 1
|
||||
WHERE id =
|
||||
)";
|
||||
sql << postId << ";";
|
||||
std::string sqlstr = sql.str();
|
||||
|
||||
char* errmsg = nullptr;
|
||||
if (sqlite3_exec(db, sqlstr.c_str(), nullptr, nullptr, &errmsg) != SQLITE_OK) {
|
||||
throw std::runtime_error("sqlite3 error: " + std::string(errmsg));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user