{-# LANGUAGE OverloadedLabels #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE NoFieldSelectors #-}
{-# OPTIONS_GHC -fno-warn-ambiguous-fields #-}
{-# OPTIONS_GHC -fno-warn-orphans #-}

module WikiMusic.Sqlite.SongCommand () where

import Data.Map qualified as Map
import Data.UUID qualified as UUID
import Database.Beam
import Database.Beam.Sqlite
import Relude
import WikiMusic.Beam.Artist
import WikiMusic.Beam.Database
import WikiMusic.Beam.Relations
import WikiMusic.Beam.Song
import WikiMusic.Free.SongCommand
import WikiMusic.Interaction.Model.Song
import WikiMusic.Model.Artwork
import WikiMusic.Model.Comment
import WikiMusic.Model.Opinion
import WikiMusic.Model.Song
import WikiMusic.Protolude

insertArtistsOfSongs' :: (MonadIO m) => Env -> [ArtistOfSong] -> m (Map UUID ArtistOfSong)
insertArtistsOfSongs' :: forall (m :: * -> *).
MonadIO m =>
Env -> [ArtistOfSong] -> m (Map UUID ArtistOfSong)
insertArtistsOfSongs' Env
env [ArtistOfSong]
items = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongArtistT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite SongArtistT -> SqliteM ())
-> (SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongArtistT)
-> SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtistT)
-> SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongArtistT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtistT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtistT)
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 SongArtistT))
#songArtists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any)) -> m ())
-> SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any)) -> m ()
forall a b. (a -> b) -> a -> b
$ [SongArtistT Identity]
-> SqlInsertValues Sqlite (SongArtistT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((ArtistOfSong -> SongArtistT Identity)
-> [ArtistOfSong] -> [SongArtistT Identity]
forall a b. (a -> b) -> [a] -> [b]
map ArtistOfSong -> SongArtistT Identity
mkSongArtistP [ArtistOfSong]
items)
  Map UUID ArtistOfSong -> m (Map UUID ArtistOfSong)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID ArtistOfSong
forall k a. Map k a
Map.empty

insertSongs' :: (MonadIO m) => Env -> [Song] -> m (Map UUID Song)
insertSongs' :: forall (m :: * -> *).
MonadIO m =>
Env -> [Song] -> m (Map UUID Song)
insertSongs' Env
env [Song]
songs = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (SongT (QExpr Sqlite Any)) -> IO ())
-> SqlInsertValues Sqlite (SongT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues Sqlite (SongT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite SongT -> SqliteM ())
-> (SqlInsertValues Sqlite (SongT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongT)
-> SqlInsertValues Sqlite (SongT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
-> SqlInsertValues Sqlite (SongT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
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 SongT))
#songs) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (SongT (QExpr Sqlite Any)) -> m ())
-> SqlInsertValues Sqlite (SongT (QExpr Sqlite Any)) -> m ()
forall a b. (a -> b) -> a -> b
$ [SongT Identity]
-> SqlInsertValues Sqlite (SongT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((Song -> SongT Identity) -> [Song] -> [SongT Identity]
forall a b. (a -> b) -> [a] -> [b]
map Song -> SongT Identity
toPersistenceSong [Song]
songs)

  [SongExternalSourcesT Identity]
externalContents <-
    (Song -> m (SongExternalSourcesT Identity))
-> [Song] -> m [SongExternalSourcesT Identity]
forall (t :: * -> *) (m :: * -> *) a b.
(Traversable t, Monad m) =>
(a -> m b) -> t a -> m (t b)
forall (m :: * -> *) a b. Monad m => (a -> m b) -> [a] -> m [b]
mapM
      ( \Song
s -> do
          UUID
newIdentifier <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
          SongExternalSourcesT Identity -> m (SongExternalSourcesT Identity)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (SongExternalSourcesT Identity
 -> m (SongExternalSourcesT Identity))
-> SongExternalSourcesT Identity
-> m (SongExternalSourcesT Identity)
forall a b. (a -> b) -> a -> b
$ Song -> UUID -> SongExternalSourcesT Identity
toPersistenceSongExternalContents Song
s UUID
newIdentifier
      )
      [Song]
songs
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues
      Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues
      Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite SongExternalSourcesT -> SqliteM ())
-> (SqlInsertValues
      Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongExternalSourcesT)
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongExternalSourcesT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
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 SongExternalSourcesT))
#songExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
 -> m ())
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [SongExternalSourcesT Identity]
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues [SongExternalSourcesT Identity]
externalContents
  Map UUID Song -> m (Map UUID Song)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID Song
forall k a. Map k a
Map.empty

insertSongComments' :: (MonadIO m) => Env -> [SongComment] -> m (Either SongCommandError ())
insertSongComments' :: forall (m :: * -> *).
MonadIO m =>
Env -> [SongComment] -> m (Either SongCommandError ())
insertSongComments' Env
env [SongComment]
comments = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongCommentT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite SongCommentT -> SqliteM ())
-> (SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongCommentT)
-> SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongCommentT)
-> SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongCommentT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongCommentT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongCommentT)
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 SongCommentT))
#songComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any)) -> m ())
-> SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any)) -> m ()
forall a b. (a -> b) -> a -> b
$ [SongCommentT Identity]
-> SqlInsertValues Sqlite (SongCommentT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((SongComment -> SongCommentT Identity)
-> [SongComment] -> [SongCommentT Identity]
forall a b. (a -> b) -> [a] -> [b]
map SongComment -> SongCommentT Identity
toPersistenceSongComment [SongComment]
comments)
  Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SongCommandError () -> m (Either SongCommandError ()))
-> (() -> Either SongCommandError ())
-> ()
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either SongCommandError ()))
-> () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

insertSongExternalSources' :: (MonadIO m) => Env -> [SongExternalSources] -> m (Map UUID SongExternalSources)
insertSongExternalSources' :: forall (m :: * -> *).
MonadIO m =>
Env -> [SongExternalSources] -> m (Map UUID SongExternalSources)
insertSongExternalSources' Env
env [SongExternalSources]
externalSources = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues
      Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues
      Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite SongExternalSourcesT -> SqliteM ())
-> (SqlInsertValues
      Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongExternalSourcesT)
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongExternalSourcesT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
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 SongExternalSourcesT))
#songExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
 -> m ())
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [SongExternalSourcesT Identity]
-> SqlInsertValues Sqlite (SongExternalSourcesT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((SongExternalSources -> SongExternalSourcesT Identity)
-> [SongExternalSources] -> [SongExternalSourcesT Identity]
forall a b. (a -> b) -> [a] -> [b]
map SongExternalSources -> SongExternalSourcesT Identity
toPersistenceSongExternalSources [SongExternalSources]
externalSources)
  Map UUID SongExternalSources -> m (Map UUID SongExternalSources)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID SongExternalSources
forall k a. Map k a
Map.empty

insertSongArtworks' :: (MonadIO m) => Env -> [SongArtwork] -> m (Map UUID SongArtwork)
insertSongArtworks' :: forall (m :: * -> *).
MonadIO m =>
Env -> [SongArtwork] -> m (Map UUID SongArtwork)
insertSongArtworks' Env
env [SongArtwork]
artworks = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongArtworkT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite SongArtworkT -> SqliteM ())
-> (SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongArtworkT)
-> SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
-> SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongArtworkT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
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 SongArtworkT))
#songArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any)) -> m ())
-> SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any)) -> m ()
forall a b. (a -> b) -> a -> b
$ [SongArtworkT Identity]
-> SqlInsertValues Sqlite (SongArtworkT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((SongArtwork -> SongArtworkT Identity)
-> [SongArtwork] -> [SongArtworkT Identity]
forall a b. (a -> b) -> [a] -> [b]
map SongArtwork -> SongArtworkT Identity
mkSongArtworkP [SongArtwork]
artworks)
  Map UUID SongArtwork -> m (Map UUID SongArtwork)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID SongArtwork
forall k a. Map k a
Map.empty

upsertSongOpinions' :: (MonadIO m) => Env -> [SongOpinion] -> m (Map UUID SongOpinion)
upsertSongOpinions' :: forall (m :: * -> *).
MonadIO m =>
Env -> [SongOpinion] -> m (Map UUID SongOpinion)
upsertSongOpinions' Env
env [SongOpinion]
opinions = do
  (SongOpinion -> m ()) -> [SongOpinion] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
    ( \SongOpinion
o -> do
        Maybe (SongOpinionT Identity)
exOpinion <- IO (Maybe (SongOpinionT Identity))
-> m (Maybe (SongOpinionT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (SongOpinionT Identity))
 -> m (Maybe (SongOpinionT Identity)))
-> IO (Maybe (SongOpinionT Identity))
-> m (Maybe (SongOpinionT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (SongOpinionT Identity))
-> IO (Maybe (SongOpinionT 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 (Maybe (SongOpinionT Identity))
 -> IO (Maybe (SongOpinionT Identity)))
-> SqliteM (Maybe (SongOpinionT Identity))
-> IO (Maybe (SongOpinionT Identity))
forall a b. (a -> b) -> a -> b
$ do
          SqlSelect Sqlite (SongOpinionT Identity)
-> SqliteM (Maybe (SongOpinionT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (SongOpinionT Identity)
 -> SqliteM (Maybe (SongOpinionT Identity)))
-> SqlSelect Sqlite (SongOpinionT Identity)
-> SqliteM (Maybe (SongOpinionT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (SongOpinionT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (SongOpinionT (QExpr 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
   (SongOpinionT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite (QExprToIdentity (SongOpinionT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongOpinionT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (SongOpinionT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
            (SongOpinionT (QExpr Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongOpinionT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongOpinionT (QExpr 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_
              ( \SongOpinionT (QExpr Sqlite QBaseScope)
s ->
                  (SongOpinionT (QExpr Sqlite QBaseScope)
s SongOpinionT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (SongOpinionT (QExpr Sqlite QBaseScope))
     (PrimaryKey SongT (QExpr Sqlite QBaseScope))
-> PrimaryKey SongT (QExpr Sqlite QBaseScope)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongOpinionT (QExpr Sqlite QBaseScope))
  (PrimaryKey SongT (QExpr Sqlite QBaseScope))
#songIdentifier)
                    PrimaryKey SongT (QExpr Sqlite QBaseScope)
-> PrimaryKey SongT (QExpr Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr (PrimaryKey SongT (QExpr Sqlite QBaseScope))
-> PrimaryKey SongT (QExpr Sqlite QBaseScope)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Columnar Identity Text -> PrimaryKey SongT Identity)
-> Columnar Identity Text -> PrimaryKey SongT Identity
forall a b. (a -> b) -> a -> b
$ UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ SongOpinion
o SongOpinion -> Optic' A_Lens NoIx SongOpinion UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx SongOpinion UUID
#songIdentifier)
                    QExpr Sqlite QBaseScope Bool
-> QExpr Sqlite QBaseScope Bool -> QExpr Sqlite QBaseScope Bool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s Bool
-> QGenExpr context be s Bool -> QGenExpr context be s Bool
&&. (SongOpinionT (QExpr Sqlite QBaseScope)
s SongOpinionT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (SongOpinionT (QExpr 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
  (SongOpinionT (QExpr Sqlite QBaseScope))
  (QGenExpr QValueContext Sqlite QBaseScope Text)
#createdBy)
                    QGenExpr QValueContext Sqlite QBaseScope Text
-> QGenExpr QValueContext Sqlite QBaseScope Text
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ SongOpinion
o SongOpinion -> Optic' A_Lens NoIx SongOpinion UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic A_Lens NoIx SongOpinion SongOpinion Opinion Opinion
#opinion Optic A_Lens NoIx SongOpinion SongOpinion Opinion Opinion
-> Optic A_Lens NoIx Opinion Opinion UUID UUID
-> Optic' A_Lens NoIx SongOpinion 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 Opinion Opinion UUID UUID
#createdBy)
              )
              (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (SongOpinionT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongOpinionT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongOpinionT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongOpinionT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongOpinionT (QExpr 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 SongOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
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 SongOpinionT))
#songOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        case Maybe (SongOpinionT Identity)
exOpinion of
          Maybe (SongOpinionT Identity)
Nothing ->
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
              (IO () -> m ())
-> (SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongOpinionT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
              (SqlInsert Sqlite SongOpinionT -> SqliteM ())
-> (SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongOpinionT)
-> SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
-> SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongOpinionT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
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 SongOpinionT))
#songOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
              (SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any)) -> m ())
-> SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any)) -> m ()
forall a b. (a -> b) -> a -> b
$ [SongOpinionT Identity]
-> SqlInsertValues Sqlite (SongOpinionT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues [SongOpinion -> SongOpinionT Identity
mkSongOpinionP SongOpinion
o]
          Just SongOpinionT Identity
oo -> do
            let newO :: SongOpinionT Identity
newO =
                  ( SongOpinionT Identity
oo
                      { isLike = o ^. #opinion % #isLike,
                        isDislike = o ^. #opinion % #isDislike,
                        lastEditedAt = o ^. #opinion % #lastEditedAt
                      }
                  ) ::
                    SongOpinion'
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
              (IO () -> m ())
-> (SqlUpdate Sqlite SongOpinionT -> IO ())
-> SqlUpdate Sqlite SongOpinionT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlUpdate Sqlite SongOpinionT -> SqliteM ())
-> SqlUpdate Sqlite SongOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite SongOpinionT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate
              (SqlUpdate Sqlite SongOpinionT -> m ())
-> SqlUpdate Sqlite SongOpinionT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
-> SongOpinionT Identity -> SqlUpdate Sqlite SongOpinionT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
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 SongOpinionT))
#songOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) SongOpinionT Identity
newO
        () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
    )
    [SongOpinion]
opinions

  Map UUID SongOpinion -> m (Map UUID SongOpinion)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID SongOpinion
forall k a. Map k a
Map.empty

uberDeleteSongs' :: (MonadIO m) => Env -> [UUID] -> m (Either SongCommandError ())
uberDeleteSongs' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
uberDeleteSongs' Env
env [UUID]
identifiers =
  do
    Either SongCommandError ()
deleteArtworksOfSongsResult <- IO (Either SongCommandError ()) -> m (Either SongCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either SongCommandError ()) -> m (Either SongCommandError ()))
-> (Free SongCommand (Either SongCommandError ())
    -> IO (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @SongCommand (Free SongCommand (Either SongCommandError ())
 -> m (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free SongCommand (Either SongCommandError ())
forall (f :: * -> *).
(SongCommand :<: f) =>
Env -> [UUID] -> Free f (Either SongCommandError ())
deleteArtworksOfSongs Env
env [UUID]
identifiers
    Either SongCommandError ()
deleteOpinionsOfSongsResult <- IO (Either SongCommandError ()) -> m (Either SongCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either SongCommandError ()) -> m (Either SongCommandError ()))
-> (Free SongCommand (Either SongCommandError ())
    -> IO (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @SongCommand (Free SongCommand (Either SongCommandError ())
 -> m (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free SongCommand (Either SongCommandError ())
forall (f :: * -> *).
(SongCommand :<: f) =>
Env -> [UUID] -> Free f (Either SongCommandError ())
deleteOpinionsOfSongs Env
env [UUID]
identifiers
    Either SongCommandError ()
deleteCommentsOfSongsResult <- IO (Either SongCommandError ()) -> m (Either SongCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either SongCommandError ()) -> m (Either SongCommandError ()))
-> (Free SongCommand (Either SongCommandError ())
    -> IO (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @SongCommand (Free SongCommand (Either SongCommandError ())
 -> m (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free SongCommand (Either SongCommandError ())
forall (f :: * -> *).
(SongCommand :<: f) =>
Env -> [UUID] -> Free f (Either SongCommandError ())
deleteCommentsOfSongs Env
env [UUID]
identifiers
    Either SongCommandError ()
deleteSongExternalSourcesResult <- IO (Either SongCommandError ()) -> m (Either SongCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either SongCommandError ()) -> m (Either SongCommandError ()))
-> (Free SongCommand (Either SongCommandError ())
    -> IO (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @SongCommand (Free SongCommand (Either SongCommandError ())
 -> m (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free SongCommand (Either SongCommandError ())
forall (f :: * -> *).
(SongCommand :<: f) =>
Env -> [UUID] -> Free f (Either SongCommandError ())
deleteSongExternalSources Env
env [UUID]
identifiers
    Either SongCommandError ()
deleteSongsResult <- Env -> [UUID] -> m (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
doDeleteSongs' Env
env [UUID]
identifiers
    Either SongCommandError ()
deleteArtistsOfSongResult <- IO (Either SongCommandError ()) -> m (Either SongCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either SongCommandError ()) -> m (Either SongCommandError ()))
-> (Free SongCommand (Either SongCommandError ())
    -> IO (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @SongCommand (Free SongCommand (Either SongCommandError ())
 -> m (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free SongCommand (Either SongCommandError ())
forall (f :: * -> *).
(SongCommand :<: f) =>
Env -> [UUID] -> Free f (Either SongCommandError ())
deleteArtistsOfSongs Env
env [UUID]
identifiers
    Either SongCommandError ()
deleteContentsOfSongResult <- IO (Either SongCommandError ()) -> m (Either SongCommandError ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either SongCommandError ()) -> m (Either SongCommandError ()))
-> (Free SongCommand (Either SongCommandError ())
    -> IO (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @SongCommand (Free SongCommand (Either SongCommandError ())
 -> m (Either SongCommandError ()))
-> Free SongCommand (Either SongCommandError ())
-> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ Env -> [UUID] -> Free SongCommand (Either SongCommandError ())
forall (f :: * -> *).
(SongCommand :<: f) =>
Env -> [UUID] -> Free f (Either SongCommandError ())
deleteContentsOfSongs Env
env [UUID]
identifiers
    Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
      (Either SongCommandError () -> m (Either SongCommandError ()))
-> Either SongCommandError () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ Either SongCommandError ()
deleteArtworksOfSongsResult
      Either SongCommandError ()
-> Either SongCommandError () -> Either SongCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either SongCommandError ()
deleteOpinionsOfSongsResult
      Either SongCommandError ()
-> Either SongCommandError () -> Either SongCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either SongCommandError ()
deleteSongExternalSourcesResult
      Either SongCommandError ()
-> Either SongCommandError () -> Either SongCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either SongCommandError ()
deleteCommentsOfSongsResult
      Either SongCommandError ()
-> Either SongCommandError () -> Either SongCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either SongCommandError ()
deleteArtistsOfSongResult
      Either SongCommandError ()
-> Either SongCommandError () -> Either SongCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either SongCommandError ()
deleteContentsOfSongResult
      Either SongCommandError ()
-> Either SongCommandError () -> Either SongCommandError ()
forall a. Semigroup a => a -> a -> a
<> Either SongCommandError ()
deleteSongsResult

doDeleteSongs' :: (MonadIO m) => Env -> [UUID] -> m (Either SongCommandError ())
doDeleteSongs' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
doDeleteSongs' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite SongT -> IO ())
-> SqlDelete Sqlite SongT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongT -> SqliteM ())
-> SqlDelete Sqlite SongT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite SongT -> m ()) -> SqlDelete Sqlite SongT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
-> (forall s.
    (forall s'. SongT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
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 SongT))
#songs) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. SongT (QExpr Sqlite s')
c -> (SongT (QGenExpr QValueContext Sqlite s)
forall s'. SongT (QExpr Sqlite s')
c SongT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SongCommandError () -> m (Either SongCommandError ()))
-> (() -> Either SongCommandError ())
-> ()
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either SongCommandError ()))
-> () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

updateSongArtworkOrder' :: (MonadIO m) => Env -> [SongArtworkOrderUpdate] -> m (Either a ())
updateSongArtworkOrder' :: forall (m :: * -> *) a.
MonadIO m =>
Env -> [SongArtworkOrderUpdate] -> m (Either a ())
updateSongArtworkOrder' Env
env [SongArtworkOrderUpdate]
orderUpdates = do
  (SongArtworkOrderUpdate -> m ())
-> [SongArtworkOrderUpdate] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
    ( \SongArtworkOrderUpdate
ou -> do
        Maybe (SongArtworkT Identity)
art <- IO (Maybe (SongArtworkT Identity))
-> m (Maybe (SongArtworkT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (SongArtworkT Identity))
 -> m (Maybe (SongArtworkT Identity)))
-> IO (Maybe (SongArtworkT Identity))
-> m (Maybe (SongArtworkT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (SongArtworkT Identity))
-> IO (Maybe (SongArtworkT 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 (Maybe (SongArtworkT Identity))
 -> IO (Maybe (SongArtworkT Identity)))
-> SqliteM (Maybe (SongArtworkT Identity))
-> IO (Maybe (SongArtworkT Identity))
forall a b. (a -> b) -> a -> b
$ do
          SqlSelect Sqlite (SongArtworkT Identity)
-> SqliteM (Maybe (SongArtworkT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (SongArtworkT Identity)
 -> SqliteM (Maybe (SongArtworkT Identity)))
-> SqlSelect Sqlite (SongArtworkT Identity)
-> SqliteM (Maybe (SongArtworkT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (SongArtworkT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (SongArtworkT (QExpr 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
   (SongArtworkT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite (QExprToIdentity (SongArtworkT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongArtworkT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (SongArtworkT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
            (SongArtworkT (QExpr Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongArtworkT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongArtworkT (QExpr 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_
              (\SongArtworkT (QExpr Sqlite QBaseScope)
s -> (SongArtworkT (QExpr Sqlite QBaseScope)
s SongArtworkT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (SongArtworkT (QExpr 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
  (SongArtworkT (QExpr 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. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr
  (QGenExpr QValueContext Sqlite QBaseScope Text)
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ SongArtworkOrderUpdate
ou SongArtworkOrderUpdate
-> Optic' A_Lens NoIx SongArtworkOrderUpdate UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx SongArtworkOrderUpdate UUID
#identifier))
              (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (SongArtworkT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongArtworkT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongArtworkT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongArtworkT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongArtworkT (QExpr 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 SongArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
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 SongArtworkT))
#songArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        case Maybe (SongArtworkT Identity)
art of
          Maybe (SongArtworkT Identity)
Nothing -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
          Just SongArtworkT Identity
foundArt -> do
            let a :: SongArtworkT Identity
a = SongArtworkT Identity
foundArt {orderValue = fromIntegral $ ou ^. #orderValue} :: SongArtwork'
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> (SongArtworkT Identity -> IO ())
-> SongArtworkT Identity
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SongArtworkT Identity -> SqliteM ())
-> SongArtworkT Identity
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite SongArtworkT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate (SqlUpdate Sqlite SongArtworkT -> SqliteM ())
-> (SongArtworkT Identity -> SqlUpdate Sqlite SongArtworkT)
-> SongArtworkT Identity
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
-> SongArtworkT Identity -> SqlUpdate Sqlite SongArtworkT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
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 SongArtworkT))
#songArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (SongArtworkT Identity -> m ()) -> SongArtworkT Identity -> m ()
forall a b. (a -> b) -> a -> b
$ SongArtworkT Identity
a
    )
    [SongArtworkOrderUpdate]
orderUpdates
  Either a () -> m (Either a ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either a () -> m (Either a ()))
-> (() -> Either a ()) -> () -> m (Either a ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either a ()
forall a b. b -> Either a b
Right (() -> m (Either a ())) -> () -> m (Either a ())
forall a b. (a -> b) -> a -> b
$ ()

updateSongs' :: (MonadIO m) => Env -> Map UUID (Song, Maybe SongDelta) -> m (Either Text ())
updateSongs' :: forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Song, Maybe SongDelta) -> m (Either Text ())
updateSongs' Env
env Map UUID (Song, Maybe SongDelta)
deltas = do
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ((Song, Maybe SongDelta) -> m ())
-> [(Song, Maybe SongDelta)] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ (SongT Identity -> m ()
save'' (SongT Identity -> m ())
-> ((Song, Maybe SongDelta) -> SongT Identity)
-> (Song, Maybe SongDelta)
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Song -> SongT Identity
toPersistenceSong (Song -> SongT Identity)
-> ((Song, Maybe SongDelta) -> Song)
-> (Song, Maybe SongDelta)
-> SongT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UTCTime -> (Song, Maybe SongDelta) -> Song
doDelta UTCTime
now) (Map UUID (Song, Maybe SongDelta) -> [(Song, Maybe SongDelta)]
forall k a. Map k a -> [a]
Map.elems Map UUID (Song, Maybe SongDelta)
deltas)
  Either Text ()
exUpdate <- IO (Either Text ()) -> m (Either Text ())
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Either Text ()) -> m (Either Text ()))
-> IO (Either Text ()) -> m (Either Text ())
forall a b. (a -> b) -> a -> b
$ forall (f :: * -> *) a. Exec f => Free f a -> IO a
exec @SongCommand (Free SongCommand (Either Text ()) -> IO (Either Text ()))
-> Free SongCommand (Either Text ()) -> IO (Either Text ())
forall a b. (a -> b) -> a -> b
$ Env
-> Map UUID (Song, Maybe SongDelta)
-> Free SongCommand (Either Text ())
forall (f :: * -> *).
(SongCommand :<: f) =>
Env -> Map UUID (Song, Maybe SongDelta) -> Free f (Either Text ())
updateSongExternalSources Env
env Map UUID (Song, Maybe SongDelta)
deltas
  Either Text () -> m (Either Text ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text () -> m (Either Text ()))
-> Either Text () -> m (Either Text ())
forall a b. (a -> b) -> a -> b
$ Either Text ()
exUpdate Either Text () -> Either Text () -> Either Text ()
forall a. Semigroup a => a -> a -> a
<> () -> Either Text ()
forall a b. b -> Either a b
Right ()
  where
    save'' :: SongT Identity -> m ()
save'' SongT Identity
x =
      IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
        (IO () -> m ())
-> (SqlUpdate Sqlite SongT -> IO ())
-> SqlUpdate Sqlite SongT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlUpdate Sqlite SongT -> SqliteM ())
-> SqlUpdate Sqlite SongT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite SongT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate
        (SqlUpdate Sqlite SongT -> m ()) -> SqlUpdate Sqlite SongT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
-> SongT Identity -> SqlUpdate Sqlite SongT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
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 SongT))
#songs) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) SongT Identity
x
    doDelta :: UTCTime -> (Song, Maybe SongDelta) -> Song
    doDelta :: UTCTime -> (Song, Maybe SongDelta) -> Song
doDelta UTCTime
now (Song
x, Maybe SongDelta
xDelta') =
      case Maybe SongDelta
xDelta' of
        Maybe SongDelta
Nothing -> Song
x
        Just SongDelta
xDelta ->
          Song
x
            { musicKey = xDelta ^. #musicKey,
              musicTuning = xDelta ^. #musicTuning,
              musicCreationDate = xDelta ^. #musicCreationDate,
              albumName = xDelta ^. #albumName,
              albumInfoLink = xDelta ^. #albumInfoLink,
              displayName = fromMaybe (x ^. #displayName) (xDelta ^. #displayName),
              description = xDelta ^. #description,
              lastEditedAt = Just now
            }

updateSongExternalSources' :: (MonadIO m) => Env -> Map UUID (Song, Maybe SongDelta) -> m (Either Text ())
updateSongExternalSources' :: forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Song, Maybe SongDelta) -> m (Either Text ())
updateSongExternalSources' Env
env Map UUID (Song, Maybe SongDelta)
deltas = do
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ((Song, Maybe SongDelta) -> m ())
-> Map UUID (Song, Maybe SongDelta) -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
    ( \(Song
song, Maybe SongDelta
xDelta) -> do
        Maybe (SongExternalSourcesT Identity)
ex <- IO (Maybe (SongExternalSourcesT Identity))
-> m (Maybe (SongExternalSourcesT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (SongExternalSourcesT Identity))
 -> m (Maybe (SongExternalSourcesT Identity)))
-> IO (Maybe (SongExternalSourcesT Identity))
-> m (Maybe (SongExternalSourcesT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (SongExternalSourcesT Identity))
-> IO (Maybe (SongExternalSourcesT 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 (Maybe (SongExternalSourcesT Identity))
 -> IO (Maybe (SongExternalSourcesT Identity)))
-> SqliteM (Maybe (SongExternalSourcesT Identity))
-> IO (Maybe (SongExternalSourcesT Identity))
forall a b. (a -> b) -> a -> b
$ do
          SqlSelect Sqlite (SongExternalSourcesT Identity)
-> SqliteM (Maybe (SongExternalSourcesT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (SongExternalSourcesT Identity)
 -> SqliteM (Maybe (SongExternalSourcesT Identity)))
-> SqlSelect Sqlite (SongExternalSourcesT Identity)
-> SqliteM (Maybe (SongExternalSourcesT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (SongExternalSourcesT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity (SongExternalSourcesT (QExpr 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
   (SongExternalSourcesT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite
      (QExprToIdentity (SongExternalSourcesT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongExternalSourcesT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite
     (QExprToIdentity (SongExternalSourcesT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
            (SongExternalSourcesT (QExpr Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongExternalSourcesT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongExternalSourcesT (QExpr 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_
              (\SongExternalSourcesT (QExpr Sqlite QBaseScope)
s -> (SongExternalSourcesT (QExpr Sqlite QBaseScope)
s SongExternalSourcesT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (SongExternalSourcesT (QExpr Sqlite QBaseScope))
     (PrimaryKey SongT (QExpr Sqlite QBaseScope))
-> PrimaryKey SongT (QExpr Sqlite QBaseScope)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongExternalSourcesT (QExpr Sqlite QBaseScope))
  (PrimaryKey SongT (QExpr Sqlite QBaseScope))
#songIdentifier) PrimaryKey SongT (QExpr Sqlite QBaseScope)
-> PrimaryKey SongT (QExpr Sqlite QBaseScope)
-> QExpr Sqlite QBaseScope Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. HaskellLiteralForQExpr (PrimaryKey SongT (QExpr Sqlite QBaseScope))
-> PrimaryKey SongT (QExpr Sqlite QBaseScope)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Columnar Identity Text -> PrimaryKey SongT Identity)
-> Columnar Identity Text -> PrimaryKey SongT Identity
forall a b. (a -> b) -> a -> b
$ UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ Song
song Song -> Optic' A_Lens NoIx Song UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx Song UUID
#identifier))
              (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (SongExternalSourcesT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongExternalSourcesT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongExternalSourcesT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongExternalSourcesT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongExternalSourcesT (QExpr 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 SongExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
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 SongExternalSourcesT))
#songExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        case Maybe (SongExternalSourcesT Identity)
ex of
          Maybe (SongExternalSourcesT Identity)
Nothing -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
          Just SongExternalSourcesT Identity
foundEx -> do
            let a :: SongExternalSourcesT Identity
a =
                  SongExternalSourcesT Identity
foundEx
                    { spotifyUrl = (^. #spotifyUrl) =<< xDelta,
                      wikipediaUrl = (^. #wikipediaUrl) =<< xDelta,
                      soundcloudUrl = (^. #soundcloudUrl) =<< xDelta,
                      youtubeUrl = (^. #youtubeUrl) =<< xDelta,
                      lastEditedAt = Just now
                    } ::
                    SongExternalSources'
            IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> (SongExternalSourcesT Identity -> IO ())
-> SongExternalSourcesT Identity
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SongExternalSourcesT Identity -> SqliteM ())
-> SongExternalSourcesT Identity
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite SongExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate (SqlUpdate Sqlite SongExternalSourcesT -> SqliteM ())
-> (SongExternalSourcesT Identity
    -> SqlUpdate Sqlite SongExternalSourcesT)
-> SongExternalSourcesT Identity
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
-> SongExternalSourcesT Identity
-> SqlUpdate Sqlite SongExternalSourcesT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
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 SongExternalSourcesT))
#songExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (SongExternalSourcesT Identity -> m ())
-> SongExternalSourcesT Identity -> m ()
forall a b. (a -> b) -> a -> b
$ SongExternalSourcesT Identity
a
    )
    Map UUID (Song, Maybe SongDelta)
deltas
  Either Text () -> m (Either Text ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text () -> m (Either Text ()))
-> (() -> Either Text ()) -> () -> m (Either Text ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either Text ()
forall a b. b -> Either a b
Right (() -> m (Either Text ())) -> () -> m (Either Text ())
forall a b. (a -> b) -> a -> b
$ ()

newSongArtworkFromRequest' :: (MonadIO m) => UUID -> InsertSongArtworksRequestItem -> m SongArtwork
newSongArtworkFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongArtworksRequestItem -> m SongArtwork
newSongArtworkFromRequest' UUID
createdBy InsertSongArtworksRequestItem
req = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  SongArtwork -> m SongArtwork
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (SongArtwork -> m SongArtwork) -> SongArtwork -> m SongArtwork
forall a b. (a -> b) -> a -> b
$ SongArtwork
      { $sel:songIdentifier:SongArtwork :: UUID
songIdentifier = InsertSongArtworksRequestItem
req InsertSongArtworksRequestItem
-> Optic' A_Lens NoIx InsertSongArtworksRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongArtworksRequestItem UUID
#songIdentifier,
        $sel:artwork:SongArtwork :: Artwork
artwork =
          Artwork
            { $sel:identifier:Artwork :: UUID
identifier = UUID
newUUID,
              $sel:createdBy:Artwork :: UUID
createdBy = UUID
createdBy,
              $sel:contentUrl:Artwork :: Text
contentUrl = InsertSongArtworksRequestItem
req InsertSongArtworksRequestItem
-> Optic' A_Lens NoIx InsertSongArtworksRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongArtworksRequestItem Text
#contentUrl,
              $sel:contentCaption:Artwork :: Maybe Text
contentCaption = InsertSongArtworksRequestItem
req InsertSongArtworksRequestItem
-> Optic' A_Lens NoIx InsertSongArtworksRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongArtworksRequestItem (Maybe Text)
#contentCaption,
              $sel:createdAt:Artwork :: UTCTime
createdAt = UTCTime
now,
              $sel:lastEditedAt:Artwork :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing,
              $sel:visibilityStatus:Artwork :: Int
visibilityStatus = Int
0,
              $sel:approvedBy:Artwork :: Maybe UUID
approvedBy = Maybe UUID
forall a. Maybe a
Nothing,
              $sel:orderValue:Artwork :: Int
orderValue = InsertSongArtworksRequestItem
req InsertSongArtworksRequestItem
-> Optic' A_Lens NoIx InsertSongArtworksRequestItem Int -> Int
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongArtworksRequestItem Int
#orderValue
            }
      }

newSongOpinionFromRequest' :: (MonadIO m) => UUID -> UpsertSongOpinionsRequestItem -> m SongOpinion
newSongOpinionFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> UpsertSongOpinionsRequestItem -> m SongOpinion
newSongOpinionFromRequest' UUID
createdBy UpsertSongOpinionsRequestItem
req = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  SongOpinion -> m SongOpinion
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (SongOpinion -> m SongOpinion) -> SongOpinion -> m SongOpinion
forall a b. (a -> b) -> a -> b
$ SongOpinion
      { $sel:songIdentifier:SongOpinion :: UUID
songIdentifier = UpsertSongOpinionsRequestItem
req UpsertSongOpinionsRequestItem
-> Optic' A_Lens NoIx UpsertSongOpinionsRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx UpsertSongOpinionsRequestItem UUID
#songIdentifier,
        $sel:opinion:SongOpinion :: Opinion
opinion =
          Opinion
            { $sel:identifier:Opinion :: UUID
identifier = UUID
newUUID,
              $sel:createdBy:Opinion :: UUID
createdBy = UUID
createdBy,
              $sel:isLike:Opinion :: Bool
isLike = UpsertSongOpinionsRequestItem
req UpsertSongOpinionsRequestItem
-> Optic' A_Lens NoIx UpsertSongOpinionsRequestItem Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx UpsertSongOpinionsRequestItem Bool
#isLike,
              $sel:isDislike:Opinion :: Bool
isDislike = Bool -> Bool
not (Bool -> Bool) -> Bool -> Bool
forall a b. (a -> b) -> a -> b
$ UpsertSongOpinionsRequestItem
req UpsertSongOpinionsRequestItem
-> Optic' A_Lens NoIx UpsertSongOpinionsRequestItem Bool -> Bool
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx UpsertSongOpinionsRequestItem Bool
#isLike,
              $sel:createdAt:Opinion :: UTCTime
createdAt = UTCTime
now,
              $sel:lastEditedAt:Opinion :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing
            }
      }

updateSongContents' :: (MonadIO m) => Env -> [SongContentDelta] -> m (Either Text ())
updateSongContents' :: forall (m :: * -> *).
MonadIO m =>
Env -> [SongContentDelta] -> m (Either Text ())
updateSongContents' Env
env [SongContentDelta]
songContentDeltas = do
  [SongContents']
songContentsP <-
    IO [SongContents'] -> m [SongContents']
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO [SongContents'] -> m [SongContents'])
-> (Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongContentsT (QExpr Sqlite QBaseScope))
    -> IO [SongContents'])
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr Sqlite QBaseScope))
-> m [SongContents']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ())
-> Connection -> SqliteM [SongContents'] -> IO [SongContents']
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 [SongContents'] -> IO [SongContents'])
-> (Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongContentsT (QExpr Sqlite QBaseScope))
    -> SqliteM [SongContents'])
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr Sqlite QBaseScope))
-> IO [SongContents']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlSelect Sqlite SongContents' -> SqliteM [SongContents']
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m [a]
runSelectReturningList
      (SqlSelect Sqlite SongContents' -> SqliteM [SongContents'])
-> (Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongContentsT (QExpr Sqlite QBaseScope))
    -> SqlSelect Sqlite SongContents')
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr Sqlite QBaseScope))
-> SqliteM [SongContents']
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (SongContentsT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (SongContentsT (QExpr Sqlite QBaseScope)))
Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (SongContentsT (QExpr Sqlite QBaseScope))
-> SqlSelect Sqlite SongContents'
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
   (SongContentsT (QExpr Sqlite QBaseScope))
 -> SqlSelect Sqlite SongContents')
-> (Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongContentsT (QExpr Sqlite QBaseScope))
    -> Q Sqlite
         WikiMusicDatabase
         QBaseScope
         (SongContentsT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr Sqlite QBaseScope))
-> SqlSelect Sqlite SongContents'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (SongContentsT (QExpr Sqlite QBaseScope)
 -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr 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_ (\SongContentsT (QExpr Sqlite QBaseScope)
s -> (SongContentsT (QExpr Sqlite QBaseScope)
s SongContentsT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (SongContentsT (QExpr 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
  (SongContentsT (QExpr 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_` (SongContentDelta -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> [SongContentDelta]
-> [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)
-> (SongContentDelta -> Text)
-> SongContentDelta
-> QGenExpr QValueContext Sqlite QBaseScope Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (\SongContentDelta
z -> UUID -> Text
UUID.toText (UUID -> Text) -> UUID -> Text
forall a b. (a -> b) -> a -> b
$ SongContentDelta
z SongContentDelta
-> Optic' A_Lens NoIx SongContentDelta UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx SongContentDelta UUID
#identifier)) [SongContentDelta]
songContentDeltas)
      (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (SongContentsT (QExpr Sqlite QBaseScope))
 -> m [SongContents'])
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr Sqlite QBaseScope))
-> m [SongContents']
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongContentsT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongContentsT (QExpr 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 SongContentsT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongContentsT)
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 SongContentsT))
#songContents) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)

  ()
_ <- IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> ([SongContentDelta] -> IO ()) -> [SongContentDelta] -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. String -> IO ()
forall (m :: * -> *). MonadIO m => String -> m ()
putStrLn (String -> IO ())
-> ([SongContentDelta] -> String) -> [SongContentDelta] -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. [SongContentDelta] -> String
forall b a. (Show a, IsString b) => a -> b
Relude.show ([SongContentDelta] -> m ()) -> [SongContentDelta] -> m ()
forall a b. (a -> b) -> a -> b
$ [SongContentDelta]
songContentDeltas
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  let updatedP :: [Maybe SongContents']
updatedP =
        (SongContentDelta -> Maybe SongContents')
-> [SongContentDelta] -> [Maybe SongContents']
forall a b. (a -> b) -> [a] -> [b]
map
          ( \SongContentDelta
songContentDelta -> do
              (NonEmpty SongContents' -> SongContents')
-> Maybe (NonEmpty SongContents') -> Maybe SongContents'
forall a b. (a -> b) -> Maybe a -> Maybe b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SongContentDelta -> UTCTime -> SongContents' -> SongContents'
updatedSongContent SongContentDelta
songContentDelta UTCTime
now (SongContents' -> SongContents')
-> (NonEmpty SongContents' -> SongContents')
-> NonEmpty SongContents'
-> SongContents'
forall b c a. (b -> c) -> (a -> b) -> a -> c
. NonEmpty SongContents' -> SongContents'
forall (f :: * -> *) a. IsNonEmpty f a a "head" => f a -> a
head)
                (Maybe (NonEmpty SongContents') -> Maybe SongContents')
-> Maybe (NonEmpty SongContents') -> Maybe SongContents'
forall a b. (a -> b) -> a -> b
$ [SongContents'] -> Maybe (NonEmpty SongContents')
forall a. [a] -> Maybe (NonEmpty a)
nonEmpty
                ([SongContents'] -> Maybe (NonEmpty SongContents'))
-> [SongContents'] -> Maybe (NonEmpty SongContents')
forall a b. (a -> b) -> a -> b
$ (SongContents' -> Bool) -> [SongContents'] -> [SongContents']
forall a. (a -> Bool) -> [a] -> [a]
filter
                  ( \SongContents'
songContentP -> SongContents'
songContentP SongContents' -> Optic' A_Lens NoIx SongContents' Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx SongContents' Text
#identifier Text -> Text -> Bool
forall a. Eq a => a -> a -> Bool
== UUID -> Text
UUID.toText (SongContentDelta
songContentDelta SongContentDelta
-> Optic' A_Lens NoIx SongContentDelta UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx SongContentDelta UUID
#identifier)
                  )
                  [SongContents']
songContentsP
          )
          [SongContentDelta]
songContentDeltas
  (SongContents' -> m ()) -> [SongContents'] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
    ( IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
        (IO () -> m ())
-> (SongContents' -> IO ()) -> SongContents' -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SongContents' -> SqliteM ()) -> SongContents' -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite SongContentsT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate
        (SqlUpdate Sqlite SongContentsT -> SqliteM ())
-> (SongContents' -> SqlUpdate Sqlite SongContentsT)
-> SongContents'
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongContentsT)
-> SongContents' -> SqlUpdate Sqlite SongContentsT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongContentsT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongContentsT)
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 SongContentsT))
#songContents) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    )
    ([Maybe SongContents'] -> [SongContents']
forall a. [Maybe a] -> [a]
catMaybes [Maybe SongContents']
updatedP)
  Either Text () -> m (Either Text ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either Text () -> m (Either Text ()))
-> (() -> Either Text ()) -> () -> m (Either Text ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either Text ()
forall a b. b -> Either a b
Right (() -> m (Either Text ())) -> () -> m (Either Text ())
forall a b. (a -> b) -> a -> b
$ ()

updatedSongContent :: SongContentDelta -> UTCTime -> SongContents' -> SongContents'
updatedSongContent :: SongContentDelta -> UTCTime -> SongContents' -> SongContents'
updatedSongContent SongContentDelta
songContentDelta UTCTime
now SongContents'
x =
  SongContents'
x
    { versionName = songContentDelta ^. #versionName,
      instrumentType = fromMaybe "" (songContentDelta ^. #instrumentType),
      asciiLegend = songContentDelta ^. #asciiLegend,
      asciiContents = songContentDelta ^. #asciiContents,
      pdfContents = songContentDelta ^. #pdfContents,
      guitarProContents = songContentDelta ^. #guitarProContents,
      lastEditedAt = Just now
    } ::
    SongContents'

deleteArtistOfSong' :: (MonadIO m) => Env -> (UUID, UUID) -> m (Either SongCommandError ())
deleteArtistOfSong' :: forall (m :: * -> *).
MonadIO m =>
Env -> (UUID, UUID) -> m (Either SongCommandError ())
deleteArtistOfSong' Env
env (UUID
songId, UUID
artistId) = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite SongArtistT -> IO ())
-> SqlDelete Sqlite SongArtistT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongArtistT -> SqliteM ())
-> SqlDelete Sqlite SongArtistT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongArtistT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite SongArtistT -> m ())
-> SqlDelete Sqlite SongArtistT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtistT)
-> (forall s.
    (forall s'. SongArtistT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongArtistT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtistT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtistT)
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 SongArtistT))
#songArtists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. SongArtistT (QExpr Sqlite s')
c -> (SongArtistT (QGenExpr QValueContext Sqlite s)
forall s'. SongArtistT (QExpr Sqlite s')
c SongArtistT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongArtistT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongArtistT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
#songIdentifier) PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. (PrimaryKey SongT Identity
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey SongT Identity
 -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey SongT Identity)
-> UUID
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey SongT Identity
Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Text -> PrimaryKey SongT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey SongT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText (UUID -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> UUID -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a b. (a -> b) -> a -> b
$ UUID
songId) QExpr Sqlite s Bool -> QExpr Sqlite s Bool -> QExpr Sqlite s Bool
forall be context s.
BeamSqlBackend be =>
QGenExpr context be s Bool
-> QGenExpr context be s Bool -> QGenExpr context be s Bool
&&. (SongArtistT (QGenExpr QValueContext Sqlite s)
forall s'. SongArtistT (QExpr Sqlite s')
c SongArtistT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongArtistT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongArtistT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
#artistIdentifier) PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. (PrimaryKey ArtistT Identity
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey ArtistT Identity
 -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey ArtistT Identity)
-> UUID
-> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey ArtistT Identity
Columnar Identity Text -> PrimaryKey ArtistT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey ArtistT f
ArtistId (Text -> PrimaryKey ArtistT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey ArtistT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText (UUID -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s))
-> UUID -> PrimaryKey ArtistT (QGenExpr QValueContext Sqlite s)
forall a b. (a -> b) -> a -> b
$ UUID
artistId))

  Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SongCommandError () -> m (Either SongCommandError ()))
-> (() -> Either SongCommandError ())
-> ()
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either SongCommandError ()))
-> () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

newSongCommentFromRequest' :: (MonadIO m) => UUID -> InsertSongCommentsRequestItem -> m SongComment
newSongCommentFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongCommentsRequestItem -> m SongComment
newSongCommentFromRequest' UUID
createdBy InsertSongCommentsRequestItem
x = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  SongComment -> m SongComment
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (SongComment -> m SongComment) -> SongComment -> m SongComment
forall a b. (a -> b) -> a -> b
$ SongComment
      { $sel:songIdentifier:SongComment :: UUID
songIdentifier = InsertSongCommentsRequestItem
x InsertSongCommentsRequestItem
-> Optic' A_Lens NoIx InsertSongCommentsRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongCommentsRequestItem UUID
#songIdentifier,
        $sel:comment:SongComment :: Comment
comment =
          Comment
            { $sel:identifier:Comment :: UUID
identifier = UUID
newUUID,
              $sel:parentIdentifier:Comment :: Maybe UUID
parentIdentifier = InsertSongCommentsRequestItem
x InsertSongCommentsRequestItem
-> Optic' A_Lens NoIx InsertSongCommentsRequestItem (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 InsertSongCommentsRequestItem (Maybe UUID)
#parentIdentifier,
              $sel:createdBy:Comment :: UUID
createdBy = UUID
createdBy,
              $sel:visibilityStatus:Comment :: Int
visibilityStatus = Int
0,
              $sel:contents:Comment :: Text
contents = InsertSongCommentsRequestItem
x InsertSongCommentsRequestItem
-> Optic' A_Lens NoIx InsertSongCommentsRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongCommentsRequestItem Text
#contents,
              $sel:approvedBy:Comment :: Maybe UUID
approvedBy = Maybe UUID
forall a. Maybe a
Nothing,
              $sel:createdAt:Comment :: UTCTime
createdAt = UTCTime
now,
              $sel:lastEditedAt:Comment :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing
            }
      }

insertSongContents' :: (MonadIO m) => Env -> [SongContent] -> m (Map UUID SongContent)
insertSongContents' :: forall (m :: * -> *).
MonadIO m =>
Env -> [SongContent] -> m (Map UUID SongContent)
insertSongContents' Env
env [SongContent]
contents = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
    -> IO ())
-> SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
    -> SqliteM ())
-> SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlInsert Sqlite SongContentsT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlInsert be table -> m ()
runInsert
    (SqlInsert Sqlite SongContentsT -> SqliteM ())
-> (SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
    -> SqlInsert Sqlite SongContentsT)
-> SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongContentsT)
-> SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
-> SqlInsert Sqlite SongContentsT
forall be (table :: (* -> *) -> *) s (db :: (* -> *) -> *).
(BeamSqlBackend be,
 ProjectibleWithPredicate AnyType () Text (table (QField s))) =>
DatabaseEntity be db (TableEntity table)
-> SqlInsertValues be (table (QExpr be s)) -> SqlInsert be table
insert ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongContentsT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongContentsT)
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 SongContentsT))
#songContents) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
    (SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any)) -> m ())
-> SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
-> m ()
forall a b. (a -> b) -> a -> b
$ [SongContents']
-> SqlInsertValues Sqlite (SongContentsT (QExpr Sqlite Any))
forall be (table :: (* -> *) -> *) s.
(BeamSqlBackend be, Beamable table,
 FieldsFulfillConstraint (BeamSqlBackendCanSerialize be) table) =>
[table Identity] -> SqlInsertValues be (table (QExpr be s))
insertValues ((SongContent -> SongContents') -> [SongContent] -> [SongContents']
forall a b. (a -> b) -> [a] -> [b]
map SongContent -> SongContents'
mkSongContentsP [SongContent]
contents)
  Map UUID SongContent -> m (Map UUID SongContent)
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure Map UUID SongContent
forall k a. Map k a
Map.empty

newSongFromRequest' :: (MonadIO m) => UUID -> InsertSongsRequestItem -> m Song
newSongFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongsRequestItem -> m Song
newSongFromRequest' UUID
createdBy InsertSongsRequestItem
song = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  Song -> m Song
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (Song -> m Song) -> Song -> m Song
forall a b. (a -> b) -> a -> b
$ Song
      { $sel:identifier:Song :: UUID
identifier = UUID
newUUID,
        $sel:displayName:Song :: Text
displayName = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem Text
#displayName,
        $sel:musicKey:Song :: Maybe Text
musicKey = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#musicKey,
        $sel:musicTuning:Song :: Maybe Text
musicTuning = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#musicTuning,
        $sel:musicCreationDate:Song :: Maybe Text
musicCreationDate = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#musicCreationDate,
        $sel:albumName:Song :: Maybe Text
albumName = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#albumName,
        $sel:albumInfoLink:Song :: Maybe Text
albumInfoLink = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#albumInfoLink,
        $sel:createdBy:Song :: UUID
createdBy = UUID
createdBy,
        $sel:visibilityStatus:Song :: Int
visibilityStatus = Int
0,
        $sel:approvedBy:Song :: Maybe UUID
approvedBy = Maybe UUID
forall a. Maybe a
Nothing,
        $sel:createdAt:Song :: UTCTime
createdAt = UTCTime
now,
        $sel:lastEditedAt:Song :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing,
        $sel:artworks:Song :: Map UUID SongArtwork
artworks = Map UUID SongArtwork
forall k a. Map k a
Map.empty,
        $sel:comments:Song :: [ThreadRender SongComment]
comments = [],
        $sel:opinions:Song :: Map UUID SongOpinion
opinions = Map UUID SongOpinion
forall k a. Map k a
Map.empty,
        $sel:contents:Song :: Map UUID SongContent
contents = Map UUID SongContent
forall k a. Map k a
Map.empty,
        $sel:spotifyUrl:Song :: Maybe Text
spotifyUrl = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#spotifyUrl,
        $sel:youtubeUrl:Song :: Maybe Text
youtubeUrl = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#youtubeUrl,
        $sel:soundcloudUrl:Song :: Maybe Text
soundcloudUrl = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#soundcloudUrl,
        $sel:wikipediaUrl:Song :: Maybe Text
wikipediaUrl = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#wikipediaUrl,
        $sel:artists:Song :: Map UUID Text
artists = Map UUID Text
forall k a. Map k a
Map.empty,
        $sel:viewCount:Song :: Int
viewCount = Int
0,
        $sel:description:Song :: Maybe Text
description = InsertSongsRequestItem
song InsertSongsRequestItem
-> Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongsRequestItem (Maybe Text)
#description
      }

newArtistOfSongFromRequest' :: (MonadIO m) => UUID -> InsertArtistsOfSongsRequestItem -> m ArtistOfSong
newArtistOfSongFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistsOfSongsRequestItem -> m ArtistOfSong
newArtistOfSongFromRequest' UUID
createdBy InsertArtistsOfSongsRequestItem
x = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  ArtistOfSong -> m ArtistOfSong
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (ArtistOfSong -> m ArtistOfSong) -> ArtistOfSong -> m ArtistOfSong
forall a b. (a -> b) -> a -> b
$ ArtistOfSong
      { $sel:identifier:ArtistOfSong :: UUID
identifier = UUID
newUUID,
        $sel:songIdentifier:ArtistOfSong :: UUID
songIdentifier = InsertArtistsOfSongsRequestItem
x InsertArtistsOfSongsRequestItem
-> Optic' A_Lens NoIx InsertArtistsOfSongsRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsOfSongsRequestItem UUID
#songIdentifier,
        $sel:artistIdentifier:ArtistOfSong :: UUID
artistIdentifier = InsertArtistsOfSongsRequestItem
x InsertArtistsOfSongsRequestItem
-> Optic' A_Lens NoIx InsertArtistsOfSongsRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertArtistsOfSongsRequestItem UUID
#artistIdentifier,
        $sel:createdAt:ArtistOfSong :: UTCTime
createdAt = UTCTime
now,
        $sel:createdBy:ArtistOfSong :: UUID
createdBy = UUID
createdBy
      }

newSongContentFromRequest' :: (MonadIO m) => UUID -> InsertSongContentsRequestItem -> m SongContent
newSongContentFromRequest' :: forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongContentsRequestItem -> m SongContent
newSongContentFromRequest' UUID
createdBy InsertSongContentsRequestItem
x = do
  UUID
newUUID <- IO UUID -> m UUID
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UUID
nextRandom
  UTCTime
now <- IO UTCTime -> m UTCTime
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO IO UTCTime
getCurrentTime
  SongContent -> m SongContent
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure
    (SongContent -> m SongContent) -> SongContent -> m SongContent
forall a b. (a -> b) -> a -> b
$ SongContent
      { $sel:identifier:SongContent :: UUID
identifier = UUID
newUUID,
        $sel:songIdentifier:SongContent :: UUID
songIdentifier = InsertSongContentsRequestItem
x InsertSongContentsRequestItem
-> Optic' A_Lens NoIx InsertSongContentsRequestItem UUID -> UUID
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongContentsRequestItem UUID
#songIdentifier,
        $sel:versionName:SongContent :: Text
versionName = InsertSongContentsRequestItem
x InsertSongContentsRequestItem
-> Optic' A_Lens NoIx InsertSongContentsRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongContentsRequestItem Text
#versionName,
        $sel:visibilityStatus:SongContent :: Int
visibilityStatus = Int
0,
        $sel:approvedBy:SongContent :: Maybe UUID
approvedBy = Maybe UUID
forall a. Maybe a
Nothing,
        $sel:instrumentType:SongContent :: Text
instrumentType = InsertSongContentsRequestItem
x InsertSongContentsRequestItem
-> Optic' A_Lens NoIx InsertSongContentsRequestItem Text -> Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongContentsRequestItem Text
#instrumentType,
        $sel:asciiLegend:SongContent :: Maybe Text
asciiLegend = InsertSongContentsRequestItem
x InsertSongContentsRequestItem
-> Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
#asciiLegend,
        $sel:asciiContents:SongContent :: Maybe Text
asciiContents = InsertSongContentsRequestItem
x InsertSongContentsRequestItem
-> Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
#asciiContents,
        $sel:pdfContents:SongContent :: Maybe Text
pdfContents = InsertSongContentsRequestItem
x InsertSongContentsRequestItem
-> Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
#pdfContents,
        $sel:guitarProContents:SongContent :: Maybe Text
guitarProContents = InsertSongContentsRequestItem
x InsertSongContentsRequestItem
-> Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
-> Maybe Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic' A_Lens NoIx InsertSongContentsRequestItem (Maybe Text)
#guitarProContents,
        $sel:createdAt:SongContent :: UTCTime
createdAt = UTCTime
now,
        $sel:createdBy:SongContent :: UUID
createdBy = UUID
createdBy,
        $sel:lastEditedAt:SongContent :: Maybe UTCTime
lastEditedAt = Maybe UTCTime
forall a. Maybe a
Nothing
      }

deleteSongComments' :: (MonadIO m) => Env -> [UUID] -> m (Either SongCommandError ())
deleteSongComments' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
deleteSongComments' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite SongCommentT -> IO ())
-> SqlDelete Sqlite SongCommentT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongCommentT -> SqliteM ())
-> SqlDelete Sqlite SongCommentT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongCommentT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite SongCommentT -> m ())
-> SqlDelete Sqlite SongCommentT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongCommentT)
-> (forall s.
    (forall s'. SongCommentT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongCommentT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongCommentT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongCommentT)
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 SongCommentT))
#songComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. SongCommentT (QExpr Sqlite s')
c -> (SongCommentT (QGenExpr QValueContext Sqlite s)
forall s'. SongCommentT (QExpr Sqlite s')
c SongCommentT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongCommentT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongCommentT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SongCommandError () -> m (Either SongCommandError ()))
-> (() -> Either SongCommandError ())
-> ()
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either SongCommandError ()))
-> () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

deleteSongArtworks' :: (MonadIO m) => Env -> [UUID] -> m (Either SongCommandError ())
deleteSongArtworks' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
deleteSongArtworks' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite SongArtworkT -> IO ())
-> SqlDelete Sqlite SongArtworkT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongArtworkT -> SqliteM ())
-> SqlDelete Sqlite SongArtworkT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongArtworkT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite SongArtworkT -> m ())
-> SqlDelete Sqlite SongArtworkT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
-> (forall s.
    (forall s'. SongArtworkT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongArtworkT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
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 SongArtworkT))
#songArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. SongArtworkT (QExpr Sqlite s')
c -> (SongArtworkT (QGenExpr QValueContext Sqlite s)
forall s'. SongArtworkT (QExpr Sqlite s')
c SongArtworkT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongArtworkT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongArtworkT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SongCommandError () -> m (Either SongCommandError ()))
-> (() -> Either SongCommandError ())
-> ()
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either SongCommandError ()))
-> () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

deleteSongOpinions' :: (MonadIO m) => Env -> [UUID] -> m (Either SongCommandError ())
deleteSongOpinions' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
deleteSongOpinions' Env
env [UUID]
identifiers = do
  IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
    (IO () -> m ())
-> (SqlDelete Sqlite SongOpinionT -> IO ())
-> SqlDelete Sqlite SongOpinionT
-> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongOpinionT -> SqliteM ())
-> SqlDelete Sqlite SongOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongOpinionT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
    (SqlDelete Sqlite SongOpinionT -> m ())
-> SqlDelete Sqlite SongOpinionT -> m ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
-> (forall s.
    (forall s'. SongOpinionT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongOpinionT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
      ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
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 SongOpinionT))
#songOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      (\forall s'. SongOpinionT (QExpr Sqlite s')
c -> (SongOpinionT (QGenExpr QValueContext Sqlite s)
forall s'. SongOpinionT (QExpr Sqlite s')
c SongOpinionT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongOpinionT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongOpinionT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
  Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SongCommandError () -> m (Either SongCommandError ()))
-> (() -> Either SongCommandError ())
-> ()
-> m (Either SongCommandError ())
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> m (Either SongCommandError ()))
-> () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ ()

incrementViewsByOne' :: (MonadIO m) => Env -> [UUID] -> m (Either SongCommandError ())
incrementViewsByOne' :: forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
incrementViewsByOne' Env
env [UUID]
identifiers = do
  (UUID -> m ()) -> [UUID] -> m ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_ UUID -> m ()
doUpdate [UUID]
identifiers
  Either SongCommandError () -> m (Either SongCommandError ())
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure (Either SongCommandError () -> m (Either SongCommandError ()))
-> Either SongCommandError () -> m (Either SongCommandError ())
forall a b. (a -> b) -> a -> b
$ () -> Either SongCommandError ()
forall a b. b -> Either a b
Right ()
  where
    doUpdate :: UUID -> m ()
doUpdate UUID
x = do
      Maybe (SongT Identity)
ex <- IO (Maybe (SongT Identity)) -> m (Maybe (SongT Identity))
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO (Maybe (SongT Identity)) -> m (Maybe (SongT Identity)))
-> IO (Maybe (SongT Identity)) -> m (Maybe (SongT Identity))
forall a b. (a -> b) -> a -> b
$ (String -> IO ())
-> Connection
-> SqliteM (Maybe (SongT Identity))
-> IO (Maybe (SongT 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 (Maybe (SongT Identity)) -> IO (Maybe (SongT Identity)))
-> SqliteM (Maybe (SongT Identity)) -> IO (Maybe (SongT Identity))
forall a b. (a -> b) -> a -> b
$ do
        SqlSelect Sqlite (SongT Identity)
-> SqliteM (Maybe (SongT Identity))
forall be (m :: * -> *) a.
(MonadBeam be m, BeamSqlBackend be, FromBackendRow be a) =>
SqlSelect be a -> m (Maybe a)
runSelectReturningOne (SqlSelect Sqlite (SongT Identity)
 -> SqliteM (Maybe (SongT Identity)))
-> SqlSelect Sqlite (SongT Identity)
-> SqliteM (Maybe (SongT Identity))
forall a b. (a -> b) -> a -> b
$ Q Sqlite
  WikiMusicDatabase
  QBaseScope
  (SongT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (SongT (QExpr 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
   (SongT (QExpr Sqlite QBaseScope))
 -> SqlSelect
      Sqlite (QExprToIdentity (SongT (QExpr Sqlite QBaseScope))))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongT (QExpr Sqlite QBaseScope))
-> SqlSelect
     Sqlite (QExprToIdentity (SongT (QExpr Sqlite QBaseScope)))
forall a b. (a -> b) -> a -> b
$ do
          (SongT (QExpr Sqlite QBaseScope) -> QExpr Sqlite QBaseScope Bool)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongT (QExpr 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_
            (\SongT (QExpr Sqlite QBaseScope)
s -> (SongT (QExpr Sqlite QBaseScope)
s SongT (QExpr Sqlite QBaseScope)
-> Optic'
     A_Lens
     NoIx
     (SongT (QExpr 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
  (SongT (QExpr 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. SqlEq expr a => a -> a -> expr Bool
==. (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 -> QGenExpr QValueContext Sqlite QBaseScope Text)
-> UUID -> QGenExpr QValueContext Sqlite QBaseScope Text
forall a b. (a -> b) -> a -> b
$ UUID
x))
            (Q Sqlite
   WikiMusicDatabase
   QBaseScope
   (SongT (QExpr Sqlite QBaseScope))
 -> Q Sqlite
      WikiMusicDatabase
      QBaseScope
      (SongT (QExpr Sqlite QBaseScope)))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongT (QExpr Sqlite QBaseScope))
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongT (QExpr Sqlite QBaseScope))
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
-> Q Sqlite
     WikiMusicDatabase
     QBaseScope
     (SongT (QExpr 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 SongT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
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 SongT))
#songs) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
      case Maybe (SongT Identity)
ex of
        Maybe (SongT Identity)
Nothing -> () -> m ()
forall a. a -> m a
forall (f :: * -> *) a. Applicative f => a -> f a
pure ()
        Just SongT Identity
foundEx -> do
          let a :: SongT Identity
a =
                SongT Identity
foundEx
                  { viewCount = (foundEx ^. #viewCount) + 1
                  } ::
                  Song'
          IO () -> m ()
forall a. IO a -> m a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ())
-> (SongT Identity -> IO ()) -> SongT Identity -> m ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SongT Identity -> SqliteM ()) -> SongT Identity -> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlUpdate Sqlite SongT -> SqliteM ()
forall be (m :: * -> *) (tbl :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlUpdate be tbl -> m ()
runUpdate (SqlUpdate Sqlite SongT -> SqliteM ())
-> (SongT Identity -> SqlUpdate Sqlite SongT)
-> SongT Identity
-> SqliteM ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
-> SongT Identity -> SqlUpdate Sqlite SongT
forall (table :: (* -> *) -> *) be (db :: (* -> *) -> *).
(Table table, BeamSqlBackend be,
 SqlValableTable be (PrimaryKey table), SqlValableTable be table,
 HasTableEquality be (PrimaryKey table)) =>
DatabaseEntity be db (TableEntity table)
-> table Identity -> SqlUpdate be table
save ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT))
-> DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongT)
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 SongT))
#songs) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (SongT Identity -> m ()) -> SongT Identity -> m ()
forall a b. (a -> b) -> a -> b
$ SongT Identity
a

instance Exec SongCommand where
  execAlgebra :: forall a. SongCommand (IO a) -> IO a
execAlgebra (IncrementViewsByOne Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) =
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> IO (Either SongCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
incrementViewsByOne' Env
env [UUID]
identifiers
  execAlgebra (InsertSongs Env
env [Song]
songs Map UUID Song -> IO a
next) =
    Map UUID Song -> IO a
next (Map UUID Song -> IO a) -> IO (Map UUID Song) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [Song] -> IO (Map UUID Song)
forall (m :: * -> *).
MonadIO m =>
Env -> [Song] -> m (Map UUID Song)
insertSongs' Env
env [Song]
songs
  execAlgebra (InsertSongComments Env
env [SongComment]
comments Either SongCommandError () -> IO a
next) =
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> IO (Either SongCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [SongComment] -> IO (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [SongComment] -> m (Either SongCommandError ())
insertSongComments' Env
env [SongComment]
comments
  execAlgebra (InsertSongExternalSources Env
env [SongExternalSources]
externalSources Map UUID SongExternalSources -> IO a
next) =
    Map UUID SongExternalSources -> IO a
next (Map UUID SongExternalSources -> IO a)
-> IO (Map UUID SongExternalSources) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [SongExternalSources] -> IO (Map UUID SongExternalSources)
forall (m :: * -> *).
MonadIO m =>
Env -> [SongExternalSources] -> m (Map UUID SongExternalSources)
insertSongExternalSources' Env
env [SongExternalSources]
externalSources
  execAlgebra (InsertSongArtworks Env
env [SongArtwork]
artworks Map UUID SongArtwork -> IO a
next) =
    Map UUID SongArtwork -> IO a
next (Map UUID SongArtwork -> IO a) -> IO (Map UUID SongArtwork) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [SongArtwork] -> IO (Map UUID SongArtwork)
forall (m :: * -> *).
MonadIO m =>
Env -> [SongArtwork] -> m (Map UUID SongArtwork)
insertSongArtworks' Env
env [SongArtwork]
artworks
  execAlgebra (UpsertSongOpinions Env
env [SongOpinion]
opinions Map UUID SongOpinion -> IO a
next) =
    Map UUID SongOpinion -> IO a
next (Map UUID SongOpinion -> IO a) -> IO (Map UUID SongOpinion) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [SongOpinion] -> IO (Map UUID SongOpinion)
forall (m :: * -> *).
MonadIO m =>
Env -> [SongOpinion] -> m (Map UUID SongOpinion)
upsertSongOpinions' Env
env [SongOpinion]
opinions
  execAlgebra (DeleteSongs Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) =
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> IO (Either SongCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
uberDeleteSongs' Env
env [UUID]
identifiers
  execAlgebra (DeleteSongComments Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> IO (Either SongCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
deleteSongComments' Env
env [UUID]
identifiers
  execAlgebra (DeleteSongArtworks Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> IO (Either SongCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
deleteSongArtworks' Env
env [UUID]
identifiers
  execAlgebra (DeleteSongOpinions Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> IO (Either SongCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [UUID] -> IO (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> [UUID] -> m (Either SongCommandError ())
deleteSongOpinions' Env
env [UUID]
identifiers
  execAlgebra (DeleteCommentsOfSongs Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    let ids :: [Text]
ids = (UUID -> Text) -> [UUID] -> [Text]
forall a b. (a -> b) -> [a] -> [b]
map UUID -> Text
UUID.toText [UUID]
identifiers

    (Text -> IO ()) -> [Text] -> IO ()
forall (t :: * -> *) (m :: * -> *) a b.
(Foldable t, Monad m) =>
(a -> m b) -> t a -> m ()
mapM_
      ( \Text
y ->
          (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongCommentT -> SqliteM ())
-> SqlDelete Sqlite SongCommentT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongCommentT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
            (SqlDelete Sqlite SongCommentT -> IO ())
-> SqlDelete Sqlite SongCommentT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongCommentT)
-> (forall s.
    (forall s'. SongCommentT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongCommentT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongCommentT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongCommentT)
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 SongCommentT))
#songComments) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase) (\forall s'. SongCommentT (QExpr Sqlite s')
c -> SongCommentT (QGenExpr QValueContext Sqlite s)
forall s'. SongCommentT (QExpr Sqlite s')
c SongCommentT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongCommentT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongCommentT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
#songIdentifier PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlEq expr a => a -> a -> expr Bool
==. (PrimaryKey SongT Identity
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey SongT Identity
 -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> (Text -> PrimaryKey SongT Identity)
-> Text
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey SongT Identity
Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Text -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> Text -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a b. (a -> b) -> a -> b
$ Text
y))
      )
      [Text]
ids

    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> Either SongCommandError () -> IO a
forall a b. (a -> b) -> a -> b
$ () -> Either SongCommandError ()
forall a b. b -> Either a b
Right ()
  execAlgebra (DeleteSongExternalSources Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite SongExternalSourcesT -> IO ())
-> SqlDelete Sqlite SongExternalSourcesT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongExternalSourcesT -> SqliteM ())
-> SqlDelete Sqlite SongExternalSourcesT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongExternalSourcesT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite SongExternalSourcesT -> IO ())
-> SqlDelete Sqlite SongExternalSourcesT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity
  Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
-> (forall s.
    (forall s'. SongExternalSourcesT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongExternalSourcesT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongExternalSourcesT)
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 SongExternalSourcesT))
#songExternalSources) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. SongExternalSourcesT (QExpr Sqlite s')
c -> (SongExternalSourcesT (QGenExpr QValueContext Sqlite s)
forall s'. SongExternalSourcesT (QExpr Sqlite s')
c SongExternalSourcesT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongExternalSourcesT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongExternalSourcesT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
#songIdentifier) PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey SongT Identity
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey SongT Identity
 -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey SongT Identity)
-> UUID
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey SongT Identity
Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Text -> PrimaryKey SongT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey SongT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> (() -> Either SongCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (DeleteArtworksOfSongs Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite SongArtworkT -> IO ())
-> SqlDelete Sqlite SongArtworkT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongArtworkT -> SqliteM ())
-> SqlDelete Sqlite SongArtworkT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongArtworkT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite SongArtworkT -> IO ())
-> SqlDelete Sqlite SongArtworkT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
-> (forall s.
    (forall s'. SongArtworkT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongArtworkT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongArtworkT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtworkT)
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 SongArtworkT))
#songArtworks) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. SongArtworkT (QExpr Sqlite s')
c -> (SongArtworkT (QGenExpr QValueContext Sqlite s)
forall s'. SongArtworkT (QExpr Sqlite s')
c SongArtworkT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongArtworkT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongArtworkT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
#songIdentifier) PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey SongT Identity
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey SongT Identity
 -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey SongT Identity)
-> UUID
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey SongT Identity
Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Text -> PrimaryKey SongT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey SongT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> (() -> Either SongCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (DeleteOpinionsOfSongs Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite SongOpinionT -> IO ())
-> SqlDelete Sqlite SongOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongOpinionT -> SqliteM ())
-> SqlDelete Sqlite SongOpinionT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongOpinionT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite SongOpinionT -> IO ())
-> SqlDelete Sqlite SongOpinionT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
-> (forall s.
    (forall s'. SongOpinionT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongOpinionT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongOpinionT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongOpinionT)
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 SongOpinionT))
#songOpinions) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. SongOpinionT (QExpr Sqlite s')
c -> (SongOpinionT (QGenExpr QValueContext Sqlite s)
forall s'. SongOpinionT (QExpr Sqlite s')
c SongOpinionT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongOpinionT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongOpinionT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
#songIdentifier) PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey SongT Identity
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey SongT Identity
 -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey SongT Identity)
-> UUID
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey SongT Identity
Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Text -> PrimaryKey SongT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey SongT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> (() -> Either SongCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (UpdateSongArtworkOrder Env
env [SongArtworkOrderUpdate]
orderUpdates Either Text () -> IO a
next) =
    Either Text () -> IO a
next (Either Text () -> IO a) -> IO (Either Text ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [SongArtworkOrderUpdate] -> IO (Either Text ())
forall (m :: * -> *) a.
MonadIO m =>
Env -> [SongArtworkOrderUpdate] -> m (Either a ())
updateSongArtworkOrder' Env
env [SongArtworkOrderUpdate]
orderUpdates
  execAlgebra (UpdateSongs Env
env Map UUID (Song, Maybe SongDelta)
deltas Either Text () -> IO a
next) =
    Either Text () -> IO a
next (Either Text () -> IO a) -> IO (Either Text ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> Map UUID (Song, Maybe SongDelta) -> IO (Either Text ())
forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Song, Maybe SongDelta) -> m (Either Text ())
updateSongs' Env
env Map UUID (Song, Maybe SongDelta)
deltas
  execAlgebra (UpdateSongContents Env
env [SongContentDelta]
deltas Either Text () -> IO a
next) =
    Either Text () -> IO a
next (Either Text () -> IO a) -> IO (Either Text ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [SongContentDelta] -> IO (Either Text ())
forall (m :: * -> *).
MonadIO m =>
Env -> [SongContentDelta] -> m (Either Text ())
updateSongContents' Env
env [SongContentDelta]
deltas
  execAlgebra (UpdateSongExternalSources Env
env Map UUID (Song, Maybe SongDelta)
deltas Either Text () -> IO a
next) =
    Either Text () -> IO a
next (Either Text () -> IO a) -> IO (Either Text ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> Map UUID (Song, Maybe SongDelta) -> IO (Either Text ())
forall (m :: * -> *).
MonadIO m =>
Env -> Map UUID (Song, Maybe SongDelta) -> m (Either Text ())
updateSongExternalSources' Env
env Map UUID (Song, Maybe SongDelta)
deltas
  execAlgebra (NewSongCommentFromRequest UUID
createdBy InsertSongCommentsRequestItem
req SongComment -> IO a
next) =
    SongComment -> IO a
next (SongComment -> IO a) -> IO SongComment -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertSongCommentsRequestItem -> IO SongComment
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongCommentsRequestItem -> m SongComment
newSongCommentFromRequest' UUID
createdBy InsertSongCommentsRequestItem
req
  execAlgebra (NewSongOpinionFromRequest UUID
createdBy UpsertSongOpinionsRequestItem
req SongOpinion -> IO a
next) =
    SongOpinion -> IO a
next (SongOpinion -> IO a) -> IO SongOpinion -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> UpsertSongOpinionsRequestItem -> IO SongOpinion
forall (m :: * -> *).
MonadIO m =>
UUID -> UpsertSongOpinionsRequestItem -> m SongOpinion
newSongOpinionFromRequest' UUID
createdBy UpsertSongOpinionsRequestItem
req
  execAlgebra (NewSongArtworkFromRequest UUID
createdBy InsertSongArtworksRequestItem
req SongArtwork -> IO a
next) =
    SongArtwork -> IO a
next (SongArtwork -> IO a) -> IO SongArtwork -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertSongArtworksRequestItem -> IO SongArtwork
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongArtworksRequestItem -> m SongArtwork
newSongArtworkFromRequest' UUID
createdBy InsertSongArtworksRequestItem
req
  execAlgebra (InsertSongContents Env
env [SongContent]
contents Map UUID SongContent -> IO a
next) =
    Map UUID SongContent -> IO a
next (Map UUID SongContent -> IO a) -> IO (Map UUID SongContent) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [SongContent] -> IO (Map UUID SongContent)
forall (m :: * -> *).
MonadIO m =>
Env -> [SongContent] -> m (Map UUID SongContent)
insertSongContents' Env
env [SongContent]
contents
  execAlgebra (InsertArtistsOfSongs Env
env [ArtistOfSong]
items Map UUID ArtistOfSong -> IO a
next) =
    Map UUID ArtistOfSong -> IO a
next (Map UUID ArtistOfSong -> IO a)
-> IO (Map UUID ArtistOfSong) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> [ArtistOfSong] -> IO (Map UUID ArtistOfSong)
forall (m :: * -> *).
MonadIO m =>
Env -> [ArtistOfSong] -> m (Map UUID ArtistOfSong)
insertArtistsOfSongs' Env
env [ArtistOfSong]
items
  execAlgebra (DeleteArtistsOfSongs Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite SongArtistT -> IO ())
-> SqlDelete Sqlite SongArtistT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongArtistT -> SqliteM ())
-> SqlDelete Sqlite SongArtistT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongArtistT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite SongArtistT -> IO ())
-> SqlDelete Sqlite SongArtistT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtistT)
-> (forall s.
    (forall s'. SongArtistT (QExpr Sqlite s')) -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongArtistT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongArtistT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongArtistT)
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 SongArtistT))
#songArtists) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. SongArtistT (QExpr Sqlite s')
c -> (SongArtistT (QGenExpr QValueContext Sqlite s)
forall s'. SongArtistT (QExpr Sqlite s')
c SongArtistT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongArtistT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongArtistT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
#songIdentifier) PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey SongT Identity
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey SongT Identity
 -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey SongT Identity)
-> UUID
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey SongT Identity
Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Text -> PrimaryKey SongT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey SongT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)

    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> (() -> Either SongCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (DeleteArtistOfSong Env
env (UUID, UUID)
identifiers Either SongCommandError () -> IO a
next) =
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> IO (Either SongCommandError ()) -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< Env -> (UUID, UUID) -> IO (Either SongCommandError ())
forall (m :: * -> *).
MonadIO m =>
Env -> (UUID, UUID) -> m (Either SongCommandError ())
deleteArtistOfSong' Env
env (UUID, UUID)
identifiers
  execAlgebra (NewSongFromRequest UUID
createdBy InsertSongsRequestItem
song Song -> IO a
next) =
    Song -> IO a
next (Song -> IO a) -> IO Song -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertSongsRequestItem -> IO Song
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongsRequestItem -> m Song
newSongFromRequest' UUID
createdBy InsertSongsRequestItem
song
  execAlgebra (NewArtistOfSongFromRequest UUID
createdBy InsertArtistsOfSongsRequestItem
x ArtistOfSong -> IO a
next) =
    ArtistOfSong -> IO a
next (ArtistOfSong -> IO a) -> IO ArtistOfSong -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertArtistsOfSongsRequestItem -> IO ArtistOfSong
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertArtistsOfSongsRequestItem -> m ArtistOfSong
newArtistOfSongFromRequest' UUID
createdBy InsertArtistsOfSongsRequestItem
x
  execAlgebra (NewSongContentFromRequest UUID
createdBy InsertSongContentsRequestItem
x SongContent -> IO a
next) =
    SongContent -> IO a
next (SongContent -> IO a) -> IO SongContent -> IO a
forall (m :: * -> *) a b. Monad m => (a -> m b) -> m a -> m b
=<< UUID -> InsertSongContentsRequestItem -> IO SongContent
forall (m :: * -> *).
MonadIO m =>
UUID -> InsertSongContentsRequestItem -> m SongContent
newSongContentFromRequest' UUID
createdBy InsertSongContentsRequestItem
x
  execAlgebra (DeleteContentsOfSongs Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite SongContentsT -> IO ())
-> SqlDelete Sqlite SongContentsT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongContentsT -> SqliteM ())
-> SqlDelete Sqlite SongContentsT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongContentsT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite SongContentsT -> IO ())
-> SqlDelete Sqlite SongContentsT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongContentsT)
-> (forall s.
    (forall s'. SongContentsT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongContentsT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongContentsT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongContentsT)
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 SongContentsT))
#songContents) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. SongContentsT (QExpr Sqlite s')
c -> (SongContentsT (QGenExpr QValueContext Sqlite s)
forall s'. SongContentsT (QExpr Sqlite s')
c SongContentsT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongContentsT (QGenExpr QValueContext Sqlite s))
     (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongContentsT (QGenExpr QValueContext Sqlite s))
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
#songIdentifier) PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
-> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
-> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> [UUID] -> [PrimaryKey SongT (QGenExpr QValueContext Sqlite s)]
forall a b. (a -> b) -> [a] -> [b]
map (PrimaryKey SongT Identity
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
HaskellLiteralForQExpr
  (PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (PrimaryKey SongT Identity
 -> PrimaryKey SongT (QGenExpr QValueContext Sqlite s))
-> (UUID -> PrimaryKey SongT Identity)
-> UUID
-> PrimaryKey SongT (QGenExpr QValueContext Sqlite s)
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Text -> PrimaryKey SongT Identity
Columnar Identity Text -> PrimaryKey SongT Identity
forall (f :: * -> *). Columnar f Text -> PrimaryKey SongT f
SongId (Text -> PrimaryKey SongT Identity)
-> (UUID -> Text) -> UUID -> PrimaryKey SongT Identity
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> (() -> Either SongCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()
  execAlgebra (DeleteSongContents Env
env [UUID]
identifiers Either SongCommandError () -> IO a
next) = do
    IO () -> IO ()
forall a. IO a -> IO a
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO
      (IO () -> IO ())
-> (SqlDelete Sqlite SongContentsT -> IO ())
-> SqlDelete Sqlite SongContentsT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (String -> IO ()) -> Connection -> SqliteM () -> IO ()
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 () -> IO ())
-> (SqlDelete Sqlite SongContentsT -> SqliteM ())
-> SqlDelete Sqlite SongContentsT
-> IO ()
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SqlDelete Sqlite SongContentsT -> SqliteM ()
forall be (m :: * -> *) (table :: (* -> *) -> *).
(BeamSqlBackend be, MonadBeam be m) =>
SqlDelete be table -> m ()
runDelete
      (SqlDelete Sqlite SongContentsT -> IO ())
-> SqlDelete Sqlite SongContentsT -> IO ()
forall a b. (a -> b) -> a -> b
$ DatabaseEntity Sqlite WikiMusicDatabase (TableEntity SongContentsT)
-> (forall s.
    (forall s'. SongContentsT (QExpr Sqlite s'))
    -> QExpr Sqlite s Bool)
-> SqlDelete Sqlite SongContentsT
forall be (db :: (* -> *) -> *) (table :: (* -> *) -> *).
BeamSqlBackend be =>
DatabaseEntity be db (TableEntity table)
-> (forall s. (forall s'. table (QExpr be s')) -> QExpr be s Bool)
-> SqlDelete be table
delete
        ((DatabaseSettings Sqlite WikiMusicDatabase
-> Optic'
     A_Lens
     NoIx
     (DatabaseSettings Sqlite WikiMusicDatabase)
     (DatabaseEntity
        Sqlite WikiMusicDatabase (TableEntity SongContentsT))
-> DatabaseEntity
     Sqlite WikiMusicDatabase (TableEntity SongContentsT)
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 SongContentsT))
#songContents) DatabaseSettings Sqlite WikiMusicDatabase
forall be. DatabaseSettings be WikiMusicDatabase
wikiMusicDatabase)
        (\forall s'. SongContentsT (QExpr Sqlite s')
c -> (SongContentsT (QGenExpr QValueContext Sqlite s)
forall s'. SongContentsT (QExpr Sqlite s')
c SongContentsT (QGenExpr QValueContext Sqlite s)
-> Optic'
     A_Lens
     NoIx
     (SongContentsT (QGenExpr QValueContext Sqlite s))
     (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall k s (is :: IxList) a.
Is k A_Getter =>
s -> Optic' k is s a -> a
^. Optic'
  A_Lens
  NoIx
  (SongContentsT (QGenExpr QValueContext Sqlite s))
  (QGenExpr QValueContext Sqlite s Text)
#identifier) QGenExpr QValueContext Sqlite s Text
-> [QGenExpr QValueContext Sqlite s Text] -> QExpr Sqlite s Bool
forall (expr :: * -> *) a. SqlIn expr a => a -> [a] -> expr Bool
`in_` (UUID -> QGenExpr QValueContext Sqlite s Text)
-> [UUID] -> [QGenExpr QValueContext Sqlite s Text]
forall a b. (a -> b) -> [a] -> [b]
map (Text -> QGenExpr QValueContext Sqlite s Text
HaskellLiteralForQExpr (QGenExpr QValueContext Sqlite s Text)
-> QGenExpr QValueContext Sqlite s Text
forall a. SqlValable a => HaskellLiteralForQExpr a -> a
val_ (Text -> QGenExpr QValueContext Sqlite s Text)
-> (UUID -> Text) -> UUID -> QGenExpr QValueContext Sqlite s Text
forall b c a. (b -> c) -> (a -> b) -> a -> c
. UUID -> Text
UUID.toText) [UUID]
identifiers)
    Either SongCommandError () -> IO a
next (Either SongCommandError () -> IO a)
-> (() -> Either SongCommandError ()) -> () -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. () -> Either SongCommandError ()
forall a b. b -> Either a b
Right (() -> IO a) -> () -> IO a
forall a b. (a -> b) -> a -> b
$ ()