예제 #1
0
bool Database::addPlaylist(const Playlist &playlist)
{
    try
    {
        _work.parameterized("INSERT INTO playlists (user_id, name, is_public) VALUES ($1, $2, $3);")
                (playlist.userId())(playlist.name())(playlist.isPublic()).exec();
    }
    catch (const pqxx::unique_violation &e)
    {
        return false;
    }

    return true;
}
예제 #2
0
UpdateStatus Database::updatePlaylist(const Playlist &playlist)
{
    pqxx::result res;
    try
    {
        res = _work.parameterized("UPDATE playlists "
                                  "SET name=$1, "
                                  "is_public=$2 "
                                  "WHERE id=$3 "
                                  "  AND user_id=$4;")
                                  (playlist.name())(playlist.isPublic())
                                  (playlist.id())(playlist.userId()).exec();
    }
    catch (const pqxx::unique_violation &e)
    {
        return UpdateStatus::CONFLICT;
    }

    return res.affected_rows() == 1 ? UpdateStatus::UPDATED : UpdateStatus::NOT_FOUND;
}