]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Join.hs
Merge branch '81-dev-zip-upload' of ssh://gitlab.iscpif.fr:20022/gargantext/haskell...
[gargantext.git] / src / Gargantext / Database / Query / Join.hs
1 {-|
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
8 Portability : POSIX
9
10 Multiple Join functions with Opaleye.
11
12 -}
13
14 {-# OPTIONS_GHC -fno-warn-orphans #-}
15
16
17 {-# LANGUAGE Arrows #-}
18 {-# LANGUAGE FunctionalDependencies #-}
19 {-# LANGUAGE QuasiQuotes #-}
20 {-# LANGUAGE NoMonomorphismRestriction #-}
21 {-# LANGUAGE TemplateHaskell #-}
22
23 ------------------------------------------------------------------------
24
25 module Gargantext.Database.Query.Join ( leftJoin2
26 , leftJoin3
27 , leftJoin4
28 , leftJoin5
29 , leftJoin6
30 , leftJoin7
31 , leftJoin8
32 , leftJoin9
33 )
34 where
35
36 import Control.Arrow ((>>>))
37 import Data.Profunctor.Product.Default
38 import Gargantext.Prelude
39 import Opaleye
40 import Opaleye.Internal.Join (NullMaker(..))
41 import qualified Opaleye.Internal.Unpackspec()
42
43 ------------------------------------------------------------------------
44 leftJoin2 :: (Default Unpackspec fieldsL fieldsL,
45 Default Unpackspec fieldsR fieldsR,
46 Default NullMaker fieldsR nullableFieldsR) =>
47 Select fieldsL
48 -> Select fieldsR
49 -> ((fieldsL, fieldsR) -> Column PGBool)
50 -> Select (fieldsL, nullableFieldsR)
51 leftJoin2 = leftJoin
52
53 ------------------------------------------------------------------------
54 -- | LeftJoin3 in two ways to write it
55 _leftJoin3 :: Query columnsA -> Query columnsB -> Query columnsC
56 -> ((columnsA, columnsB, columnsC) -> Column PGBool)
57 -> Query (columnsA, columnsB, columnsC)
58 _leftJoin3 q1 q2 q3 cond = ((,,) <$> q1 <*> q2 <*> q3) >>> keepWhen cond
59
60
61 leftJoin3 :: ( Default Unpackspec b2 b2
62 , Default Unpackspec b3 b3
63 , Default Unpackspec fieldsL fieldsL
64 , Default Unpackspec fieldsR fieldsR
65 , Default NullMaker b3 b4
66 , Default NullMaker b2 b5
67 , Default NullMaker fieldsR b2) =>
68 Select fieldsR
69 -> Select b3
70 -> Select fieldsL
71 -> ((b3, fieldsR) -> Column PGBool)
72 -> ((fieldsL, (b3, b2)) -> Column PGBool)
73 -> Select (fieldsL, (b4, b5))
74
75 leftJoin3 q1 q2 q3
76 cond12 cond23 =
77 leftJoin q3 ( leftJoin q2 q1 cond12) cond23
78
79
80 leftJoin4 :: (Default Unpackspec b2 b2,
81 Default Unpackspec fieldsL fieldsL, Default Unpackspec b3 b3,
82 Default Unpackspec b4 b4, Default Unpackspec b5 b5,
83 Default Unpackspec b6 b6, Default Unpackspec fieldsR fieldsR,
84 Default NullMaker b2 b7, Default NullMaker b5 b8,
85 Default NullMaker b6 b9, Default NullMaker b3 b5,
86 Default NullMaker b4 b6, Default NullMaker fieldsR b4) =>
87 Select fieldsR
88 -> Select b3
89 -> Select b2
90 -> Select fieldsL
91 -> ((b3, fieldsR) -> Column PGBool)
92 -> ((b2, (b3, b4)) -> Column PGBool)
93 -> ((fieldsL, (b2, (b5, b6))) -> Column PGBool)
94 -> Select (fieldsL, (b7, (b8, b9)))
95 leftJoin4 q1 q2 q3 q4
96 cond12 cond23 cond34 =
97 leftJoin q4 ( leftJoin q3
98 ( leftJoin q2 q1
99 cond12
100 ) cond23
101 ) cond34
102
103
104 leftJoin5 :: (Default Unpackspec b2 b2, Default Unpackspec b3 b3,
105 Default Unpackspec b4 b4, Default Unpackspec b5 b5,
106 Default Unpackspec b6 b6, Default Unpackspec b7 b7,
107 Default Unpackspec fieldsL fieldsL, Default Unpackspec b8 b8,
108 Default Unpackspec b9 b9, Default Unpackspec b10 b10,
109 Default Unpackspec fieldsR fieldsR, Default NullMaker b7 b6,
110 Default NullMaker b6 b11, Default NullMaker b8 b12,
111 Default NullMaker b3 b13, Default NullMaker b2 b14,
112 Default NullMaker b9 b3, Default NullMaker b10 b2,
113 Default NullMaker b5 b9, Default NullMaker b4 b10,
114 Default NullMaker fieldsR b4) =>
115 Select fieldsR
116 -> Select b5
117 -> Select b7
118 -> Select b8
119 -> Select fieldsL
120 -> ((b5, fieldsR) -> Column PGBool)
121 -> ((b7, (b5, b4)) -> Column PGBool)
122 -> ((b8, (b7, (b9, b10))) -> Column PGBool)
123 -> ((fieldsL, (b8, (b6, (b3, b2)))) -> Column PGBool)
124 -> Select (fieldsL, (b12, (b11, (b13, b14))))
125 leftJoin5 q1 q2 q3 q4 q5
126 cond12 cond23 cond34 cond45 =
127 leftJoin q5 ( leftJoin q4
128 ( leftJoin q3
129 ( leftJoin q2 q1
130 cond12
131 ) cond23
132 ) cond34
133 ) cond45
134
135
136 leftJoin6 :: (Default Unpackspec b2 b2, Default Unpackspec b3 b3,
137 Default Unpackspec b4 b4, Default Unpackspec b5 b5,
138 Default Unpackspec fieldsL fieldsL, Default Unpackspec b6 b6,
139 Default Unpackspec b7 b7, Default Unpackspec b8 b8,
140 Default Unpackspec b9 b9, Default Unpackspec b10 b10,
141 Default Unpackspec b11 b11, Default Unpackspec b12 b12,
142 Default Unpackspec b13 b13, Default Unpackspec b14 b14,
143 Default Unpackspec b15 b15, Default Unpackspec fieldsR fieldsR,
144 Default NullMaker b5 b4, Default NullMaker b4 b16,
145 Default NullMaker b6 b17, Default NullMaker b2 b18,
146 Default NullMaker b7 b2, Default NullMaker b3 b7,
147 Default NullMaker b12 b19, Default NullMaker b13 b20,
148 Default NullMaker b10 b12, Default NullMaker b11 b13,
149 Default NullMaker b14 b10, Default NullMaker b15 b11,
150 Default NullMaker b8 b14, Default NullMaker b9 b15,
151 Default NullMaker fieldsR b9) =>
152 Select fieldsR
153 -> Select b8
154 -> Select b3
155 -> Select b5
156 -> Select b6
157 -> Select fieldsL
158 -> ((b8, fieldsR) -> Column PGBool)
159 -> ((b3, (b8, b9)) -> Column PGBool)
160 -> ((b5, (b3, (b14, b15))) -> Column PGBool)
161 -> ((b6, (b5, (b7, (b10, b11)))) -> Column PGBool)
162 -> ((fieldsL, (b6, (b4, (b2, (b12, b13))))) -> Column PGBool)
163 -> Select (fieldsL, (b17, (b16, (b18, (b19, b20)))))
164 leftJoin6 q1 q2 q3 q4 q5 q6
165 cond12 cond23 cond34 cond45 cond56 =
166 leftJoin q6 ( leftJoin q5
167 ( leftJoin q4
168 ( leftJoin q3
169 ( leftJoin q2 q1
170 cond12
171 ) cond23
172 ) cond34
173 ) cond45
174 ) cond56
175
176
177 leftJoin7 :: (Default Unpackspec b2 b2, Default Unpackspec b3 b3,
178 Default Unpackspec b4 b4, Default Unpackspec b5 b5,
179 Default Unpackspec b6 b6, Default Unpackspec b7 b7,
180 Default Unpackspec b8 b8, Default Unpackspec b9 b9,
181 Default Unpackspec b10 b10, Default Unpackspec b11 b11,
182 Default Unpackspec b12 b12, Default Unpackspec b13 b13,
183 Default Unpackspec fieldsL fieldsL, Default Unpackspec b14 b14,
184 Default Unpackspec b15 b15, Default Unpackspec b16 b16,
185 Default Unpackspec b17 b17, Default Unpackspec b18 b18,
186 Default Unpackspec b19 b19, Default Unpackspec b20 b20,
187 Default Unpackspec b21 b21, Default Unpackspec fieldsR fieldsR,
188 Default NullMaker b11 b8, Default NullMaker b8 b10,
189 Default NullMaker b10 b9, Default NullMaker b9 b22,
190 Default NullMaker b16 b12, Default NullMaker b12 b17,
191 Default NullMaker b17 b23, Default NullMaker b13 b24,
192 Default NullMaker b15 b25, Default NullMaker b14 b15,
193 Default NullMaker b3 b26, Default NullMaker b2 b27,
194 Default NullMaker b18 b3, Default NullMaker b19 b2,
195 Default NullMaker b5 b18, Default NullMaker b4 b19,
196 Default NullMaker b20 b5, Default NullMaker b21 b4,
197 Default NullMaker b7 b20, Default NullMaker b6 b21,
198 Default NullMaker fieldsR b6) =>
199 Select fieldsR
200 -> Select b7
201 -> Select b11
202 -> Select b16
203 -> Select b14
204 -> Select b13
205 -> Select fieldsL
206 -> ((b7, fieldsR) -> Column PGBool)
207 -> ((b11, (b7, b6)) -> Column PGBool)
208 -> ((b16, (b11, (b20, b21))) -> Column PGBool)
209 -> ((b14, (b16, (b8, (b5, b4)))) -> Column PGBool)
210 -> ((b13, (b14, (b12, (b10, (b18, b19))))) -> Column PGBool)
211 -> ((fieldsL, (b13, (b15, (b17, (b9, (b3, b2))))))
212 -> Column PGBool)
213 -> Select (fieldsL, (b24, (b25, (b23, (b22, (b26, b27))))))
214 leftJoin7 q1 q2 q3 q4 q5 q6 q7
215 cond12 cond23 cond34 cond45 cond56 cond67 =
216 leftJoin q7 ( leftJoin q6
217 ( leftJoin q5
218 ( leftJoin q4
219 ( leftJoin q3
220 ( leftJoin q2 q1
221 cond12
222 ) cond23
223 ) cond34
224 ) cond45
225 ) cond56
226 ) cond67
227
228
229 leftJoin8 :: (Default Unpackspec b2 b2, Default Unpackspec b3 b3,
230 Default Unpackspec b4 b4, Default Unpackspec b5 b5,
231 Default Unpackspec b6 b6, Default Unpackspec b7 b7,
232 Default Unpackspec b8 b8, Default Unpackspec b9 b9,
233 Default Unpackspec b10 b10, Default Unpackspec fieldsL fieldsL,
234 Default Unpackspec b11 b11, Default Unpackspec b12 b12,
235 Default Unpackspec b13 b13, Default Unpackspec b14 b14,
236 Default Unpackspec b15 b15, Default Unpackspec b16 b16,
237 Default Unpackspec b17 b17, Default Unpackspec b18 b18,
238 Default Unpackspec b19 b19, Default Unpackspec b20 b20,
239 Default Unpackspec b21 b21, Default Unpackspec b22 b22,
240 Default Unpackspec b23 b23, Default Unpackspec b24 b24,
241 Default Unpackspec b25 b25, Default Unpackspec b26 b26,
242 Default Unpackspec b27 b27, Default Unpackspec b28 b28,
243 Default Unpackspec fieldsR fieldsR, Default NullMaker b8 b5,
244 Default NullMaker b5 b7, Default NullMaker b7 b6,
245 Default NullMaker b6 b29, Default NullMaker b13 b9,
246 Default NullMaker b9 b14, Default NullMaker b14 b30,
247 Default NullMaker b10 b31, Default NullMaker b12 b32,
248 Default NullMaker b11 b12, Default NullMaker b2 b33,
249 Default NullMaker b15 b2, Default NullMaker b3 b15,
250 Default NullMaker b16 b3, Default NullMaker b4 b16,
251 Default NullMaker b23 b34, Default NullMaker b24 b35,
252 Default NullMaker b21 b23, Default NullMaker b22 b24,
253 Default NullMaker b25 b21, Default NullMaker b26 b22,
254 Default NullMaker b19 b25, Default NullMaker b20 b26,
255 Default NullMaker b27 b19, Default NullMaker b28 b20,
256 Default NullMaker b17 b27, Default NullMaker b18 b28,
257 Default NullMaker fieldsR b18) =>
258 Select fieldsR
259 -> Select b17
260 -> Select b4
261 -> Select b8
262 -> Select b13
263 -> Select b11
264 -> Select b10
265 -> Select fieldsL
266 -> ((b17, fieldsR) -> Column PGBool)
267 -> ((b4, (b17, b18)) -> Column PGBool)
268 -> ((b8, (b4, (b27, b28))) -> Column PGBool)
269 -> ((b13, (b8, (b16, (b19, b20)))) -> Column PGBool)
270 -> ((b11, (b13, (b5, (b3, (b25, b26))))) -> Column PGBool)
271 -> ((b10, (b11, (b9, (b7, (b15, (b21, b22)))))) -> Column PGBool)
272 -> ((fieldsL, (b10, (b12, (b14, (b6, (b2, (b23, b24)))))))
273 -> Column PGBool)
274 -> Select (fieldsL, (b31, (b32, (b30, (b29, (b33, (b34, b35)))))))
275 leftJoin8 q1 q2 q3 q4 q5 q6 q7 q8
276 cond12 cond23 cond34 cond45 cond56 cond67 cond78 =
277 leftJoin q8 ( leftJoin q7
278 ( leftJoin q6
279 ( leftJoin q5
280 ( leftJoin q4
281 ( leftJoin q3
282 ( leftJoin q2 q1
283 cond12
284 ) cond23
285 ) cond34
286 ) cond45
287 ) cond56
288 ) cond67
289 ) cond78
290
291
292
293 leftJoin9 :: (Default Unpackspec b2 b2, Default Unpackspec b3 b3,
294 Default Unpackspec b4 b4, Default Unpackspec b5 b5,
295 Default Unpackspec b6 b6, Default Unpackspec b7 b7,
296 Default Unpackspec b8 b8, Default Unpackspec b9 b9,
297 Default Unpackspec b10 b10, Default Unpackspec b11 b11,
298 Default Unpackspec b12 b12, Default Unpackspec b13 b13,
299 Default Unpackspec b14 b14, Default Unpackspec b15 b15,
300 Default Unpackspec b16 b16, Default Unpackspec b17 b17,
301 Default Unpackspec b18 b18, Default Unpackspec b19 b19,
302 Default Unpackspec b20 b20, Default Unpackspec b21 b21,
303 Default Unpackspec fieldsL fieldsL, Default Unpackspec b22 b22,
304 Default Unpackspec b23 b23, Default Unpackspec b24 b24,
305 Default Unpackspec b25 b25, Default Unpackspec b26 b26,
306 Default Unpackspec b27 b27, Default Unpackspec b28 b28,
307 Default Unpackspec b29 b29, Default Unpackspec b30 b30,
308 Default Unpackspec b31 b31, Default Unpackspec b32 b32,
309 Default Unpackspec b33 b33, Default Unpackspec b34 b34,
310 Default Unpackspec b35 b35, Default Unpackspec b36 b36,
311 Default Unpackspec fieldsR fieldsR, Default NullMaker b15 b10,
312 Default NullMaker b10 b14, Default NullMaker b14 b11,
313 Default NullMaker b11 b13, Default NullMaker b13 b12,
314 Default NullMaker b12 b37, Default NullMaker b28 b16,
315 Default NullMaker b16 b29, Default NullMaker b29 b17,
316 Default NullMaker b17 b30, Default NullMaker b30 b38,
317 Default NullMaker b21 b20, Default NullMaker b20 b39,
318 Default NullMaker b22 b40, Default NullMaker b18 b41,
319 Default NullMaker b23 b18, Default NullMaker b19 b23,
320 Default NullMaker b26 b42, Default NullMaker b25 b26,
321 Default NullMaker b27 b25, Default NullMaker b24 b27,
322 Default NullMaker b3 b43, Default NullMaker b2 b44,
323 Default NullMaker b31 b3, Default NullMaker b32 b2,
324 Default NullMaker b5 b31, Default NullMaker b4 b32,
325 Default NullMaker b33 b5, Default NullMaker b34 b4,
326 Default NullMaker b7 b33, Default NullMaker b6 b34,
327 Default NullMaker b35 b7, Default NullMaker b36 b6,
328 Default NullMaker b9 b35, Default NullMaker b8 b36,
329 Default NullMaker fieldsR b8) =>
330 Select fieldsR
331 -> Select b9
332 -> Select b15
333 -> Select b28
334 -> Select b24
335 -> Select b19
336 -> Select b21
337 -> Select b22
338 -> Select fieldsL
339 -> ((b9, fieldsR) -> Column PGBool)
340 -> ((b15, (b9, b8)) -> Column PGBool)
341 -> ((b28, (b15, (b35, b36))) -> Column PGBool)
342 -> ((b24, (b28, (b10, (b7, b6)))) -> Column PGBool)
343 -> ((b19, (b24, (b16, (b14, (b33, b34))))) -> Column PGBool)
344 -> ((b21, (b19, (b27, (b29, (b11, (b5, b4)))))) -> Column PGBool)
345 -> ((b22, (b21, (b23, (b25, (b17, (b13, (b31, b32)))))))
346 -> Column PGBool)
347 -> ((fieldsL, (b22, (b20, (b18, (b26, (b30, (b12, (b3, b2))))))))
348 -> Column PGBool)
349 -> Select
350 (fieldsL, (b40, (b39, (b41, (b42, (b38, (b37, (b43, b44))))))))
351 leftJoin9 q1 q2 q3 q4 q5 q6 q7 q8 q9
352 cond12 cond23 cond34 cond45 cond56 cond67 cond78 cond89 =
353 leftJoin q9 ( leftJoin q8
354 ( leftJoin q7
355 ( leftJoin q6
356 ( leftJoin q5
357 ( leftJoin q4
358 ( leftJoin q3
359 ( leftJoin q2 q1
360 cond12
361 ) cond23
362 ) cond34
363 ) cond45
364 ) cond56
365 ) cond67
366 ) cond78
367 ) cond89
368