Skip to content

Commit

Permalink
Reformat after merge.
Browse files Browse the repository at this point in the history
  • Loading branch information
michalmoc committed May 26, 2024
1 parent 94d761e commit fa7f193
Show file tree
Hide file tree
Showing 27 changed files with 343 additions and 329 deletions.
6 changes: 3 additions & 3 deletions approot/multisearch.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
${cover}
</div>
<div class="p-1">
<i class="fa fa-music text-secondary" aria-hidden="true"></i>
<i class="fa fa-music" aria-hidden="true"></i>
</div>
<div class="row align-items-center flex-fill overflow-hidden">
<div class="col-12 col-md-6 col-lg-4">
Expand Down Expand Up @@ -74,7 +74,7 @@
${cover}
</div>
<div class="p-1">
<i class="fa fa-list text-primary" aria-hidden="true"></i>
<i class="fa fa-list" aria-hidden="true"></i>
</div>
<div class="row align-items-center flex-fill overflow-hidden">
<div class="col-12 col-md-6 col-lg-4">
Expand Down Expand Up @@ -117,7 +117,7 @@
${cover}
</div>
<div class="p-1">
<i class="fa fa-user text-info" aria-hidden="true"></i>
<i class="fa fa-user" aria-hidden="true"></i>
</div>
<div class="row align-items-center flex-fill overflow-hidden">
<div class="col-12 col-md-6 col-lg-4">
Expand Down
46 changes: 22 additions & 24 deletions src/libs/database/impl/AnyMedium.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

using namespace lms::db;

AnyMediumId any_medium::fromString(const std::string &type, const Wt::Dbo::dbo_default_traits::IdType id)
AnyMediumId any_medium::fromString(const std::string& type, const Wt::Dbo::dbo_default_traits::IdType id)
{
if (type == "artist")
return ArtistId(id);
Expand All @@ -21,19 +21,18 @@ AnyMediumId any_medium::fromString(const std::string &type, const Wt::Dbo::dbo_d
throw std::logic_error("unknown medium type");
}

RangeResults<AnyMediumId> any_medium::findIds(Session &session, Type type, const std::vector<std::string_view> &keywords,
std::span<const ClusterId> clusters, MediaLibraryId mediaLibrary,
std::optional<Range> range)
RangeResults<AnyMediumId> any_medium::findIds(Session& session, Type type, const std::vector<std::string_view>& keywords,
std::span<const ClusterId> clusters, MediaLibraryId mediaLibrary,
std::optional<Range> range)
{
using Columns = std::tuple<std::string, Wt::Dbo::dbo_default_traits::IdType, int>;

session.checkReadTransaction();

auto media_library_query = session.getDboSession()->query<Wt::Dbo::dbo_default_traits::IdType>("SELECT json_each.value FROM json_each(media_library_ids)")
.where("json_each.value = ?").bind(mediaLibrary.getValue());
auto media_library_query = session.getDboSession()->query<Wt::Dbo::dbo_default_traits::IdType>("SELECT json_each.value FROM json_each(media_library_ids)").where("json_each.value = ?").bind(mediaLibrary.getValue());

auto cluster_query = session.getDboSession()->query<Wt::Dbo::dbo_default_traits::IdType>("SELECT json_each.value FROM json_each(cluster_ids)");
for (auto cluster_id: clusters)
for (auto cluster_id : clusters)
cluster_query.orWhere("json_each.value = ?").bind(cluster_id.getValue());

auto query = session.getDboSession()->query<Columns>(R"(
Expand All @@ -54,17 +53,17 @@ RangeResults<AnyMediumId> any_medium::findIds(Session &session, Type type, const

switch (type)
{
case Type::ALL:
break;
case Type::RELEASES:
query.where("type = 'release'");
break;
case Type::ARTISTS:
query.where("type = 'artist'");
break;
case Type::TRACKS:
query.where("type = 'track'");
break;
case Type::ALL:
break;
case Type::RELEASES:
query.where("type = 'release'");
break;
case Type::ARTISTS:
query.where("type = 'artist'");
break;
case Type::TRACKS:
query.where("type = 'track'");
break;
}

query
Expand All @@ -75,7 +74,7 @@ RangeResults<AnyMediumId> any_medium::findIds(Session &session, Type type, const

auto results = std::vector<AnyMediumId>();
results.reserve(columns.results.size());
for (const auto&[type, id, _] : columns.results)
for (const auto& [type, id, _] : columns.results)
results.emplace_back(fromString(type, id));

return {
Expand All @@ -85,10 +84,9 @@ RangeResults<AnyMediumId> any_medium::findIds(Session &session, Type type, const
};
}

std::ostream & lms::db::operator<<(std::ostream &os, const AnyMediumId &v)
std::ostream& lms::db::operator<<(std::ostream& os, const AnyMediumId& v)
{
std::visit([&os](auto&& arg)
{
std::visit([&os](auto&& arg) {
using T = std::decay_t<decltype(arg)>;
if constexpr (std::is_same_v<T, ArtistId>)
os << "Artist(" << arg.getValue() << ")";
Expand All @@ -98,7 +96,7 @@ std::ostream & lms::db::operator<<(std::ostream &os, const AnyMediumId &v)
os << "Track(" << arg.getValue() << ")";
else
static_assert(false, "inexhaustible patterns");

}, v);
},
v);
return os;
}
20 changes: 11 additions & 9 deletions src/libs/database/include/database/AnyMedium.hpp
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#pragma once

#include <optional>
#include <variant>
#include <vector>
#include <optional>

#include "ArtistId.hpp"
#include "ClusterId.hpp"
Expand All @@ -11,7 +11,6 @@
#include "TrackId.hpp"
#include "Types.hpp"


namespace lms::db
{
class Session;
Expand All @@ -23,12 +22,15 @@ namespace lms::db
{
enum class Type
{
ALL, RELEASES, ARTISTS, TRACKS
ALL,
RELEASES,
ARTISTS,
TRACKS
};

AnyMediumId fromString(const std::string &type, Wt::Dbo::dbo_default_traits::IdType id);
RangeResults<AnyMediumId> findIds(Session &session, Type type, const std::vector<std::string_view> &keywords,
std::span<const ClusterId> clusters, MediaLibraryId mediaLibrary,
std::optional<Range> range);
}
}
AnyMediumId fromString(const std::string& type, Wt::Dbo::dbo_default_traits::IdType id);
RangeResults<AnyMediumId> findIds(Session& session, Type type, const std::vector<std::string_view>& keywords,
std::span<const ClusterId> clusters, MediaLibraryId mediaLibrary,
std::optional<Range> range);
} // namespace any_medium
} // namespace lms::db
5 changes: 3 additions & 2 deletions src/libs/database/include/database/ArtistId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class Artist;
namespace lms::db
{
class Artist;
}

LMS_DECLARE_IDTYPE(ArtistId, lms::db::Artist)
9 changes: 5 additions & 4 deletions src/libs/database/include/database/ClusterId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

#include "database/IdType.hpp"

namespace lms::db {
class Cluster;
class ClusterType;
}
namespace lms::db
{
class Cluster;
class ClusterType;
} // namespace lms::db

LMS_DECLARE_IDTYPE(ClusterId, lms::db::Cluster)
LMS_DECLARE_IDTYPE(ClusterTypeId, lms::db::ClusterType)
37 changes: 19 additions & 18 deletions src/libs/database/include/database/IdType.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,25 @@ namespace lms::db
Wt::Dbo::dbo_default_traits::IdType _id{ Wt::Dbo::dbo_default_traits::invalidId() };
};

#define LMS_DECLARE_IDTYPE(name, target) \
namespace lms::db { \
class name : public IdType \
{ \
public: \
using IdType::IdType; \
using Target = target; \
auto operator<=>(const name& other) const = default; \
};\
} \
namespace std \
{ \
template<> \
class hash<lms::db::name> \
{ \
public: \
size_t operator()(lms::db::name id) const \
{ \
#define LMS_DECLARE_IDTYPE(name, target) \
namespace lms::db \
{ \
class name : public IdType \
{ \
public: \
using IdType::IdType; \
using Target = target; \
auto operator<=>(const name& other) const = default; \
}; \
} \
namespace std \
{ \
template<> \
class hash<lms::db::name> \
{ \
public: \
size_t operator()(lms::db::name id) const \
{ \
return std::hash<lms::db::name::ValueType>()(id.getValue()); \
} \
}; \
Expand Down
5 changes: 3 additions & 2 deletions src/libs/database/include/database/ListenId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class Listen;
namespace lms::db
{
class Listen;
}

LMS_DECLARE_IDTYPE(ListenId, lms::db::Listen)
5 changes: 3 additions & 2 deletions src/libs/database/include/database/MediaLibraryId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class MediaLibrary;
namespace lms::db
{
class MediaLibrary;
}

LMS_DECLARE_IDTYPE(MediaLibraryId, lms::db::MediaLibrary)
5 changes: 3 additions & 2 deletions src/libs/database/include/database/ReleaseId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class Release;
namespace lms::db
{
class Release;
}

LMS_DECLARE_IDTYPE(ReleaseId, lms::db::Release)
5 changes: 3 additions & 2 deletions src/libs/database/include/database/ReleaseTypeId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class ReleaseType;
namespace lms::db
{
class ReleaseType;
}

LMS_DECLARE_IDTYPE(ReleaseTypeId, lms::db::ReleaseType)
5 changes: 3 additions & 2 deletions src/libs/database/include/database/StarredArtistId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class StarredArtist;
namespace lms::db
{
class StarredArtist;
}

LMS_DECLARE_IDTYPE(StarredArtistId, lms::db::StarredArtist)
5 changes: 3 additions & 2 deletions src/libs/database/include/database/StarredReleaseId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class StarredRelease;
namespace lms::db
{
class StarredRelease;
}

LMS_DECLARE_IDTYPE(StarredReleaseId, lms::db::StarredRelease)
5 changes: 3 additions & 2 deletions src/libs/database/include/database/StarredTrackId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class StarredTrack;
namespace lms::db
{
class StarredTrack;
}

LMS_DECLARE_IDTYPE(StarredTrackId, lms::db::StarredTrack)
3 changes: 2 additions & 1 deletion src/libs/database/include/database/TrackArtistLink.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@
#include "database/TrackId.hpp"
#include "database/Types.hpp"

namespace lms::db {
namespace lms::db
{
class TrackArtistLink;
}

Expand Down
3 changes: 2 additions & 1 deletion src/libs/database/include/database/TrackBookmark.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@
#include "database/Types.hpp"
#include "database/UserId.hpp"

namespace lms::db {
namespace lms::db
{
class TrackBookmark;
}

Expand Down
3 changes: 2 additions & 1 deletion src/libs/database/include/database/TrackFeatures.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@
#include "database/TrackId.hpp"
#include "database/Types.hpp"

namespace lms::db {
namespace lms::db
{
class TrackFeatures;
}

Expand Down
5 changes: 3 additions & 2 deletions src/libs/database/include/database/TrackId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class Track;
namespace lms::db
{
class Track;
}

LMS_DECLARE_IDTYPE(TrackId, lms::db::Track)
9 changes: 5 additions & 4 deletions src/libs/database/include/database/TrackListId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,11 @@

#include "database/IdType.hpp"

namespace lms::db {
class TrackListEntry;
class TrackList;
}
namespace lms::db
{
class TrackListEntry;
class TrackList;
} // namespace lms::db

LMS_DECLARE_IDTYPE(TrackListId, lms::db::TrackList)

Expand Down
5 changes: 3 additions & 2 deletions src/libs/database/include/database/UserId.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@

#include "database/IdType.hpp"

namespace lms::db {
class User;
namespace lms::db
{
class User;
}

LMS_DECLARE_IDTYPE(UserId, lms::db::User)
Loading

0 comments on commit fa7f193

Please sign in to comment.