2 Module : Gargantext.Database.Queries.Join
3 Description : Main requests of Node to the database
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 {-# OPTIONS_GHC -fno-warn-orphans #-}
12 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE FlexibleInstances #-}
18 {-# LANGUAGE FunctionalDependencies #-}
19 {-# LANGUAGE MultiParamTypeClasses #-}
20 {-# LANGUAGE QuasiQuotes #-}
21 {-# LANGUAGE NoImplicitPrelude #-}
22 {-# LANGUAGE NoMonomorphismRestriction #-}
23 {-# LANGUAGE OverloadedStrings #-}
24 {-# LANGUAGE TemplateHaskell #-}
25 ------------------------------------------------------------------------
26 module Gargantext.Database.Queries.Join
28 ------------------------------------------------------------------------
30 import Control.Applicative ((<*>))
31 import Control.Arrow ((>>>))
32 import Data.Profunctor.Product.Default
33 import Gargantext.Database.Schema.Ngrams
34 import Gargantext.Database.Schema.Node
35 import Gargantext.Database.Schema.NodeNode
36 import Gargantext.Prelude
38 import Opaleye.Internal.Join (NullMaker(..))
39 import qualified Opaleye.Internal.Unpackspec()
42 --leftJoin3 :: Query columnsL1 -> Query columnsR -> Query columnsL
43 -- -> ((columnsL1, columnsR) -> Column PGBool)
44 -- -> ((columnsL, (columnsL1, nullableColumnsR1)) -> Column PGBool)
45 -- -> Query (columnsL, nullableColumnsR)
46 --leftJoin3 q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q1 q2 cond12) cond23
47 join3 :: Query columnsA -> Query columnsB -> Query columnsC
48 -> ((columnsA, columnsB, columnsC) -> Column PGBool)
49 -> Query (columnsA, columnsB, columnsC)
50 join3 q1 q2 q3 cond = ((,,) <$> q1 <*> q2 <*> q3) >>> keepWhen cond
52 ------------------------------------------------------------------------
54 leftJoin3Ex :: Query (NodeRead, (NodeNodeReadNull, NodeReadNull))
55 leftJoin3Ex = leftJoin3 queryNodeNodeTable queryNodeTable queryNodeTable cond12 cond23
58 cond23 :: (NodeRead, (NodeNodeRead, NodeReadNull)) -> Column PGBool
62 leftJoin3 :: ( Default Unpackspec columnsL1 columnsL1
63 , Default Unpackspec columnsL2 columnsL2
64 , Default Unpackspec columnsL3 columnsL3
66 , Default Unpackspec nullableColumnsL2 nullableColumnsL2
68 , Default NullMaker columnsL2 nullableColumnsL2
69 , Default NullMaker (columnsL1, nullableColumnsL2) nullableColumnsL3
72 Query columnsL1 -> Query columnsL2 -> Query columnsL3
73 -> ((columnsL1, columnsL2) -> Column PGBool)
74 -> ((columnsL3, (columnsL1, nullableColumnsL2)) -> Column PGBool)
75 -> Query (columnsL3, nullableColumnsL3)
76 leftJoin3 q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q1 q2 cond12) cond23
80 :: (Default Unpackspec fieldsL1 fieldsL1,
81 Default Unpackspec fieldsL2 fieldsL2,
82 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
83 Default Unpackspec fieldsR fieldsR,
84 Default NullMaker fieldsR nullableFieldsR1,
85 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR2) =>
86 Opaleye.Select fieldsR
87 -> Opaleye.Select fieldsL2
88 -> Opaleye.Select fieldsL1
89 -> ((fieldsL2, fieldsR) -> Column PGBool)
90 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
91 -> Opaleye.Select (fieldsL1, nullableFieldsR2)
92 leftJoin3' q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q2 q1 cond12) cond23
95 leftJoin4' :: Query (NodeRead, (NodeReadNull, (NgramsReadNull, NodeReadNull)))
96 leftJoin4' = leftJoin4 queryNgramsTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34
98 cond12 :: (NgramsRead, NodeRead) -> Column PGBool
101 cond23 :: (NodeRead, (NgramsRead, NodeReadNull)) -> Column PGBool
104 cond34 :: (NodeRead, (NodeRead, (NgramsReadNull, NodeReadNull))) -> Column PGBool
108 rightJoin4' :: Query (((NodeReadNull, NodeReadNull), NodeReadNull), NodeRead)
109 rightJoin4' = rightJoin4 queryNodeTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34
111 cond12 :: (NodeRead, NodeRead) -> Column PGBool
114 cond23 :: ((NodeReadNull, NodeRead), NodeRead) -> Column PGBool
117 cond34 :: (((NodeReadNull, NodeReadNull), NodeRead), NodeRead) -> Column PGBool
124 :: (Default Unpackspec fieldsL1 fieldsL1,
125 Default Unpackspec fieldsL2 fieldsL2,
126 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
127 Default Unpackspec fieldsL3 fieldsL3,
128 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
129 Default Unpackspec fieldsR fieldsR,
130 Default NullMaker fieldsR nullableFieldsR2,
131 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR3,
132 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1) =>
133 Opaleye.Select fieldsL3
134 -> Opaleye.Select fieldsR
135 -> Opaleye.Select fieldsL2
136 -> Opaleye.Select fieldsL1
137 -> ((fieldsL3, fieldsR) -> Column PGBool)
138 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
139 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
140 -> Opaleye.Select (fieldsL1, nullableFieldsR3)
141 leftJoin4 q1 q2 q3 q4 cond12 cond23 cond34 = leftJoin q4 (leftJoin q3 (leftJoin q1 q2 cond12) cond23) cond34
144 -- rightJoin4 q1 q2 q3 q4 cond12 cond23 cond34 = rightJoin q4 (rightJoin q3 (rightJoin q1 q2 cond12) cond23) cond34
147 leftJoin5' :: Query (NodeRead, (NodeReadNull, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull))))
148 leftJoin5' = leftJoin5 queryNodeSearchTable queryNodeNodeTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34 cond45
150 cond12 :: (NodeNodeRead, NodeSearchRead) -> Column PGBool
153 cond23 :: (NodeRead, (NodeNodeRead, NodeSearchReadNull)) -> Column PGBool
156 cond34 :: (NodeRead, (NodeRead, (NodeNodeReadNull, NodeSearchReadNull))) -> Column PGBool
159 cond45 :: (NodeRead, (NodeRead, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull)))) -> Column PGBool
163 leftJoin5 :: ( Default Unpackspec fieldsL1 fieldsL1,
164 Default Unpackspec fieldsL2 fieldsL2,
165 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
166 Default Unpackspec fieldsL3 fieldsL3,
167 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
168 Default Unpackspec fieldsL4 fieldsL4,
169 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
170 Default Unpackspec fieldsR fieldsR,
171 Default NullMaker fieldsR nullableFieldsR3,
172 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR4,
173 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
174 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2) =>
180 -> ((fieldsL4, fieldsR) -> Column PGBool)
181 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
182 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
183 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
184 -> Query (fieldsL1, nullableFieldsR4)
185 leftJoin5 q1 q2 q3 q4 q5 cond12 cond23 cond34 cond45 = leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45
188 leftJoin6 :: ( Default Unpackspec fieldsL1 fieldsL1,
189 Default Unpackspec fieldsL2 fieldsL2,
190 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
191 Default Unpackspec fieldsL3 fieldsL3,
192 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
193 Default Unpackspec fieldsL4 fieldsL4,
194 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
195 Default Unpackspec fieldsL5 fieldsL5,
196 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
197 Default Unpackspec fieldsR fieldsR,
198 Default NullMaker fieldsR nullableFieldsR4,
199 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR5,
200 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
201 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
202 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3) =>
208 -> Query fieldsL1 -> ((fieldsL5, fieldsR) -> Column PGBool)
209 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
210 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
211 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
212 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
213 -> Query (fieldsL1, nullableFieldsR5)
214 leftJoin6 q1 q2 q3 q4 q5 q6 cond12 cond23 cond34 cond45 cond56 =
215 leftJoin q6 (leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45) cond56
218 leftJoin6' :: Query (NodeRead, (NodeReadNull, (NodeReadNull, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull)))))
219 leftJoin6' = leftJoin6 queryNodeSearchTable queryNodeNodeTable queryNodeTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34 cond45 cond56
221 cond12 :: (NodeNodeRead, NodeSearchRead) -> Column PGBool
224 cond23 :: (NodeRead, (NodeNodeRead, NodeSearchReadNull)) -> Column PGBool
227 cond34 :: (NodeRead, (NodeRead, (NodeNodeReadNull, NodeSearchReadNull))) -> Column PGBool
230 cond45 :: (NodeRead, (NodeRead, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull)))) -> Column PGBool
233 cond56 :: (NodeRead, (NodeRead, (NodeReadNull, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull))))) -> Column PGBool