1 {-# LANGUAGE TemplateHaskell, OverloadedStrings #-} 2 module Databrary.Model.Container.SQL 3 ( selectContainerRow 4 , selectVolumeContainer 5 , selectContainer 6 -- for expanded query 7 , setContainerId 8 ) where 9 10 import qualified Language.Haskell.TH as TH 11 12 import Databrary.Model.SQL.Select 13 import Databrary.Model.Id.Types 14 import Databrary.Model.Volume.SQL 15 import Databrary.Model.Release.SQL 16 import Databrary.Model.Container.Types 17 18 selectContainerRow :: Selector -- ^ @'ContainerRow'@ 19 selectContainerRow = selectColumns 'ContainerRow "container" ["id", "top", "name", "date"] 20 21 selectVolumeContainer :: Selector -- ^ @'Volume' -> 'Container'@ 22 selectVolumeContainer = selectJoin 'Container 23 [ selectContainerRow 24 , maybeJoinOn "container.id = slot_release.container AND slot_release.segment = '(,)'" 25 releaseRow 26 ] 27 28 selectContainer :: TH.Name -- ^ @'Identity'@ 29 -> Selector -- ^ @'Container'@ 30 selectContainer ident = selectJoin '($) 31 [ selectVolumeContainer 32 , joinOn "container.volume = volume.id" $ selectVolume ident 33 ] 34 35 setContainerId :: Container -> Id Container -> Container 36 setContainerId o i = o{ containerRow = (containerRow o) { containerId = i } }