{-# 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.GenreQuery () 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.Database
import WikiMusic.Beam.Genre
import WikiMusic.Beam.Util
import WikiMusic.Free.GenreQuery
import WikiMusic.Model.Genre
import WikiMusic.Model.Other
import WikiMusic.Model.Thread as CommentThread
import WikiMusic.Protolude
instance Exec GenreQuery where
execAlgebra :: forall a. GenreQuery (IO a) -> IO a
execAlgebra (FetchGenres Env
env GenreSortOrder
sortOrder Limit
limit Offset
offset (Map UUID Genre, [UUID]) -> IO a
next) =
(Map UUID Genre, [UUID]) -> IO a
next ((Map UUID Genre, [UUID]) -> IO a)
-> IO (Map UUID Genre, [UUID]) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env
-> GenreSortOrder -> Limit -> Offset -> IO (Map UUID Genre, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env
-> GenreSortOrder -> Limit -> Offset -> m (Map UUID Genre, [UUID])
fetchGenres' Env
env GenreSortOrder
sortOrder Limit
limit Offset
offset
execAlgebra (FetchGenresByUUID Env
env GenreSortOrder
sortOrder [UUID]
identifiers (Map UUID Genre, [UUID]) -> IO a
next) =
(Map UUID Genre, [UUID]) -> IO a
next ((Map UUID Genre, [UUID]) -> IO a)
-> IO (Map UUID Genre, [UUID]) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> GenreSortOrder -> [UUID] -> IO (Map UUID Genre, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> GenreSortOrder -> [UUID] -> m (Map UUID Genre, [UUID])
fetchGenresByUUID' Env
env GenreSortOrder
sortOrder [UUID]
identifiers
execAlgebra (EnrichedGenreResponse Env
env Map UUID Genre
genreMap EnrichGenreParams
enrichGenreParams Map UUID Genre -> IO a
next) =
Map UUID Genre -> IO a
next (Map UUID Genre -> IO a) -> IO (Map UUID Genre) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> Map UUID Genre -> EnrichGenreParams -> IO (Map UUID Genre)
forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID Genre -> EnrichGenreParams -> m (Map UUID Genre)
enrichedGenreResponse' Env
env Map UUID Genre
genreMap EnrichGenreParams
enrichGenreParams
execAlgebra (FetchGenreComments Env
env [UUID]
identifiers Map UUID GenreComment -> IO a
next) =
Map UUID GenreComment -> IO a
next (Map UUID GenreComment -> IO a)
-> IO (Map UUID GenreComment) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Map UUID GenreComment)
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID GenreComment)
fetchGenreComments' Env
env [UUID]
identifiers
execAlgebra (FetchGenreOpinions Env
env [UUID]
identifiers Map UUID GenreOpinion -> IO a
next) =
Map UUID GenreOpinion -> IO a
next (Map UUID GenreOpinion -> IO a)
-> IO (Map UUID GenreOpinion) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Map UUID GenreOpinion)
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID GenreOpinion)
fetchGenreOpinions' Env
env [UUID]
identifiers
execAlgebra (SearchGenres Env
env SearchInput
searchInput GenreSortOrder
sortOrder Limit
limit Offset
offset (Map UUID Genre, [UUID]) -> IO a
next) =
(Map UUID Genre, [UUID]) -> IO a
next ((Map UUID Genre, [UUID]) -> IO a)
-> IO (Map UUID Genre, [UUID]) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env
-> SearchInput
-> GenreSortOrder
-> Limit
-> Offset
-> IO (Map UUID Genre, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env
-> SearchInput
-> GenreSortOrder
-> Limit
-> Offset
-> m (Map UUID Genre, [UUID])
searchGenres' Env
env SearchInput
searchInput GenreSortOrder
sortOrder Limit
limit Offset
offset
execAlgebra (FetchGenreArtworks Env
env [UUID]
identifiers Map UUID GenreArtwork -> IO a
next) =
Map UUID GenreArtwork -> IO a
next (Map UUID GenreArtwork -> IO a)
-> IO (Map UUID GenreArtwork) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Map UUID GenreArtwork)
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID GenreArtwork)
fetchGenreArtworks' Env
env [UUID]
identifiers
mkOrderBy :: GenreSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy GenreSortOrder
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 GenreSortOrder
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 GenreSortOrder
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 GenreSortOrder
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 GenreSortOrder
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 GenreSortOrder
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))
fetchGenres' :: (MonadIO m) => Env -> GenreSortOrder -> Limit -> Offset -> m (Map UUID Genre, [UUID])
fetchGenres' :: forall (m :: * -> *).
MonadIO m =>
Env
-> GenreSortOrder -> Limit -> Offset -> m (Map UUID Genre, [UUID])
fetchGenres' Env
env GenreSortOrder
sortOrder (Limit Int
limit) (Offset Int
offset) = do
[Genre']
genres <- IO [Genre'] -> m [Genre']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [Genre'] -> m [Genre']) -> IO [Genre'] -> m [Genre']
forall a b. (a -> b) -> a -> b
$ (String -> IO ()) -> Connection -> SqliteM [Genre'] -> IO [Genre']
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 [Genre'] -> IO [Genre'])
-> SqliteM [Genre'] -> IO [Genre']
forall a b. (a -> b) -> a -> b
$ do
SqlSelect Sqlite Genre' -> SqliteM [Genre']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
(SqlSelect Sqlite Genre' -> SqliteM [Genre'])
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqlSelect Sqlite Genre')
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Genre']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect
Sqlite
(QExprToIdentity
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect Sqlite Genre'
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)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect Sqlite Genre')
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqlSelect Sqlite Genre'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(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)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested QBaseScope))
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(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))
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested QBaseScope))
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenreSortOrder
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested QBaseScope))
(WithRewrittenThread
(QNested (QNested (QNested QBaseScope)))
(QNested (QNested QBaseScope))
(GenreT (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) =>
GenreSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy GenreSortOrder
sortOrder
(Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Genre'])
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Genre']
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (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 GenreT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
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 GenreT))
#genres) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
Env -> [Genre'] -> m (Map UUID Genre, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> [Genre'] -> m (Map UUID Genre, [UUID])
filledGenres Env
env [Genre']
genres
fetchGenresByUUID' :: (MonadIO m) => Env -> GenreSortOrder -> [UUID] -> m (Map UUID Genre, [UUID])
fetchGenresByUUID' :: forall (m :: * -> *).
MonadIO m =>
Env -> GenreSortOrder -> [UUID] -> m (Map UUID Genre, [UUID])
fetchGenresByUUID' Env
env GenreSortOrder
sortOrder [UUID]
identifiers = do
[Genre']
genres <-
IO [Genre'] -> m [Genre']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
(IO [Genre'] -> m [Genre'])
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> IO [Genre'])
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [Genre']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM [Genre'] -> IO [Genre']
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 [Genre'] -> IO [Genre'])
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqliteM [Genre'])
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> IO [Genre']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSelect Sqlite Genre' -> SqliteM [Genre']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
(SqlSelect Sqlite Genre' -> SqliteM [Genre'])
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqlSelect Sqlite Genre')
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqliteM [Genre']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)))
Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite Genre'
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
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite Genre')
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqlSelect Sqlite Genre'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (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_ (\GenreT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (GenreT (QGenExpr QValueContext Sqlite QBaseScope)
s GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
A_Lens
NoIx
(GenreT (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
(GenreT (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
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)))
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenreSortOrder
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(GenreT (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) =>
GenreSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy GenreSortOrder
sortOrder
(Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [Genre'])
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [Genre']
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (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 GenreT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
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 GenreT))
#genres) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
Env -> [Genre'] -> m (Map UUID Genre, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> [Genre'] -> m (Map UUID Genre, [UUID])
filledGenres Env
env [Genre']
genres
fetchGenreArtworks' :: (MonadIO m) => Env -> [UUID] -> m (Map UUID GenreArtwork)
fetchGenreArtworks' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID GenreArtwork)
fetchGenreArtworks' Env
env [UUID]
identifiers = do
[GenreArtwork']
artworks <- IO [GenreArtwork'] -> m [GenreArtwork']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
(IO [GenreArtwork'] -> m [GenreArtwork'])
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> IO [GenreArtwork'])
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [GenreArtwork']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ())
-> Connection -> SqliteM [GenreArtwork'] -> IO [GenreArtwork']
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 [GenreArtwork'] -> IO [GenreArtwork'])
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqliteM [GenreArtwork'])
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> IO [GenreArtwork']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSelect Sqlite GenreArtwork' -> SqliteM [GenreArtwork']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
(SqlSelect Sqlite GenreArtwork' -> SqliteM [GenreArtwork'])
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqlSelect Sqlite GenreArtwork')
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqliteM [GenreArtwork']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreArtworkT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreArtworkT (QGenExpr QValueContext Sqlite QBaseScope)))
Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreArtworkT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite GenreArtwork'
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
(GenreArtworkT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite GenreArtwork')
-> (Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreArtworkT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> SqlSelect Sqlite GenreArtwork'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenreArtworkT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> QOrd Sqlite (QNested QBaseScope) Int64)
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(GenreArtworkT
(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)
-> (GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> QExpr Sqlite (QNested QBaseScope) Int64)
-> GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> QOrd Sqlite (QNested QBaseScope) Int64
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenreArtworkT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Optic'
A_Lens
NoIx
(GenreArtworkT
(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
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
(QExpr Sqlite (QNested QBaseScope) Int64)
#orderValue))
(Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [GenreArtwork'])
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> m [GenreArtwork']
forall a b. (a -> b) -> a -> b
$ do
GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
songs <-
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> QExpr Sqlite (QNested QBaseScope) Bool)
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (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_ (\GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
s -> (GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
s GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Optic'
A_Lens
NoIx
(GenreT (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
(GenreT (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)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreT (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 GenreT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
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 GenreT))
#genres) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreArtworkT)
-> (GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> PrimaryKey
GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(GenreArtworkT
(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 GenreArtworkT))
-> DatabaseEntity
Sqlite WikiMusicDatabase (TableEntity GenreArtworkT)
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 GenreArtworkT))
#genreArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (GenreArtworkT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
-> Optic'
A_Lens
NoIx
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
(PrimaryKey
GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
-> PrimaryKey
GenreT (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
(GenreArtworkT
(QGenExpr QValueContext Sqlite (QNested QBaseScope)))
(PrimaryKey
GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope)))
#genreIdentifier) GenreT (QGenExpr QValueContext Sqlite (QNested QBaseScope))
songs
Map UUID GenreArtwork -> m (Map UUID GenreArtwork)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID GenreArtwork -> m (Map UUID GenreArtwork))
-> ([GenreArtwork'] -> Map UUID GenreArtwork)
-> [GenreArtwork']
-> m (Map UUID GenreArtwork)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(UUID, GenreArtwork)] -> Map UUID GenreArtwork
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(UUID, GenreArtwork)] -> Map UUID GenreArtwork)
-> ([GenreArtwork'] -> [(UUID, GenreArtwork)])
-> [GenreArtwork']
-> Map UUID GenreArtwork
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenreArtwork' -> (UUID, GenreArtwork))
-> [GenreArtwork'] -> [(UUID, GenreArtwork)]
forall a b. (a -> b) -> [a] -> [b]
map GenreArtwork' -> (UUID, GenreArtwork)
toGenreArtwork ([GenreArtwork'] -> m (Map UUID GenreArtwork))
-> [GenreArtwork'] -> m (Map UUID GenreArtwork)
forall a b. (a -> b) -> a -> b
$ [GenreArtwork']
artworks
enrichedGenreResponse' :: (MonadIO m) => Env -> Map UUID Genre -> EnrichGenreParams -> m (Map UUID Genre)
enrichedGenreResponse' :: forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID Genre -> EnrichGenreParams -> m (Map UUID Genre)
enrichedGenreResponse' Env
env Map UUID Genre
genreMap EnrichGenreParams
enrichGenreParams = do
Map UUID GenreArtwork
artworkMap <- IO (Map UUID GenreArtwork) -> m (Map UUID GenreArtwork)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Map UUID GenreArtwork)
getArtwork
Map UUID GenreOpinion
opinionMap <- IO (Map UUID GenreOpinion) -> m (Map UUID GenreOpinion)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Map UUID GenreOpinion)
getOpinion
Map UUID GenreComment
commentMap <- IO (Map UUID GenreComment) -> m (Map UUID GenreComment)
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO (Map UUID GenreComment)
getComment
let enrichedGenres :: Map UUID Genre
enrichedGenres =
(Genre -> Genre) -> Map UUID Genre -> Map UUID Genre
forall a b k. (a -> b) -> Map k a -> Map k b
mapMap
( \Genre
genre -> do
let rawCommentMap :: Map UUID GenreComment
rawCommentMap = (GenreComment -> Bool)
-> Map UUID GenreComment -> Map UUID GenreComment
forall a k. (a -> Bool) -> Map k a -> Map k a
Map.filter (Genre -> GenreComment -> 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 "genreIdentifier" k a a b b) =>
s -> a -> Bool
matchesGenreIdentifier Genre
genre) Map UUID GenreComment
commentMap
allComments :: [GenreComment]
allComments = Map UUID GenreComment -> [GenreComment]
forall k a. Map k a -> [a]
elems Map UUID GenreComment
rawCommentMap
commentThreads :: [ThreadRender GenreComment]
commentThreads = (Thread GenreComment -> ThreadRender GenreComment)
-> [Thread GenreComment] -> [ThreadRender GenreComment]
forall a b. (a -> b) -> [a] -> [b]
map Thread GenreComment -> ThreadRender GenreComment
forall a. Thread a -> ThreadRender a
renderThread ([Thread GenreComment] -> [ThreadRender GenreComment])
-> [Thread GenreComment] -> [ThreadRender GenreComment]
forall a b. (a -> b) -> a -> b
$ [GenreComment]
-> (GenreComment -> GenreComment -> Bool)
-> (GenreComment -> Maybe UUID)
-> [Thread GenreComment]
forall a b. [a] -> (a -> a -> Bool) -> (a -> Maybe b) -> [Thread a]
mkThreads [GenreComment]
allComments GenreComment -> GenreComment -> 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' (GenreComment
-> Optic' A_Lens NoIx GenreComment (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 GenreComment GenreComment Comment Comment
#comment Optic A_Lens NoIx GenreComment GenreComment Comment Comment
-> Optic A_Lens NoIx Comment Comment (Maybe UUID) (Maybe UUID)
-> Optic' A_Lens NoIx GenreComment (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)
Genre
genre
{ comments = commentThreads,
artworks = filterMap (matchesGenreIdentifier genre) artworkMap,
opinions = filterMap (matchesGenreIdentifier genre) opinionMap
}
)
Map UUID Genre
genreMap
Map UUID Genre -> m (Map UUID Genre)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID Genre
enrichedGenres
where
matchesGenreIdentifier :: s -> a -> Bool
matchesGenreIdentifier s
genre = (b -> b -> Bool
forall a. Eq a => a -> a -> Bool
== s
genre 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
#genreIdentifier)
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
genreIds :: [UUID]
genreIds = Map UUID Genre -> [UUID]
forall k a. Map k a -> [k]
keys Map UUID Genre
genreMap
getComment :: IO (Map UUID GenreComment)
getComment =
if EnrichGenreParams
enrichGenreParams EnrichGenreParams
-> Optic' A_Lens NoIx EnrichGenreParams Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EnrichGenreParams Bool
#includeComments
then forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @GenreQuery (Free GenreQuery (Map UUID GenreComment)
-> IO (Map UUID GenreComment))
-> Free GenreQuery (Map UUID GenreComment)
-> IO (Map UUID GenreComment)
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free GenreQuery (Map UUID GenreComment)
forall (f :: * -> *).
(GenreQuery :<: f) =>
Env -> [UUID] -> Free f (Map UUID GenreComment)
fetchGenreComments Env
env [UUID]
genreIds
else Map UUID GenreComment -> IO (Map UUID GenreComment)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID GenreComment -> IO (Map UUID GenreComment))
-> Map UUID GenreComment -> IO (Map UUID GenreComment)
forall a b. (a -> b) -> a -> b
$ [Item (Map UUID GenreComment)] -> Map UUID GenreComment
forall l. IsList l => [Item l] -> l
fromList []
getArtwork :: IO (Map UUID GenreArtwork)
getArtwork =
if EnrichGenreParams
enrichGenreParams EnrichGenreParams
-> Optic' A_Lens NoIx EnrichGenreParams Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EnrichGenreParams Bool
#includeArtworks
then forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @GenreQuery (Free GenreQuery (Map UUID GenreArtwork)
-> IO (Map UUID GenreArtwork))
-> Free GenreQuery (Map UUID GenreArtwork)
-> IO (Map UUID GenreArtwork)
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free GenreQuery (Map UUID GenreArtwork)
forall (f :: * -> *).
(GenreQuery :<: f) =>
Env -> [UUID] -> Free f (Map UUID GenreArtwork)
fetchGenreArtworks Env
env [UUID]
genreIds
else Map UUID GenreArtwork -> IO (Map UUID GenreArtwork)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID GenreArtwork -> IO (Map UUID GenreArtwork))
-> Map UUID GenreArtwork -> IO (Map UUID GenreArtwork)
forall a b. (a -> b) -> a -> b
$ [Item (Map UUID GenreArtwork)] -> Map UUID GenreArtwork
forall l. IsList l => [Item l] -> l
fromList []
getOpinion :: IO (Map UUID GenreOpinion)
getOpinion =
if EnrichGenreParams
enrichGenreParams EnrichGenreParams
-> Optic' A_Lens NoIx EnrichGenreParams Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx EnrichGenreParams Bool
#includeOpinions
then forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @GenreQuery (Free GenreQuery (Map UUID GenreOpinion)
-> IO (Map UUID GenreOpinion))
-> Free GenreQuery (Map UUID GenreOpinion)
-> IO (Map UUID GenreOpinion)
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free GenreQuery (Map UUID GenreOpinion)
forall (f :: * -> *).
(GenreQuery :<: f) =>
Env -> [UUID] -> Free f (Map UUID GenreOpinion)
fetchGenreOpinions Env
env [UUID]
genreIds
else Map UUID GenreOpinion -> IO (Map UUID GenreOpinion)
forall a. a -> IO a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID GenreOpinion -> IO (Map UUID GenreOpinion))
-> Map UUID GenreOpinion -> IO (Map UUID GenreOpinion)
forall a b. (a -> b) -> a -> b
$ [Item (Map UUID GenreOpinion)] -> Map UUID GenreOpinion
forall l. IsList l => [Item l] -> l
fromList []
fetchGenreComments' :: (MonadIO m) => Env -> [UUID] -> m (Map UUID GenreComment)
Env
env [UUID]
identifiers = do
[GenreComment']
comments <- IO [GenreComment'] -> m [GenreComment']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [GenreComment'] -> m [GenreComment'])
-> IO [GenreComment'] -> m [GenreComment']
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection -> SqliteM [GenreComment'] -> IO [GenreComment']
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 [GenreComment'] -> IO [GenreComment'])
-> SqliteM [GenreComment'] -> IO [GenreComment']
forall a b. (a -> b) -> a -> b
$ do
SqlSelect Sqlite GenreComment' -> SqliteM [GenreComment']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList (SqlSelect Sqlite GenreComment' -> SqliteM [GenreComment'])
-> SqlSelect Sqlite GenreComment' -> SqliteM [GenreComment']
forall a b. (a -> b) -> a -> b
$ Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreCommentT (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
(GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
GenreT (QGenExpr QValueContext Sqlite QBaseScope)
genres <-
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (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_ (\GenreT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (GenreT (QGenExpr QValueContext Sqlite QBaseScope)
s GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
A_Lens
NoIx
(GenreT (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
(GenreT (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
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (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 GenreT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
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 GenreT))
#genres) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreCommentT)
-> (GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope)
-> PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreCommentT (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 GenreCommentT))
-> DatabaseEntity
Sqlite WikiMusicDatabase (TableEntity GenreCommentT)
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 GenreCommentT))
#genreComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
A_Lens
NoIx
(GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope))
(PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey GenreT (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
(GenreCommentT (QGenExpr QValueContext Sqlite QBaseScope))
(PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
#genreIdentifier) GenreT (QGenExpr QValueContext Sqlite QBaseScope)
genres
Map UUID GenreComment -> m (Map UUID GenreComment)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID GenreComment -> m (Map UUID GenreComment))
-> ([GenreComment'] -> Map UUID GenreComment)
-> [GenreComment']
-> m (Map UUID GenreComment)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(UUID, GenreComment)] -> Map UUID GenreComment
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(UUID, GenreComment)] -> Map UUID GenreComment)
-> ([GenreComment'] -> [(UUID, GenreComment)])
-> [GenreComment']
-> Map UUID GenreComment
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenreComment' -> (UUID, GenreComment))
-> [GenreComment'] -> [(UUID, GenreComment)]
forall a b. (a -> b) -> [a] -> [b]
map GenreComment' -> (UUID, GenreComment)
toGenreComment ([GenreComment'] -> m (Map UUID GenreComment))
-> [GenreComment'] -> m (Map UUID GenreComment)
forall a b. (a -> b) -> a -> b
$ [GenreComment']
comments
searchGenres' :: (MonadIO m) => Env -> SearchInput -> GenreSortOrder -> Limit -> Offset -> m (Map UUID Genre, [UUID])
searchGenres' :: forall (m :: * -> *).
MonadIO m =>
Env
-> SearchInput
-> GenreSortOrder
-> Limit
-> Offset
-> m (Map UUID Genre, [UUID])
searchGenres' Env
env SearchInput
searchInput GenreSortOrder
sortOrder (Limit Int
limit) (Offset Int
offset) = do
[Genre']
genres <-
IO [Genre'] -> m [Genre']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
(IO [Genre'] -> m [Genre'])
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> IO [Genre'])
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> m [Genre']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM [Genre'] -> IO [Genre']
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 [Genre'] -> IO [Genre'])
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Genre'])
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> IO [Genre']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSelect Sqlite Genre' -> SqliteM [Genre']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
(SqlSelect Sqlite Genre' -> SqliteM [Genre'])
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqlSelect Sqlite Genre')
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqliteM [Genre']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect
Sqlite
(QExprToIdentity
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect Sqlite Genre'
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)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> SqlSelect Sqlite Genre')
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> SqlSelect Sqlite Genre'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(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)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
s -> (WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
s WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Optic'
A_Lens
NoIx
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(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)
(GenreT
(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)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(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)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(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)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))))
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(WithRewrittenThread
(QNested QBaseScope)
QBaseScope
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Integer
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested QBaseScope))
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(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))
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope))))))
-> (Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested QBaseScope))
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested QBaseScope)
(WithRewrittenThread
(QNested (QNested QBaseScope))
(QNested QBaseScope)
(GenreT
(QGenExpr QValueContext Sqlite (QNested (QNested QBaseScope)))))
forall b c a. (b -> c) -> (a -> b) -> a -> c
. GenreSortOrder
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested QBaseScope))
(WithRewrittenThread
(QNested (QNested (QNested QBaseScope)))
(QNested (QNested QBaseScope))
(GenreT (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) =>
GenreSortOrder
-> Q be db (QNested s) a
-> Q be db s (WithRewrittenThread (QNested s) s a)
mkOrderBy GenreSortOrder
sortOrder
(Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> m [Genre'])
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (QExpr Sqlite (QNested (QNested (QNested QBaseScope)))))
-> m [Genre']
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
-> Q Sqlite
WikiMusicDatabase
(QNested (QNested (QNested QBaseScope)))
(GenreT (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 GenreT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
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 GenreT))
#genres) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
Env -> [Genre'] -> m (Map UUID Genre, [UUID])
forall (m :: * -> *).
MonadIO m =>
Env -> [Genre'] -> m (Map UUID Genre, [UUID])
filledGenres Env
env [Genre']
genres
fetchGenreOpinions' :: (MonadIO m) => Env -> [UUID] -> m (Map UUID GenreOpinion)
fetchGenreOpinions' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Map UUID GenreOpinion)
fetchGenreOpinions' Env
env [UUID]
identifiers = do
[GenreOpinion']
opinions <- IO [GenreOpinion'] -> m [GenreOpinion']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [GenreOpinion'] -> m [GenreOpinion'])
-> IO [GenreOpinion'] -> m [GenreOpinion']
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection -> SqliteM [GenreOpinion'] -> IO [GenreOpinion']
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 [GenreOpinion'] -> IO [GenreOpinion'])
-> SqliteM [GenreOpinion'] -> IO [GenreOpinion']
forall a b. (a -> b) -> a -> b
$ do
SqlSelect Sqlite GenreOpinion' -> SqliteM [GenreOpinion']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList (SqlSelect Sqlite GenreOpinion' -> SqliteM [GenreOpinion'])
-> SqlSelect Sqlite GenreOpinion' -> SqliteM [GenreOpinion']
forall a b. (a -> b) -> a -> b
$ Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreOpinionT (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
(GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope))))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
GenreT (QGenExpr QValueContext Sqlite QBaseScope)
genres <-
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (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_ (\GenreT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (GenreT (QGenExpr QValueContext Sqlite QBaseScope)
s GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
A_Lens
NoIx
(GenreT (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
(GenreT (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
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (QGenExpr QValueContext Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreT (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 GenreT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreT)
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 GenreT))
#genres) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
DatabaseEntity Sqlite WikiMusicDatabase (TableEntity GenreOpinionT)
-> (GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope)
-> PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreOpinionT (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 GenreOpinionT))
-> DatabaseEntity
Sqlite WikiMusicDatabase (TableEntity GenreOpinionT)
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 GenreOpinionT))
#genreOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
A_Lens
NoIx
(GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
(PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey GenreT (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
(GenreOpinionT (QGenExpr QValueContext Sqlite QBaseScope))
(PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
#genreIdentifier) GenreT (QGenExpr QValueContext Sqlite QBaseScope)
genres
Map UUID GenreOpinion -> m (Map UUID GenreOpinion)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Map UUID GenreOpinion -> m (Map UUID GenreOpinion))
-> ([GenreOpinion'] -> Map UUID GenreOpinion)
-> [GenreOpinion']
-> m (Map UUID GenreOpinion)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [(UUID, GenreOpinion)] -> Map UUID GenreOpinion
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList ([(UUID, GenreOpinion)] -> Map UUID GenreOpinion)
-> ([GenreOpinion'] -> [(UUID, GenreOpinion)])
-> [GenreOpinion']
-> Map UUID GenreOpinion
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenreOpinion' -> (UUID, GenreOpinion))
-> [GenreOpinion'] -> [(UUID, GenreOpinion)]
forall a b. (a -> b) -> [a] -> [b]
map GenreOpinion' -> (UUID, GenreOpinion)
toGenreOpinion ([GenreOpinion'] -> m (Map UUID GenreOpinion))
-> [GenreOpinion'] -> m (Map UUID GenreOpinion)
forall a b. (a -> b) -> a -> b
$ [GenreOpinion']
opinions
filledGenres :: (MonadIO m) => Env -> [Genre'] -> m (Map UUID Genre, [UUID])
filledGenres :: forall (m :: * -> *).
MonadIO m =>
Env -> [Genre'] -> m (Map UUID Genre, [UUID])
filledGenres Env
env [Genre']
genres = do
[GenreExternalSourcesT Identity]
externalSources <- IO [GenreExternalSourcesT Identity]
-> m [GenreExternalSourcesT Identity]
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO [GenreExternalSourcesT Identity]
-> m [GenreExternalSourcesT Identity])
-> IO [GenreExternalSourcesT Identity]
-> m [GenreExternalSourcesT Identity]
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM [GenreExternalSourcesT Identity]
-> IO [GenreExternalSourcesT 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 [GenreExternalSourcesT Identity]
-> IO [GenreExternalSourcesT Identity])
-> SqliteM [GenreExternalSourcesT Identity]
-> IO [GenreExternalSourcesT Identity]
forall a b. (a -> b) -> a -> b
$ do
SqlSelect Sqlite (GenreExternalSourcesT Identity)
-> SqliteM [GenreExternalSourcesT Identity]
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
(SqlSelect Sqlite (GenreExternalSourcesT Identity)
-> SqliteM [GenreExternalSourcesT Identity])
-> (Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite (GenreExternalSourcesT Identity))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqliteM [GenreExternalSourcesT Identity]
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect
Sqlite
(QExprToIdentity
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)))
Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite (GenreExternalSourcesT 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
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite (GenreExternalSourcesT Identity))
-> (Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqlSelect Sqlite (GenreExternalSourcesT Identity)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (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_ (\GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
s -> (GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
s GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope)
-> Optic'
A_Lens
NoIx
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
(PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey GenreT (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
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
(PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
#genreIdentifier) PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope)
-> [PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope)]
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (Genre'
-> PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> [Genre']
-> [PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey GenreT Identity
-> PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope)
HaskellLiteralForQExpr
(PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey GenreT Identity
-> PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope))
-> (Genre' -> PrimaryKey GenreT Identity)
-> Genre'
-> PrimaryKey GenreT (QGenExpr QValueContext Sqlite QBaseScope)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\Genre'
x -> Columnar Identity Text -> PrimaryKey GenreT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey GenreT f
GenreId (Columnar Identity Text -> PrimaryKey GenreT Identity)
-> Columnar Identity Text -> PrimaryKey GenreT Identity
forall a b. (a -> b) -> a -> b
$ Genre'
x Genre'
-> Optic' A_Lens NoIx Genre' (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 Genre' (Columnar Identity Text)
#identifier)) [Genre']
genres)
(Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqliteM [GenreExternalSourcesT Identity])
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (QGenExpr QValueContext Sqlite QBaseScope))
-> SqliteM [GenreExternalSourcesT Identity]
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
Sqlite WikiMusicDatabase (TableEntity GenreExternalSourcesT)
-> Q Sqlite
WikiMusicDatabase
QBaseScope
(GenreExternalSourcesT (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 GenreExternalSourcesT))
-> DatabaseEntity
Sqlite WikiMusicDatabase (TableEntity GenreExternalSourcesT)
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 GenreExternalSourcesT))
#genreExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
let filledGenres' :: [(UUID, Genre)]
filledGenres' = (Genre' -> (UUID, Genre)) -> [Genre'] -> [(UUID, Genre)]
forall a b. (a -> b) -> [a] -> [b]
map ([GenreExternalSourcesT Identity] -> Genre' -> (UUID, Genre)
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
"genreIdentifier"
k
s
s
(PrimaryKey GenreT f)
(PrimaryKey GenreT f)) =>
[s] -> Genre' -> (UUID, Genre)
withExternalSources [GenreExternalSourcesT Identity]
externalSources) [Genre']
genres
(Map UUID Genre, [UUID]) -> m (Map UUID Genre, [UUID])
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ([(UUID, Genre)] -> Map UUID Genre
forall k a. Ord k => [(k, a)] -> Map k a
Map.fromList [(UUID, Genre)]
filledGenres', (Genre' -> UUID) -> [Genre'] -> [UUID]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> UUID
textToUUID (Text -> UUID) -> (Genre' -> Text) -> Genre' -> UUID
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (Genre' -> Optic' A_Lens NoIx Genre' Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Genre' Text
#identifier)) [Genre']
genres)
where
withExternalSources :: [s] -> Genre' -> (UUID, Genre)
withExternalSources [s]
externalSources Genre'
genre =
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 GenreT f -> Columnar f Text
forall (f :: * -> *). PrimaryKey GenreT f -> Columnar f Text
fromGenrePk (s
x s -> Optic' k NoIx s (PrimaryKey GenreT f) -> PrimaryKey GenreT f
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' k NoIx s (PrimaryKey GenreT f)
#genreIdentifier) Columnar f Text -> Columnar f Text -> Bool
forall a. Eq a => a -> a -> Bool
== (Genre'
genre Genre'
-> Optic' A_Lens NoIx Genre' (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 Genre' (Columnar f Text)
#identifier)) [s]
externalSources)
in Genre' -> ExternalSources -> (UUID, Genre)
toGenre Genre'
genre (ExternalSources -> Maybe ExternalSources -> ExternalSources
forall a. a -> Maybe a -> a
fromMaybe ExternalSources
emptyExternalSources Maybe ExternalSources
maybeFoundExternal)