2 Module : Gargantext.Database.Query.Join
3 Description : Main Join queries (using Opaleye)
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
10 Multiple Join functions with Opaleye.
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
15 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
17 {-# LANGUAGE Arrows #-}
18 {-# LANGUAGE DeriveGeneric #-}
19 {-# LANGUAGE FlexibleContexts #-}
20 {-# LANGUAGE FlexibleInstances #-}
21 {-# LANGUAGE FunctionalDependencies #-}
22 {-# LANGUAGE MultiParamTypeClasses #-}
23 {-# LANGUAGE QuasiQuotes #-}
24 {-# LANGUAGE NoImplicitPrelude #-}
25 {-# LANGUAGE NoMonomorphismRestriction #-}
26 {-# LANGUAGE OverloadedStrings #-}
27 {-# LANGUAGE TemplateHaskell #-}
29 ------------------------------------------------------------------------
31 module Gargantext.Database.Action.Query.Join
34 import Control.Applicative ((<*>))
35 import Control.Arrow ((>>>))
36 import Data.Profunctor.Product.Default
37 import Gargantext.Prelude
39 import Opaleye.Internal.Join (NullMaker(..))
40 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 :: (Default Unpackspec fieldsL1 fieldsL1,
55 Default Unpackspec fieldsL2 fieldsL2,
56 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
57 Default Unpackspec fieldsR fieldsR,
58 Default NullMaker fieldsR nullableFieldsR1,
59 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR2) =>
60 Opaleye.Select fieldsR
61 -> Opaleye.Select fieldsL2
62 -> Opaleye.Select fieldsL1
63 -> ((fieldsL2, fieldsR) -> Column PGBool)
64 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
65 -> Opaleye.Select (fieldsL1, nullableFieldsR2)
68 leftJoin q3 ( leftJoin q2 q1 cond12) cond23
72 :: (Default Unpackspec fieldsL1 fieldsL1,
73 Default Unpackspec fieldsL2 fieldsL2,
74 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
75 Default Unpackspec fieldsL3 fieldsL3,
76 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
77 Default Unpackspec fieldsR fieldsR,
78 Default NullMaker fieldsR nullableFieldsR2,
79 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR3,
80 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1) =>
81 Opaleye.Select fieldsR
82 -> Opaleye.Select fieldsL3
83 -> Opaleye.Select fieldsL2
84 -> Opaleye.Select fieldsL1
85 -> ((fieldsL3, fieldsR) -> Column PGBool)
86 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
87 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
88 -> Opaleye.Select (fieldsL1, nullableFieldsR3)
90 cond12 cond23 cond34 =
91 leftJoin q4 ( leftJoin q3
98 leftJoin5 :: ( Default Unpackspec fieldsL1 fieldsL1,
99 Default Unpackspec fieldsL2 fieldsL2,
100 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
101 Default Unpackspec fieldsL3 fieldsL3,
102 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
103 Default Unpackspec fieldsL4 fieldsL4,
104 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
105 Default Unpackspec fieldsR fieldsR,
106 Default NullMaker fieldsR nullableFieldsR3,
107 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR4,
108 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
109 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2) =>
115 -> ((fieldsL4, fieldsR) -> Column PGBool)
116 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
117 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
118 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
119 -> Query (fieldsL1, nullableFieldsR4)
120 leftJoin5 q1 q2 q3 q4 q5
121 cond12 cond23 cond34 cond45 =
122 leftJoin q5 ( leftJoin q4
131 leftJoin6 :: ( Default Unpackspec fieldsL1 fieldsL1,
132 Default Unpackspec fieldsL2 fieldsL2,
133 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
134 Default Unpackspec fieldsL3 fieldsL3,
135 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
136 Default Unpackspec fieldsL4 fieldsL4,
137 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
138 Default Unpackspec fieldsL5 fieldsL5,
139 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
140 Default Unpackspec fieldsR fieldsR,
141 Default NullMaker fieldsR nullableFieldsR4,
142 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR5,
143 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
144 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
145 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3) =>
151 -> Query fieldsL1 -> ((fieldsL5, fieldsR) -> Column PGBool)
152 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
153 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
154 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
155 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
156 -> Query (fieldsL1, nullableFieldsR5)
157 leftJoin6 q1 q2 q3 q4 q5 q6
158 cond12 cond23 cond34 cond45 cond56 =
159 leftJoin q6 ( leftJoin q5
171 :: (Default Unpackspec fieldsL1 fieldsL1,
172 Default Unpackspec fieldsL2 fieldsL2,
173 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
174 Default Unpackspec fieldsL3 fieldsL3,
175 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
176 Default Unpackspec fieldsL4 fieldsL4,
177 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
178 Default Unpackspec fieldsL5 fieldsL5,
179 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
180 Default Unpackspec fieldsL6 fieldsL6,
181 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
182 Default Unpackspec fieldsR fieldsR,
183 Default NullMaker fieldsR nullableFieldsR5,
184 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR6,
185 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
186 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
187 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
188 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4) =>
189 Opaleye.Select fieldsR
190 -> Opaleye.Select fieldsL6
191 -> Opaleye.Select fieldsL5
192 -> Opaleye.Select fieldsL4
193 -> Opaleye.Select fieldsL3
194 -> Opaleye.Select fieldsL2
195 -> Opaleye.Select fieldsL1
196 -> ((fieldsL6, fieldsR) -> Column PGBool)
197 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
198 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
199 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
200 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
201 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
202 -> Opaleye.Select (fieldsL1, nullableFieldsR6)
203 leftJoin7 q1 q2 q3 q4 q5 q6 q7
204 cond12 cond23 cond34 cond45 cond56 cond67 =
205 leftJoin q7 ( leftJoin q6
219 :: (Default Unpackspec fieldsL1 fieldsL1,
220 Default Unpackspec fieldsL2 fieldsL2,
221 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
222 Default Unpackspec fieldsL3 fieldsL3,
223 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
224 Default Unpackspec fieldsL4 fieldsL4,
225 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
226 Default Unpackspec fieldsL5 fieldsL5,
227 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
228 Default Unpackspec fieldsL6 fieldsL6,
229 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
230 Default Unpackspec fieldsL7 fieldsL7,
231 Default Unpackspec nullableFieldsR6 nullableFieldsR6,
232 Default Unpackspec fieldsR fieldsR,
233 Default NullMaker fieldsR nullableFieldsR6,
234 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR7,
235 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
236 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
237 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
238 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4,
239 Default NullMaker (fieldsL7, nullableFieldsR6) nullableFieldsR5) =>
240 Opaleye.Select fieldsR
241 -> Opaleye.Select fieldsL7
242 -> Opaleye.Select fieldsL6
243 -> Opaleye.Select fieldsL5
244 -> Opaleye.Select fieldsL4
245 -> Opaleye.Select fieldsL3
246 -> Opaleye.Select fieldsL2
247 -> Opaleye.Select fieldsL1
248 -> ((fieldsL7, fieldsR) -> Column PGBool)
249 -> ((fieldsL6, (fieldsL7, nullableFieldsR6)) -> Column PGBool)
250 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
251 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
252 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
253 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
254 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
255 -> Opaleye.Select (fieldsL1, nullableFieldsR7)
256 leftJoin8 q1 q2 q3 q4 q5 q6 q7 q8
257 cond12 cond23 cond34 cond45 cond56 cond67 cond78 =
258 leftJoin q8 ( leftJoin q7
274 :: (Default Unpackspec fieldsL1 fieldsL1,
275 Default Unpackspec fieldsL2 fieldsL2,
276 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
277 Default Unpackspec fieldsL3 fieldsL3,
278 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
279 Default Unpackspec fieldsL4 fieldsL4,
280 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
281 Default Unpackspec fieldsL5 fieldsL5,
282 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
283 Default Unpackspec fieldsL6 fieldsL6,
284 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
285 Default Unpackspec fieldsL7 fieldsL7,
286 Default Unpackspec nullableFieldsR6 nullableFieldsR6,
287 Default Unpackspec fieldsL8 fieldsL8,
288 Default Unpackspec nullableFieldsR7 nullableFieldsR7,
289 Default Unpackspec fieldsR fieldsR,
290 Default NullMaker fieldsR nullableFieldsR7,
291 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR8,
292 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
293 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
294 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
295 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4,
296 Default NullMaker (fieldsL7, nullableFieldsR6) nullableFieldsR5,
297 Default NullMaker (fieldsL8, nullableFieldsR7) nullableFieldsR6) =>
298 Opaleye.Select fieldsR
299 -> Opaleye.Select fieldsL8
300 -> Opaleye.Select fieldsL7
301 -> Opaleye.Select fieldsL6
302 -> Opaleye.Select fieldsL5
303 -> Opaleye.Select fieldsL4
304 -> Opaleye.Select fieldsL3
305 -> Opaleye.Select fieldsL2
306 -> Opaleye.Select fieldsL1
307 -> ((fieldsL8, fieldsR) -> Column PGBool)
308 -> ((fieldsL7, (fieldsL8, nullableFieldsR7)) -> Column PGBool)
309 -> ((fieldsL6, (fieldsL7, nullableFieldsR6)) -> Column PGBool)
310 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
311 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
312 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
313 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
314 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
315 -> Opaleye.Select (fieldsL1, nullableFieldsR8)
316 leftJoin9 q1 q2 q3 q4 q5 q6 q7 q8 q9
317 cond12 cond23 cond34 cond45 cond56 cond67 cond78 cond89 =
318 leftJoin q9 ( leftJoin q8