{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fno-warn-missing-signatures #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module WikiMusic.Sqlite.ArtistQuery () where

import Data.Map (elems, keys)
import Data.Map qualified as Map
import Data.UUID qualified as UUID
import Database.Beam
import Database.Beam.Sqlite
import WikiMusic.Beam.Artist
import WikiMusic.Beam.Database
import WikiMusic.Beam.Util
import WikiMusic.Free.ArtistQuery
import WikiMusic.Model.Artist
import WikiMusic.Model.Other
import WikiMusic.Model.Thread as CommentThread
import WikiMusic.Protolude

instance Exec ArtistQuery where
  execAlgebra :: forall a. ArtistQuery (IO a) -> IO a
execAlgebra (FetchArtists Env
env ArtistSortOrder
sortOrder Limit
limit Offset
offset (Map UUID Artist, [UUID]) -> IO a
next) =
    (Map UUID Artist, [UUID]) -> IO a
next ((Map UUID Artist, [UUID]) -> IO a)
-> IO (Map UUID Artist, [UUID]) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env
-> ArtistSortOrder
-> Limit
-> Offset
-> IO (Map UUID Artist, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env
-> ArtistSortOrder
-> Limit
-> Offset
-> m (Map UUID Artist, [UUID])
fetchArtists' Env
env ArtistSortOrder
sortOrder Limit
limit Offset
offset
  execAlgebra (FetchArtistsByUUID Env
env ArtistSortOrder
sortOrder [UUID]
identifiers (Map UUID Artist, [UUID]) -> IO a
next) =
    (Map UUID Artist, [UUID]) -> IO a
next ((Map UUID Artist, [UUID]) -> IO a)
-> IO (Map UUID Artist, [UUID]) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> ArtistSortOrder -> [UUID] -> IO (Map UUID Artist, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> ArtistSortOrder -> [UUID] -> m (Map UUID Artist, [UUID])
fetchArtistsByUUID' Env
env ArtistSortOrder
sortOrder [UUID]
identifiers
  execAlgebra (EnrichedArtistResponse Env
env Map UUID Artist
artistMap EnrichArtistParams
enrichArtistParams Map UUID Artist -> IO a
next) =
    Map UUID Artist -> IO a
next (Map UUID Artist -> IO a) -> IO (Map UUID Artist) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env
-> Map UUID Artist -> EnrichArtistParams -> IO (Map UUID Artist)
forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID Artist -> EnrichArtistParams -> m (Map UUID Artist)
enrichedArtistResponse' Env
env Map UUID Artist
artistMap EnrichArtistParams
enrichArtistParams
  execAlgebra (FetchArtistComments Env
env [UUID]
identifiers Map UUID ArtistComment -> IO a
next) =
    Map UUID ArtistComment -> IO a
next (Map UUID ArtistComment -> IO a)
-> IO (Map UUID ArtistComment) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Map UUID ArtistComment)
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID ArtistComment)
fetchArtistComments' Env
env [UUID]
identifiers
  execAlgebra (FetchArtistOpinions Env
env [UUID]
identifiers Map UUID ArtistOpinion -> IO a
next) =
    Map UUID ArtistOpinion -> IO a
next (Map UUID ArtistOpinion -> IO a)
-> IO (Map UUID ArtistOpinion) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Map UUID ArtistOpinion)
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID ArtistOpinion)
fetchArtistOpinions' Env
env [UUID]
identifiers
  execAlgebra (SearchArtists Env
env SearchInput
searchInput ArtistSortOrder
sortOrder Limit
limit Offset
offset (Map UUID Artist, [UUID]) -> IO a
next) =
    (Map UUID Artist, [UUID]) -> IO a
next ((Map UUID Artist, [UUID]) -> IO a)
-> IO (Map UUID Artist, [UUID]) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env
-> SearchInput
-> ArtistSortOrder
-> Limit
-> Offset
-> IO (Map UUID Artist, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env
-> SearchInput
-> ArtistSortOrder
-> Limit
-> Offset
-> m (Map UUID Artist, [UUID])
searchArtists' Env
env SearchInput
searchInput ArtistSortOrder
sortOrder Limit
limit Offset
offset
  execAlgebra (FetchArtistArtworks Env
env [UUID]
identifiers Map UUID ArtistArtwork -> IO a
next) =
    Map UUID ArtistArtwork -> IO a
next (Map UUID ArtistArtwork -> IO a)
-> IO (Map UUID ArtistArtwork) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Map UUID ArtistArtwork)
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID ArtistArtwork)
fetchArtistArtworks' Env
env [UUID]
identifiers

mkOrderBy :: ArtistSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy ArtistSortOrder
AscCreatedAt = (a -> QOrd be s a)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall s a ordering be (db :: (* -> *) -> *).
(Projectible be a, SqlOrderable be ordering,
 ThreadRewritable (QNested s) a) =>
(a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ (QExpr be s a -> QOrd be s a
forall be s a. BeamSqlBackend be => QExpr be s a -> QOrd be s a
asc_ (QExpr be s a -> QOrd be s a)
-> (a -> QExpr be s a) -> a -> QOrd be s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Optic' k NoIx a (QExpr be s a) -> QExpr be s a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx a (QExpr be s a)
#createdAt))
mkOrderBy ArtistSortOrder
DescCreatedAt = (a -> QOrd be s a)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall s a ordering be (db :: (* -> *) -> *).
(Projectible be a, SqlOrderable be ordering,
 ThreadRewritable (QNested s) a) =>
(a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ (QExpr be s a -> QOrd be s a
forall be s a. BeamSqlBackend be => QExpr be s a -> QOrd be s a
desc_ (QExpr be s a -> QOrd be s a)
-> (a -> QExpr be s a) -> a -> QOrd be s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Optic' k NoIx a (QExpr be s a) -> QExpr be s a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx a (QExpr be s a)
#createdAt))
mkOrderBy ArtistSortOrder
AscDisplayName = (a -> QOrd be s a)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall s a ordering be (db :: (* -> *) -> *).
(Projectible be a, SqlOrderable be ordering,
 ThreadRewritable (QNested s) a) =>
(a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ (QExpr be s a -> QOrd be s a
forall be s a. BeamSqlBackend be => QExpr be s a -> QOrd be s a
asc_ (QExpr be s a -> QOrd be s a)
-> (a -> QExpr be s a) -> a -> QOrd be s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Optic' k NoIx a (QExpr be s a) -> QExpr be s a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx a (QExpr be s a)
#displayName))
mkOrderBy ArtistSortOrder
DescDisplayName = (a -> QOrd be s a)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall s a ordering be (db :: (* -> *) -> *).
(Projectible be a, SqlOrderable be ordering,
 ThreadRewritable (QNested s) a) =>
(a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ (QExpr be s a -> QOrd be s a
forall be s a. BeamSqlBackend be => QExpr be s a -> QOrd be s a
desc_ (QExpr be s a -> QOrd be s a)
-> (a -> QExpr be s a) -> a -> QOrd be s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Optic' k NoIx a (QExpr be s a) -> QExpr be s a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx a (QExpr be s a)
#displayName))
mkOrderBy ArtistSortOrder
AscLastEditedAt = (a -> QOrd be s a)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall s a ordering be (db :: (* -> *) -> *).
(Projectible be a, SqlOrderable be ordering,
 ThreadRewritable (QNested s) a) =>
(a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ (QExpr be s a -> QOrd be s a
forall be s a. BeamSqlBackend be => QExpr be s a -> QOrd be s a
asc_ (QExpr be s a -> QOrd be s a)
-> (a -> QExpr be s a) -> a -> QOrd be s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Optic' k NoIx a (QExpr be s a) -> QExpr be s a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx a (QExpr be s a)
#lastEditedAt))
mkOrderBy ArtistSortOrder
DescLastEditedAt = (a -> QOrd be s a)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
forall s a ordering be (db :: (* -> *) -> *).
(Projectible be a, SqlOrderable be ordering,
 ThreadRewritable (QNested s) a) =>
(a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ (QExpr be s a -> QOrd be s a
forall be s a. BeamSqlBackend be => QExpr be s a -> QOrd be s a
desc_ (QExpr be s a -> QOrd be s a)
-> (a -> QExpr be s a) -> a -> QOrd be s a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Optic' k NoIx a (QExpr be s a) -> QExpr be s a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx a (QExpr be s a)
#lastEditedAt))

-- | Fetch artists from storage, according to a sort order, limit and offset
fetchArtists' :: (MonadIO m) => Env -> ArtistSortOrder -> Limit -> Offset -> m (Map UUID Artist, [UUID])
fetchArtists' :: forall (m :: * -> *).
MonadIO m =>
Env
-> ArtistSortOrder
-> Limit
-> Offset
-> m (Map UUID Artist, [UUID])
fetchArtists' Env
env ArtistSortOrder
sortOrder (Limit Int
limit) (Offset Int
offset) = do
  [Artist']
artists <- IO [Artist'] -> m [Artist']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Artist'] -> m [Artist']) -> IO [Artist'] -> m [Artist']
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection -> SqliteM [Artist'] -> IO [Artist']
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM [Artist'] -> IO [Artist'])
-> SqliteM [Artist'] -> IO [Artist']
forall a b. (a -> b) -> a -> b
$ do
    SqlSelect Sqlite Artist' -> SqliteM [Artist']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
      (SqlSelect Sqlite Artist' -> SqliteM [Artist'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> SqlSelect Sqlite Artist')
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Artist']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (WithRewrittenThread
     (QNested QBaseScope)
     QBaseScope
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (WithRewrittenThread
           (QNested QBaseScope)
           QBaseScope
           (WithRewrittenThread
              (QNested (QNested QBaseScope))
              (QNested QBaseScope)
              (ArtistT
                 (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (WithRewrittenThread
     (QNested QBaseScope)
     QBaseScope
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect Sqlite Artist'
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (WithRewrittenThread
      (QNested QBaseScope)
      QBaseScope
      (WithRewrittenThread
         (QNested (QNested QBaseScope))
         (QNested QBaseScope)
         (ArtistT
            (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
 -> SqlSelect Sqlite Artist')
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (WithRewrittenThread
            (QNested QBaseScope)
            QBaseScope
            (WithRewrittenThread
               (QNested (QNested QBaseScope))
               (QNested QBaseScope)
               (ArtistT
                  (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqlSelect Sqlite Artist'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall s a be (db :: (* -> *) -> *).
(Projectible be a, ThreadRewritable (QNested s) a) =>
Integer
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
limit_ (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
limit)
      (Q Sqlite
   WikiMusicDatabase
   (QNested QBaseScope)
   (WithRewrittenThread
      (QNested (QNested QBaseScope))
      (QNested QBaseScope)
      (ArtistT
         (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (WithRewrittenThread
         (QNested QBaseScope)
         QBaseScope
         (WithRewrittenThread
            (QNested (QNested QBaseScope))
            (QNested QBaseScope)
            (ArtistT
               (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> Q Sqlite
         WikiMusicDatabase
         (QNested QBaseScope)
         (WithRewrittenThread
            (QNested (QNested QBaseScope))
            (QNested QBaseScope)
            (ArtistT
               (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested QBaseScope))
     (ArtistT
        (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
forall s a be (db :: (* -> *) -> *).
(Projectible be a, ThreadRewritable (QNested s) a) =>
Integer
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
offset_ (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
offset)
      (Q Sqlite
   WikiMusicDatabase
   (QNested (QNested QBaseScope))
   (ArtistT
      (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
 -> Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (WithRewrittenThread
         (QNested (QNested QBaseScope))
         (QNested QBaseScope)
         (ArtistT
            (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> Q Sqlite
         WikiMusicDatabase
         (QNested (QNested QBaseScope))
         (ArtistT
            (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArtistSortOrder
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested QBaseScope))
     (WithRewrittenThread
        (QNested (QNested (QNested QBaseScope)))
        (QNested (QNested QBaseScope))
        (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope))))))
forall {be} {a} {s} {k} {k} {k} {s} {a} {s} {a} {s} {a}
       {db :: (* -> *) -> *}.
(Sql92OrderingExpressionSyntax
   (Sql92SelectOrderingSyntax
      (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92TableSourceExpressionSyntax
   (Sql92FromTableSourceSyntax
      (Sql92SelectTableFromSyntax
         (Sql92SelectSelectTableSyntax
            (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92GroupingExpressionSyntax
   (Sql92SelectTableGroupingSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92ExpressionSelectSyntax
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92SelectSyntax (BeamSqlBackendSyntax be),
 Sql92ProjectionExpressionSyntax
   (Sql92SelectTableProjectionSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92InsertValuesExpressionSyntax
   (Sql92InsertValuesSyntax
      (Sql92InsertSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92FromExpressionSyntax
   (Sql92SelectTableFromSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92UpdateFieldNameSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 ~ Sql92ExpressionFieldNameSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 ProjectibleWithPredicate
   AnyType
   be
   (WithExprContext (BeamSqlBackendExpressionSyntax' be))
   a,
 ThreadRewritable (QNested s) a, BeamSqlBackend be, Is k A_Getter,
 Is k A_Getter, Is k A_Getter,
 LabelOptic "createdAt" k a a (QExpr be s a) (QExpr be s a),
 LabelOptic "lastEditedAt" k a a (QExpr be s a) (QExpr be s a),
 LabelOptic "displayName" k a a (QExpr be s a) (QExpr be s a),
 IsSql92AggregationExpressionSyntax
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 Eq
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 HasSqlValueSyntax
   (Sql92ExpressionValueSyntax
      (Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
   SqlNull) =>
ArtistSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy ArtistSortOrder
sortOrder
      (Q Sqlite
   WikiMusicDatabase
   (QNested (QNested (QNested QBaseScope)))
   (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
 -> SqliteM [Artist'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Artist']
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
  Env -> [Artist'] -> m (Map UUID Artist, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> [Artist'] -> m (Map UUID Artist, [UUID])
filledArtists Env
env [Artist']
artists

-- | Fetch artists by UUID from storage, according to a sort order
fetchArtistsByUUID' :: (MonadIO m) => Env -> ArtistSortOrder -> [UUID] -> m (Map UUID Artist, [UUID])
fetchArtistsByUUID' :: forall (m :: * -> *).
MonadIO m =>
Env -> ArtistSortOrder -> [UUID] -> m (Map UUID Artist, [UUID])
fetchArtistsByUUID' Env
env ArtistSortOrder
sortOrder [UUID]
identifiers = do
  [Artist']
artists <-
    IO [Artist'] -> m [Artist']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO [Artist'] -> m [Artist'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> IO [Artist'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [Artist']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ())
-> Connection -> SqliteM [Artist'] -> IO [Artist']
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
      (SqliteM [Artist'] -> IO [Artist'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> SqliteM [Artist'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> IO [Artist']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSelect Sqlite Artist' -> SqliteM [Artist']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
      (SqlSelect Sqlite Artist' -> SqliteM [Artist'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> SqlSelect Sqlite Artist')
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqliteM [Artist']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)))
Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite Artist'
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
 -> SqlSelect Sqlite Artist')
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqlSelect Sqlite Artist'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_ (\ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
s ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
     (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#identifier) QGenExpr QValueContext Sqlite QBaseScope Text
-> [QGenExpr QValueContext Sqlite QBaseScope Text]
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite QBaseScope Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite QBaseScope Text
HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> (UUID -> Text)
-> UUID
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)))
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArtistSortOrder
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))))
forall {be} {a} {s} {k} {k} {k} {s} {a} {s} {a} {s} {a}
       {db :: (* -> *) -> *}.
(Sql92OrderingExpressionSyntax
   (Sql92SelectOrderingSyntax
      (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92TableSourceExpressionSyntax
   (Sql92FromTableSourceSyntax
      (Sql92SelectTableFromSyntax
         (Sql92SelectSelectTableSyntax
            (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92GroupingExpressionSyntax
   (Sql92SelectTableGroupingSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92ExpressionSelectSyntax
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92SelectSyntax (BeamSqlBackendSyntax be),
 Sql92ProjectionExpressionSyntax
   (Sql92SelectTableProjectionSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92InsertValuesExpressionSyntax
   (Sql92InsertValuesSyntax
      (Sql92InsertSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92FromExpressionSyntax
   (Sql92SelectTableFromSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92UpdateFieldNameSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 ~ Sql92ExpressionFieldNameSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 ProjectibleWithPredicate
   AnyType
   be
   (WithExprContext (BeamSqlBackendExpressionSyntax' be))
   a,
 ThreadRewritable (QNested s) a, BeamSqlBackend be, Is k A_Getter,
 Is k A_Getter, Is k A_Getter,
 LabelOptic "createdAt" k a a (QExpr be s a) (QExpr be s a),
 LabelOptic "lastEditedAt" k a a (QExpr be s a) (QExpr be s a),
 LabelOptic "displayName" k a a (QExpr be s a) (QExpr be s a),
 IsSql92AggregationExpressionSyntax
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 Eq
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 HasSqlValueSyntax
   (Sql92ExpressionValueSyntax
      (Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
   SqlNull) =>
ArtistSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy ArtistSortOrder
sortOrder
      (Q Sqlite
   WikiMusicDatabase
   (QNested QBaseScope)
   (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
 -> m [Artist'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [Artist']
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
  Env -> [Artist'] -> m (Map UUID Artist, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> [Artist'] -> m (Map UUID Artist, [UUID])
filledArtists Env
env [Artist']
artists

-- | Fetch artist artworks from storage
fetchArtistArtworks' :: (MonadIO m) => Env -> [UUID] -> m (Map UUID ArtistArtwork)
fetchArtistArtworks' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID ArtistArtwork)
fetchArtistArtworks' Env
env [UUID]
identifiers = do
  [ArtistArtwork']
artworks <- IO [ArtistArtwork'] -> m [ArtistArtwork']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO [ArtistArtwork'] -> m [ArtistArtwork'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistArtworkT
         (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> IO [ArtistArtwork'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [ArtistArtwork']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ())
-> Connection -> SqliteM [ArtistArtwork'] -> IO [ArtistArtwork']
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
    (SqliteM [ArtistArtwork'] -> IO [ArtistArtwork'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistArtworkT
         (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> SqliteM [ArtistArtwork'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> IO [ArtistArtwork']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSelect Sqlite ArtistArtwork' -> SqliteM [ArtistArtwork']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
    (SqlSelect Sqlite ArtistArtwork' -> SqliteM [ArtistArtwork'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistArtworkT
         (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> SqlSelect Sqlite ArtistArtwork')
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqliteM [ArtistArtwork']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistArtworkT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistArtworkT (QGenExpr QValueContext Sqlite QBaseScope)))
Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistArtworkT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite ArtistArtwork'
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select
    (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistArtworkT (QGenExpr QValueContext Sqlite QBaseScope))
 -> SqlSelect Sqlite ArtistArtwork')
-> (Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistArtworkT
         (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (ArtistArtworkT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqlSelect Sqlite ArtistArtwork'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArtistArtworkT
   (QGenExpr QValueContext Sqlite (QNested QBaseScope))
 -> QOrd Sqlite (QNested QBaseScope) Int64)
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (ArtistArtworkT
           (QGenExpr QValueContext Sqlite (QNested QBaseScope))))
forall s a ordering be (db :: (* -> *) -> *).
(Projectible be a, SqlOrderable be ordering,
 ThreadRewritable (QNested s) a) =>
(a -> ordering)
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
orderBy_ (QExpr Sqlite (QNested QBaseScope) Int64
-> QOrd Sqlite (QNested QBaseScope) Int64
forall be s a. BeamSqlBackend be => QExpr be s a -> QOrd be s a
asc_ (QExpr Sqlite (QNested QBaseScope) Int64
 -> QOrd Sqlite (QNested QBaseScope) Int64)
-> (ArtistArtworkT
      (QGenExpr QValueContext Sqlite (QNested QBaseScope))
    -> QExpr Sqlite (QNested QBaseScope) Int64)
-> ArtistArtworkT
     (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> QOrd Sqlite (QNested QBaseScope) Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArtistArtworkT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Optic'
     A_Lens
     NoIx
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
     (QExpr Sqlite (QNested QBaseScope) Int64)
-> QExpr Sqlite (QNested QBaseScope) Int64
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistArtworkT
     (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
  (QExpr Sqlite (QNested QBaseScope) Int64)
#orderValue))
    (Q Sqlite
   WikiMusicDatabase
   (QNested QBaseScope)
   (ArtistArtworkT
      (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
 -> m [ArtistArtwork'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [ArtistArtwork']
forall a b. (a -> b) -> a -> b
$ do
      ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
songs <-
        (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
 -> QExpr Sqlite (QNested QBaseScope) Bool)
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_ (\ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
s -> (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
s ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Optic'
     A_Lens
     NoIx
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
     (QGenExpr QValueContext Sqlite (QNested QBaseScope) Text)
-> QGenExpr QValueContext Sqlite (QNested QBaseScope) Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
  (QGenExpr QValueContext Sqlite (QNested QBaseScope) Text)
#identifier) QGenExpr QValueContext Sqlite (QNested QBaseScope) Text
-> [QGenExpr QValueContext Sqlite (QNested QBaseScope) Text]
-> QExpr Sqlite (QNested QBaseScope) Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite (QNested QBaseScope) Text)
-> [UUID]
-> [QGenExpr QValueContext Sqlite (QNested QBaseScope) Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite (QNested QBaseScope) Text
HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite (QNested QBaseScope) Text)
-> QGenExpr QValueContext Sqlite (QNested QBaseScope) Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite (QNested QBaseScope) Text)
-> (UUID -> Text)
-> UUID
-> QGenExpr QValueContext Sqlite (QNested QBaseScope) Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
          (Q Sqlite
   WikiMusicDatabase
   (QNested QBaseScope)
   (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
 -> Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
-> (ArtistArtworkT
      (QGenExpr QValueContext Sqlite (QNested QBaseScope))
    -> PrimaryKey
         ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
forall be (db :: (* -> *) -> *) (tbl :: (* -> *) -> *)
       (rel :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be,
 HasTableEquality be (PrimaryKey tbl), Table tbl, Table rel) =>
DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> PrimaryKey tbl (QExpr be s))
-> tbl (QExpr be s)
-> Q be db s (rel (QExpr be s))
oneToMany_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistArtworkT))
#artistArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (ArtistArtworkT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Optic'
     A_Lens
     NoIx
     (ArtistArtworkT
        (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
     (PrimaryKey
        ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> PrimaryKey
     ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistArtworkT
     (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
  (PrimaryKey
     ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
#artistIdentifier) ArtistT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
songs
  Map UUID ArtistArtwork -> m (Map UUID ArtistArtwork)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID ArtistArtwork -> m (Map UUID ArtistArtwork))
-> ([ArtistArtwork'] -> Map UUID ArtistArtwork)
-> [ArtistArtwork']
-> m (Map UUID ArtistArtwork)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(UUID, ArtistArtwork)] -> Map UUID ArtistArtwork
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(UUID, ArtistArtwork)] -> Map UUID ArtistArtwork)
-> ([ArtistArtwork'] -> [(UUID, ArtistArtwork)])
-> [ArtistArtwork']
-> Map UUID ArtistArtwork
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArtistArtwork' -> (UUID, ArtistArtwork))
-> [ArtistArtwork'] -> [(UUID, ArtistArtwork)]
forall a b. (a -> b) -> [a] -> [b]
map ArtistArtwork' -> (UUID, ArtistArtwork)
toArtistArtwork ([ArtistArtwork'] -> m (Map UUID ArtistArtwork))
-> [ArtistArtwork'] -> m (Map UUID ArtistArtwork)
forall a b. (a -> b) -> a -> b
$ [ArtistArtwork']
artworks

-- | Enrich artists with related information, according to enrichment parameters
enrichedArtistResponse' :: (MonadIO m) => Env -> Map UUID Artist -> EnrichArtistParams -> m (Map UUID Artist)
enrichedArtistResponse' :: forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID Artist -> EnrichArtistParams -> m (Map UUID Artist)
enrichedArtistResponse' Env
env Map UUID Artist
artistMap EnrichArtistParams
enrichArtistParams = do
  Map UUID ArtistArtwork
artworkMap <- IO (Map UUID ArtistArtwork) -> m (Map UUID ArtistArtwork)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Map UUID ArtistArtwork)
getArtwork
  Map UUID ArtistOpinion
opinionMap <- IO (Map UUID ArtistOpinion) -> m (Map UUID ArtistOpinion)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Map UUID ArtistOpinion)
getOpinion
  Map UUID ArtistComment
commentMap <- IO (Map UUID ArtistComment) -> m (Map UUID ArtistComment)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Map UUID ArtistComment)
getComment

  let enrichedArtists :: Map UUID Artist
enrichedArtists =
        (Artist -> Artist) -> Map UUID Artist -> Map UUID Artist
forall a b k. (a -> b) -> Map k a -> Map k b
mapMap
          ( \Artist
artist -> do
              let rawCommentMap :: Map UUID ArtistComment
rawCommentMap = (ArtistComment -> Bool)
-> Map UUID ArtistComment -> Map UUID ArtistComment
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Artist -> ArtistComment -> Bool
forall {k} {k} {b} {s} {a}.
(Is k A_Getter, Is k A_Getter, Eq b,
 LabelOptic "identifier" k s s b b,
 LabelOptic "artistIdentifier" k a a b b) =>
s -> a -> Bool
matchesArtistIdentifier Artist
artist) Map UUID ArtistComment
commentMap
                  allComments :: [ArtistComment]
allComments = Map UUID ArtistComment -> [ArtistComment]
forall k a. Map k a -> [a]
elems Map UUID ArtistComment
rawCommentMap
                  commentThreads :: [ThreadRender ArtistComment]
commentThreads = (Thread ArtistComment -> ThreadRender ArtistComment)
-> [Thread ArtistComment] -> [ThreadRender ArtistComment]
forall a b. (a -> b) -> [a] -> [b]
map Thread ArtistComment -> ThreadRender ArtistComment
forall a. Thread a -> ThreadRender a
renderThread ([Thread ArtistComment] -> [ThreadRender ArtistComment])
-> [Thread ArtistComment] -> [ThreadRender ArtistComment]
forall a b. (a -> b) -> a -> b
$ [ArtistComment]
-> (ArtistComment -> ArtistComment -> Bool)
-> (ArtistComment -> Maybe UUID)
-> [Thread ArtistComment]
forall a b. [a] -> (a -> a -> Bool) -> (a -> Maybe b) -> [Thread a]
mkThreads [ArtistComment]
allComments ArtistComment -> ArtistComment -> Bool
forall {k} {l} {k} {k} {l} {k} {a} {u} {v} {u} {v} {s} {s}.
(JoinKinds k l k, JoinKinds k l k, Is k A_Getter, Is k A_Getter,
 Eq a, LabelOptic "identifier" l u v a a,
 LabelOptic "parentIdentifier" l u v (Maybe a) (Maybe a),
 LabelOptic "comment" k s s u v, LabelOptic "comment" k s s u v) =>
s -> s -> Bool
isChildOf' (ArtistComment
-> Optic' A_Lens NoIx ArtistComment (Maybe UUID) -> Maybe UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx ArtistComment ArtistComment Comment Comment
#comment Optic A_Lens NoIx ArtistComment ArtistComment Comment Comment
-> Optic A_Lens NoIx Comment Comment (Maybe UUID) (Maybe UUID)
-> Optic' A_Lens NoIx ArtistComment (Maybe UUID)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic A_Lens NoIx Comment Comment (Maybe UUID) (Maybe UUID)
#parentIdentifier)

              Artist
artist
                { comments = commentThreads,
                  artworks = filterMap (matchesArtistIdentifier artist) artworkMap,
                  opinions = filterMap (matchesArtistIdentifier artist) opinionMap
                }
          )
          Map UUID Artist
artistMap

  Map UUID Artist -> m (Map UUID Artist)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID Artist
enrichedArtists
  where
    matchesArtistIdentifier :: s -> a -> Bool
matchesArtistIdentifier s
artist = (b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== s
artist s -> Optic' k NoIx s b -> b
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx s b
#identifier) (b -> Bool) -> (a -> b) -> a -> Bool
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (a -> Optic' k NoIx a b -> b
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx a b
#artistIdentifier)
    isChildOf' :: s -> s -> Bool
isChildOf' s
p s
x = a -> Maybe a
forall a. a -> Maybe a
Just (s
p s -> Optic' k NoIx s a -> a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic k NoIx s s u v
#comment Optic k NoIx s s u v -> Optic l NoIx u v a a -> Optic' k NoIx s a
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic l NoIx u v a a
#identifier) Maybe a -> Maybe a -> Bool
forall a. Eq a => a -> a -> Bool
== s
x s -> Optic' k NoIx s (Maybe a) -> Maybe a
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic k NoIx s s u v
#comment Optic k NoIx s s u v
-> Optic l NoIx u v (Maybe a) (Maybe a)
-> Optic' k NoIx s (Maybe a)
forall k l m (is :: IxList) (js :: IxList) (ks :: IxList) s t u v a
       b.
(JoinKinds k l m, AppendIndices is js ks) =>
Optic k is s t u v -> Optic l js u v a b -> Optic m ks s t a b
% Optic l NoIx u v (Maybe a) (Maybe a)
#parentIdentifier
    artistIds :: [UUID]
artistIds = Map UUID Artist -> [UUID]
forall k a. Map k a -> [k]
keys Map UUID Artist
artistMap
    getComment :: IO (Map UUID ArtistComment)
getComment =
      if EnrichArtistParams
enrichArtistParams EnrichArtistParams
-> Optic' A_Lens NoIx EnrichArtistParams Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EnrichArtistParams Bool
#includeComments
        then forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistQuery (Free ArtistQuery (Map UUID ArtistComment)
 -> IO (Map UUID ArtistComment))
-> Free ArtistQuery (Map UUID ArtistComment)
-> IO (Map UUID ArtistComment)
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free ArtistQuery (Map UUID ArtistComment)
forall (f :: * -> *).
(ArtistQuery :<: f) =>
Env -> [UUID] -> Free f (Map UUID ArtistComment)
fetchArtistComments Env
env [UUID]
artistIds
        else Map UUID ArtistComment -> IO (Map UUID ArtistComment)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID ArtistComment -> IO (Map UUID ArtistComment))
-> Map UUID ArtistComment -> IO (Map UUID ArtistComment)
forall a b. (a -> b) -> a -> b
$ [Item (Map UUID ArtistComment)] -> Map UUID ArtistComment
forall l. IsList l => [Item l] -> l
fromList []
    getArtwork :: IO (Map UUID ArtistArtwork)
getArtwork =
      if EnrichArtistParams
enrichArtistParams EnrichArtistParams
-> Optic' A_Lens NoIx EnrichArtistParams Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EnrichArtistParams Bool
#includeArtworks
        then forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistQuery (Free ArtistQuery (Map UUID ArtistArtwork)
 -> IO (Map UUID ArtistArtwork))
-> Free ArtistQuery (Map UUID ArtistArtwork)
-> IO (Map UUID ArtistArtwork)
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free ArtistQuery (Map UUID ArtistArtwork)
forall (f :: * -> *).
(ArtistQuery :<: f) =>
Env -> [UUID] -> Free f (Map UUID ArtistArtwork)
fetchArtistArtworks Env
env [UUID]
artistIds
        else Map UUID ArtistArtwork -> IO (Map UUID ArtistArtwork)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID ArtistArtwork -> IO (Map UUID ArtistArtwork))
-> Map UUID ArtistArtwork -> IO (Map UUID ArtistArtwork)
forall a b. (a -> b) -> a -> b
$ [Item (Map UUID ArtistArtwork)] -> Map UUID ArtistArtwork
forall l. IsList l => [Item l] -> l
fromList []
    getOpinion :: IO (Map UUID ArtistOpinion)
getOpinion =
      if EnrichArtistParams
enrichArtistParams EnrichArtistParams
-> Optic' A_Lens NoIx EnrichArtistParams Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EnrichArtistParams Bool
#includeOpinions
        then forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @ArtistQuery (Free ArtistQuery (Map UUID ArtistOpinion)
 -> IO (Map UUID ArtistOpinion))
-> Free ArtistQuery (Map UUID ArtistOpinion)
-> IO (Map UUID ArtistOpinion)
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free ArtistQuery (Map UUID ArtistOpinion)
forall (f :: * -> *).
(ArtistQuery :<: f) =>
Env -> [UUID] -> Free f (Map UUID ArtistOpinion)
fetchArtistOpinions Env
env [UUID]
artistIds
        else Map UUID ArtistOpinion -> IO (Map UUID ArtistOpinion)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID ArtistOpinion -> IO (Map UUID ArtistOpinion))
-> Map UUID ArtistOpinion -> IO (Map UUID ArtistOpinion)
forall a b. (a -> b) -> a -> b
$ [Item (Map UUID ArtistOpinion)] -> Map UUID ArtistOpinion
forall l. IsList l => [Item l] -> l
fromList []

-- | Fetch artist comments from storage
fetchArtistComments' :: (MonadIO m) => Env -> [UUID] -> m (Map UUID ArtistComment)
fetchArtistComments' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID ArtistComment)
fetchArtistComments' Env
env [UUID]
identifiers = do
  [ArtistComment']
comments <- IO [ArtistComment'] -> m [ArtistComment']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [ArtistComment'] -> m [ArtistComment'])
-> IO [ArtistComment'] -> m [ArtistComment']
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection -> SqliteM [ArtistComment'] -> IO [ArtistComment']
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM [ArtistComment'] -> IO [ArtistComment'])
-> SqliteM [ArtistComment'] -> IO [ArtistComment']
forall a b. (a -> b) -> a -> b
$ do
    SqlSelect Sqlite ArtistComment' -> SqliteM [ArtistComment']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList (SqlSelect Sqlite ArtistComment' -> SqliteM [ArtistComment'])
-> SqlSelect Sqlite ArtistComment' -> SqliteM [ArtistComment']
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope)))
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope))
 -> SqlSelect
      Sqlite
      (QExprToIdentity
         (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
      ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
artists <-
        (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_ (\ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
s ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
     (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#identifier) QGenExpr QValueContext Sqlite QBaseScope Text
-> [QGenExpr QValueContext Sqlite QBaseScope Text]
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite QBaseScope Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite QBaseScope Text
HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> (UUID -> Text)
-> UUID
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
          (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
-> (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope)
    -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (tbl :: (* -> *) -> *)
       (rel :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be,
 HasTableEquality be (PrimaryKey tbl), Table tbl, Table rel) =>
DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> PrimaryKey tbl (QExpr be s))
-> tbl (QExpr be s)
-> Q be db s (rel (QExpr be s))
oneToMany_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistCommentT))
#artistComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistCommentT (QGenExpr QValueContext Sqlite QBaseScope))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
#artistIdentifier) ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
artists

  Map UUID ArtistComment -> m (Map UUID ArtistComment)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID ArtistComment -> m (Map UUID ArtistComment))
-> ([ArtistComment'] -> Map UUID ArtistComment)
-> [ArtistComment']
-> m (Map UUID ArtistComment)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(UUID, ArtistComment)] -> Map UUID ArtistComment
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(UUID, ArtistComment)] -> Map UUID ArtistComment)
-> ([ArtistComment'] -> [(UUID, ArtistComment)])
-> [ArtistComment']
-> Map UUID ArtistComment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArtistComment' -> (UUID, ArtistComment))
-> [ArtistComment'] -> [(UUID, ArtistComment)]
forall a b. (a -> b) -> [a] -> [b]
map ArtistComment' -> (UUID, ArtistComment)
toArtistComment ([ArtistComment'] -> m (Map UUID ArtistComment))
-> [ArtistComment'] -> m (Map UUID ArtistComment)
forall a b. (a -> b) -> a -> b
$ [ArtistComment']
comments

searchArtists' :: (MonadIO m) => Env -> SearchInput -> ArtistSortOrder -> Limit -> Offset -> m (Map UUID Artist, [UUID])
searchArtists' :: forall (m :: * -> *).
MonadIO m =>
Env
-> SearchInput
-> ArtistSortOrder
-> Limit
-> Offset
-> m (Map UUID Artist, [UUID])
searchArtists' Env
env SearchInput
searchInput ArtistSortOrder
sortOrder (Limit Int
limit) (Offset Int
offset) = do
  [Artist']
artists <-
    IO [Artist'] -> m [Artist']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO [Artist'] -> m [Artist'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> IO [Artist'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> m [Artist']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ())
-> Connection -> SqliteM [Artist'] -> IO [Artist']
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn)
      (SqliteM [Artist'] -> IO [Artist'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> SqliteM [Artist'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> IO [Artist']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSelect Sqlite Artist' -> SqliteM [Artist']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
      (SqlSelect Sqlite Artist' -> SqliteM [Artist'])
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> SqlSelect Sqlite Artist')
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Artist']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (WithRewrittenThread
     (QNested QBaseScope)
     QBaseScope
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (WithRewrittenThread
           (QNested QBaseScope)
           QBaseScope
           (WithRewrittenThread
              (QNested (QNested QBaseScope))
              (QNested QBaseScope)
              (ArtistT
                 (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (WithRewrittenThread
     (QNested QBaseScope)
     QBaseScope
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect Sqlite Artist'
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (WithRewrittenThread
      (QNested QBaseScope)
      QBaseScope
      (WithRewrittenThread
         (QNested (QNested QBaseScope))
         (QNested QBaseScope)
         (ArtistT
            (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
 -> SqlSelect Sqlite Artist')
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (WithRewrittenThread
            (QNested QBaseScope)
            QBaseScope
            (WithRewrittenThread
               (QNested (QNested QBaseScope))
               (QNested QBaseScope)
               (ArtistT
                  (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqlSelect Sqlite Artist'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WithRewrittenThread
   (QNested QBaseScope)
   QBaseScope
   (WithRewrittenThread
      (QNested (QNested QBaseScope))
      (QNested QBaseScope)
      (ArtistT
         (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_ (\WithRewrittenThread
  (QNested QBaseScope)
  QBaseScope
  (WithRewrittenThread
     (QNested (QNested QBaseScope))
     (QNested QBaseScope)
     (ArtistT
        (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
s -> (WithRewrittenThread
  (QNested QBaseScope)
  QBaseScope
  (WithRewrittenThread
     (QNested (QNested QBaseScope))
     (QNested QBaseScope)
     (ArtistT
        (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
s WithRewrittenThread
  (QNested QBaseScope)
  QBaseScope
  (WithRewrittenThread
     (QNested (QNested QBaseScope))
     (QNested QBaseScope)
     (ArtistT
        (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Optic'
     A_Lens
     NoIx
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
     (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (WithRewrittenThread
     (QNested QBaseScope)
     QBaseScope
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#displayName) QGenExpr QValueContext Sqlite QBaseScope Text
-> QGenExpr QValueContext Sqlite QBaseScope Text
-> QExpr Sqlite QBaseScope Bool
forall be text ctxt s.
(BeamSqlBackendIsString be text, BeamSqlBackend be) =>
QGenExpr ctxt be s text
-> QGenExpr ctxt be s text -> QGenExpr ctxt be s Bool
`like_` HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text
"%" Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> SearchInput
searchInput SearchInput -> Optic' An_Iso NoIx SearchInput Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' An_Iso NoIx SearchInput Text
#value Text -> Text -> Text
forall a. Semigroup a => a -> a -> a
<> Text
"%"))
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (WithRewrittenThread
      (QNested QBaseScope)
      QBaseScope
      (WithRewrittenThread
         (QNested (QNested QBaseScope))
         (QNested QBaseScope)
         (ArtistT
            (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (WithRewrittenThread
         (QNested QBaseScope)
         QBaseScope
         (WithRewrittenThread
            (QNested (QNested QBaseScope))
            (QNested QBaseScope)
            (ArtistT
               (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (WithRewrittenThread
            (QNested QBaseScope)
            QBaseScope
            (WithRewrittenThread
               (QNested (QNested QBaseScope))
               (QNested QBaseScope)
               (ArtistT
                  (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall s a be (db :: (* -> *) -> *).
(Projectible be a, ThreadRewritable (QNested s) a) =>
Integer
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
limit_ (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
limit)
      (Q Sqlite
   WikiMusicDatabase
   (QNested QBaseScope)
   (WithRewrittenThread
      (QNested (QNested QBaseScope))
      (QNested QBaseScope)
      (ArtistT
         (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (WithRewrittenThread
         (QNested QBaseScope)
         QBaseScope
         (WithRewrittenThread
            (QNested (QNested QBaseScope))
            (QNested QBaseScope)
            (ArtistT
               (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> Q Sqlite
         WikiMusicDatabase
         (QNested QBaseScope)
         (WithRewrittenThread
            (QNested (QNested QBaseScope))
            (QNested QBaseScope)
            (ArtistT
               (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (WithRewrittenThread
        (QNested QBaseScope)
        QBaseScope
        (WithRewrittenThread
           (QNested (QNested QBaseScope))
           (QNested QBaseScope)
           (ArtistT
              (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested QBaseScope))
     (ArtistT
        (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
forall s a be (db :: (* -> *) -> *).
(Projectible be a, ThreadRewritable (QNested s) a) =>
Integer
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
offset_ (Int -> Integer
forall a b. (Integral a, Num b) => a -> b
fromIntegral Int
offset)
      (Q Sqlite
   WikiMusicDatabase
   (QNested (QNested QBaseScope))
   (ArtistT
      (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
 -> Q Sqlite
      WikiMusicDatabase
      (QNested QBaseScope)
      (WithRewrittenThread
         (QNested (QNested QBaseScope))
         (QNested QBaseScope)
         (ArtistT
            (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> (Q Sqlite
      WikiMusicDatabase
      (QNested (QNested (QNested QBaseScope)))
      (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
    -> Q Sqlite
         WikiMusicDatabase
         (QNested (QNested QBaseScope))
         (ArtistT
            (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested QBaseScope)
     (WithRewrittenThread
        (QNested (QNested QBaseScope))
        (QNested QBaseScope)
        (ArtistT
           (QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ArtistSortOrder
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested QBaseScope))
     (WithRewrittenThread
        (QNested (QNested (QNested QBaseScope)))
        (QNested (QNested QBaseScope))
        (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope))))))
forall {be} {a} {s} {k} {k} {k} {s} {a} {s} {a} {s} {a}
       {db :: (* -> *) -> *}.
(Sql92OrderingExpressionSyntax
   (Sql92SelectOrderingSyntax
      (Sql92SelectSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92TableSourceExpressionSyntax
   (Sql92FromTableSourceSyntax
      (Sql92SelectTableFromSyntax
         (Sql92SelectSelectTableSyntax
            (Sql92SelectSyntax (BeamSqlBackendSyntax be)))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92GroupingExpressionSyntax
   (Sql92SelectTableGroupingSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92ExpressionSelectSyntax
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92SelectSyntax (BeamSqlBackendSyntax be),
 Sql92ProjectionExpressionSyntax
   (Sql92SelectTableProjectionSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92InsertValuesExpressionSyntax
   (Sql92InsertValuesSyntax
      (Sql92InsertSyntax (BeamSqlBackendSyntax be)))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92FromExpressionSyntax
   (Sql92SelectTableFromSyntax
      (Sql92SelectSelectTableSyntax
         (Sql92SelectSyntax (BeamSqlBackendSyntax be))))
 ~ Sql92UpdateExpressionSyntax
     (Sql92UpdateSyntax (BeamSqlBackendSyntax be)),
 Sql92UpdateFieldNameSyntax
   (Sql92UpdateSyntax (BeamSqlBackendSyntax be))
 ~ Sql92ExpressionFieldNameSyntax
     (Sql92UpdateExpressionSyntax
        (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 ProjectibleWithPredicate
   AnyType
   be
   (WithExprContext (BeamSqlBackendExpressionSyntax' be))
   a,
 ThreadRewritable (QNested s) a, BeamSqlBackend be, Is k A_Getter,
 Is k A_Getter, Is k A_Getter,
 LabelOptic "createdAt" k a a (QExpr be s a) (QExpr be s a),
 LabelOptic "lastEditedAt" k a a (QExpr be s a) (QExpr be s a),
 LabelOptic "displayName" k a a (QExpr be s a) (QExpr be s a),
 IsSql92AggregationExpressionSyntax
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 Eq
   (Sql92UpdateExpressionSyntax
      (Sql92UpdateSyntax (BeamSqlBackendSyntax be))),
 HasSqlValueSyntax
   (Sql92ExpressionValueSyntax
      (Sql92UpdateExpressionSyntax
         (Sql92UpdateSyntax (BeamSqlBackendSyntax be))))
   SqlNull) =>
ArtistSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy ArtistSortOrder
sortOrder
      (Q Sqlite
   WikiMusicDatabase
   (QNested (QNested (QNested QBaseScope)))
   (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
 -> m [Artist'])
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> m [Artist']
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> Q Sqlite
     WikiMusicDatabase
     (QNested (QNested (QNested QBaseScope)))
     (ArtistT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
  Env -> [Artist'] -> m (Map UUID Artist, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> [Artist'] -> m (Map UUID Artist, [UUID])
filledArtists Env
env [Artist']
artists

-- | Fetch artist opinions from storage
fetchArtistOpinions' :: (MonadIO m) => Env -> [UUID] -> m (Map UUID ArtistOpinion)
fetchArtistOpinions' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID ArtistOpinion)
fetchArtistOpinions' Env
env [UUID]
identifiers = do
  [ArtistOpinion']
opinions <- IO [ArtistOpinion'] -> m [ArtistOpinion']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [ArtistOpinion'] -> m [ArtistOpinion'])
-> IO [ArtistOpinion'] -> m [ArtistOpinion']
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection -> SqliteM [ArtistOpinion'] -> IO [ArtistOpinion']
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM [ArtistOpinion'] -> IO [ArtistOpinion'])
-> SqliteM [ArtistOpinion'] -> IO [ArtistOpinion']
forall a b. (a -> b) -> a -> b
$ do
    SqlSelect Sqlite ArtistOpinion' -> SqliteM [ArtistOpinion']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList (SqlSelect Sqlite ArtistOpinion' -> SqliteM [ArtistOpinion'])
-> SqlSelect Sqlite ArtistOpinion' -> SqliteM [ArtistOpinion']
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope)))
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
 -> SqlSelect
      Sqlite
      (QExprToIdentity
         (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
      ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
artists <-
        (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_ (\ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
s ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
     (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#identifier) QGenExpr QValueContext Sqlite QBaseScope Text
-> [QGenExpr QValueContext Sqlite QBaseScope Text]
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite QBaseScope Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite QBaseScope Text
HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> (UUID -> Text)
-> UUID
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
          (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity ArtistT))
#artists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
-> (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope)
    -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (tbl :: (* -> *) -> *)
       (rel :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be,
 HasTableEquality be (PrimaryKey tbl), Table tbl, Table rel) =>
DatabaseEntity be db (TableEntity rel)
-> (rel (QExpr be s) -> PrimaryKey tbl (QExpr be s))
-> tbl (QExpr be s)
-> Q be db s (rel (QExpr be s))
oneToMany_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistOpinionT))
#artistOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
#artistIdentifier) ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
artists

  Map UUID ArtistOpinion -> m (Map UUID ArtistOpinion)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID ArtistOpinion -> m (Map UUID ArtistOpinion))
-> ([ArtistOpinion'] -> Map UUID ArtistOpinion)
-> [ArtistOpinion']
-> m (Map UUID ArtistOpinion)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(UUID, ArtistOpinion)] -> Map UUID ArtistOpinion
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(UUID, ArtistOpinion)] -> Map UUID ArtistOpinion)
-> ([ArtistOpinion'] -> [(UUID, ArtistOpinion)])
-> [ArtistOpinion']
-> Map UUID ArtistOpinion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArtistOpinion' -> (UUID, ArtistOpinion))
-> [ArtistOpinion'] -> [(UUID, ArtistOpinion)]
forall a b. (a -> b) -> [a] -> [b]
map ArtistOpinion' -> (UUID, ArtistOpinion)
toArtistOpinion ([ArtistOpinion'] -> m (Map UUID ArtistOpinion))
-> [ArtistOpinion'] -> m (Map UUID ArtistOpinion)
forall a b. (a -> b) -> a -> b
$ [ArtistOpinion']
opinions

filledArtists :: (MonadIO m) => Env -> [Artist'] -> m (Map UUID Artist, [UUID])
filledArtists :: forall (m :: * -> *).
MonadIO m =>
Env -> [Artist'] -> m (Map UUID Artist, [UUID])
filledArtists Env
env [Artist']
artists = do
  [ArtistExternalSourcesT Identity]
externalSources <- IO [ArtistExternalSourcesT Identity]
-> m [ArtistExternalSourcesT Identity]
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [ArtistExternalSourcesT Identity]
 -> m [ArtistExternalSourcesT Identity])
-> IO [ArtistExternalSourcesT Identity]
-> m [ArtistExternalSourcesT Identity]
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM [ArtistExternalSourcesT Identity]
-> IO [ArtistExternalSourcesT Identity]
forall a. (String -> IO ()) -> Connection -> SqliteM a -> IO a
runBeamSqliteDebug String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (Env
env Env -> Optic' A_Lens NoIx Env Connection -> Connection
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Env Connection
#conn) (SqliteM [ArtistExternalSourcesT Identity]
 -> IO [ArtistExternalSourcesT Identity])
-> SqliteM [ArtistExternalSourcesT Identity]
-> IO [ArtistExternalSourcesT Identity]
forall a b. (a -> b) -> a -> b
$ do
    SqlSelect Sqlite (ArtistExternalSourcesT Identity)
-> SqliteM [ArtistExternalSourcesT Identity]
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
      (SqlSelect Sqlite (ArtistExternalSourcesT Identity)
 -> SqliteM [ArtistExternalSourcesT Identity])
-> (Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
    -> SqlSelect Sqlite (ArtistExternalSourcesT Identity))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqliteM [ArtistExternalSourcesT Identity]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity
        (ArtistExternalSourcesT
           (QGenExpr QValueContext Sqlite QBaseScope)))
Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite (ArtistExternalSourcesT Identity)
forall be (db :: (* -> *) -> *) res.
(BeamSqlBackend be, HasQBuilder be, Projectible be res) =>
Q be db QBaseScope res -> SqlSelect be (QExprToIdentity res)
select
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
 -> SqlSelect Sqlite (ArtistExternalSourcesT Identity))
-> (Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (ArtistExternalSourcesT
            (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite (ArtistExternalSourcesT Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
forall r be (db :: (* -> *) -> *) s.
BeamSqlBackend be =>
(r -> QExpr be s Bool) -> Q be db s r -> Q be db s r
filter_ (\ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
s ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
#artistIdentifier) PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
-> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)]
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (Artist'
 -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> [Artist']
-> [PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey ArtistT Identity
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey ArtistT Identity
 -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope))
-> (Artist' -> PrimaryKey ArtistT Identity)
-> Artist'
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite QBaseScope)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Artist'
x -> Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Columnar Identity Text -> PrimaryKey ArtistT Identity)
-> Columnar Identity Text -> PrimaryKey ArtistT Identity
forall a b. (a -> b) -> a -> b
$ Artist'
x Artist'
-> Optic' A_Lens NoIx Artist' (Columnar Identity Text)
-> Columnar Identity Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Artist' (Columnar Identity Text)
#identifier)) [Artist']
artists)
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
 -> SqliteM [ArtistExternalSourcesT Identity])
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqliteM [ArtistExternalSourcesT Identity]
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (ArtistExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *) s.
(Database be db, BeamSqlBackend be) =>
DatabaseEntity be db (TableEntity table)
-> Q be db s (table (QExpr be s))
all_ ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (DatabaseSettings Sqlite WikiMusicDatabase)
  (DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity ArtistExternalSourcesT))
#artistExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
  let filledArtists' :: [(UUID, Artist)]
filledArtists' = (Artist' -> (UUID, Artist)) -> [Artist'] -> [(UUID, Artist)]
forall a b. (a -> b) -> [a] -> [b]
map ([ArtistExternalSourcesT Identity] -> Artist' -> (UUID, Artist)
forall {f :: * -> *} {k1} {k2} {k3} {k4} {k} {s}.
(Columnar f Text ~ Text, Is k1 A_Getter, Is k2 A_Getter,
 Is k3 A_Getter, Is k4 A_Getter, Is k A_Getter,
 LabelOptic "spotifyUrl" k3 s s (Maybe Text) (Maybe Text),
 LabelOptic "youtubeUrl" k2 s s (Maybe Text) (Maybe Text),
 LabelOptic "soundcloudUrl" k4 s s (Maybe Text) (Maybe Text),
 LabelOptic "wikipediaUrl" k1 s s (Maybe Text) (Maybe Text),
 LabelOptic
   "artistIdentifier"
   k
   s
   s
   (PrimaryKey ArtistT f)
   (PrimaryKey ArtistT f)) =>
[s] -> Artist' -> (UUID, Artist)
withExternalSources [ArtistExternalSourcesT Identity]
externalSources) [Artist']
artists
  (Map UUID Artist, [UUID]) -> m (Map UUID Artist, [UUID])
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(UUID, Artist)] -> Map UUID Artist
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(UUID, Artist)]
filledArtists', (Artist' -> UUID) -> [Artist'] -> [UUID]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> UUID
textToUUID (Text -> UUID) -> (Artist' -> Text) -> Artist' -> UUID
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Artist' -> Optic' A_Lens NoIx Artist' Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Artist' Text
#identifier)) [Artist']
artists)
  where
    withExternalSources :: [s] -> Artist' -> (UUID, Artist)
withExternalSources [s]
externalSources Artist'
artist =
      let maybeFoundExternal :: Maybe ExternalSources
maybeFoundExternal =
            (NonEmpty s -> ExternalSources)
-> Maybe (NonEmpty s) -> Maybe ExternalSources
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap
              (s -> ExternalSources
forall {k1} {k2} {k3} {k4} {s}.
(Is k1 A_Getter, Is k2 A_Getter, Is k3 A_Getter, Is k4 A_Getter,
 LabelOptic "spotifyUrl" k3 s s (Maybe Text) (Maybe Text),
 LabelOptic "youtubeUrl" k2 s s (Maybe Text) (Maybe Text),
 LabelOptic "soundcloudUrl" k4 s s (Maybe Text) (Maybe Text),
 LabelOptic "wikipediaUrl" k1 s s (Maybe Text) (Maybe Text)) =>
s -> ExternalSources
fromPersistenceExternalSource (s -> ExternalSources)
-> (NonEmpty s -> s) -> NonEmpty s -> ExternalSources
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty s -> s
forall (f :: * -> *) a. IsNonEmpty f a a "head" => f a -> a
head)
              ([s] -> Maybe (NonEmpty s)
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty ([s] -> Maybe (NonEmpty s)) -> [s] -> Maybe (NonEmpty s)
forall a b. (a -> b) -> a -> b
$ (s -> Bool) -> [s] -> [s]
forall a. (a -> Bool) -> [a] -> [a]
filter (\s
x -> PrimaryKey ArtistT f -> Columnar f Text
forall (f :: * -> *). PrimaryKey ArtistT f -> Columnar f Text
fromArtistPk (s
x s -> Optic' k NoIx s (PrimaryKey ArtistT f) -> PrimaryKey ArtistT f
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx s (PrimaryKey ArtistT f)
#artistIdentifier) Columnar f Text -> Columnar f Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Artist'
artist Artist'
-> Optic' A_Lens NoIx Artist' (Columnar f Text) -> Columnar f Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Artist' (Columnar f Text)
#identifier)) [s]
externalSources)
       in Artist' -> ExternalSources -> (UUID, Artist)
toArtist Artist'
artist (ExternalSources -> Maybe ExternalSources -> ExternalSources
forall a. a -> Maybe a -> a
fromMaybe ExternalSources
emptyExternalSources Maybe ExternalSources
maybeFoundExternal)