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