]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Join.hs
[FIX] working for all ngrams but NgramsTerms with simple Tree (1 depth)
[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 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
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
62 :: (Default Unpackspec fieldsL1 fieldsL1,
63 Default Unpackspec fieldsL2 fieldsL2,
64 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
65 Default Unpackspec fieldsR fieldsR,
66 Default NullMaker fieldsR nullableFieldsR1,
67 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR2) =>
68 Opaleye.Select fieldsR
69 -> Opaleye.Select fieldsL2
70 -> Opaleye.Select fieldsL1
71 -> ((fieldsL2, fieldsR) -> Column PGBool)
72 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
73 -> Opaleye.Select (fieldsL1, nullableFieldsR2)
74 leftJoin3 q1 q2 q3
75 cond12 cond23 =
76 leftJoin q3 ( leftJoin q2 q1 cond12) cond23
77
78
79 leftJoin4
80 :: (Default Unpackspec fieldsL1 fieldsL1,
81 Default Unpackspec fieldsL2 fieldsL2,
82 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
83 Default Unpackspec fieldsL3 fieldsL3,
84 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
85 Default Unpackspec fieldsR fieldsR,
86 Default NullMaker fieldsR nullableFieldsR2,
87 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR3,
88 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1) =>
89 Opaleye.Select fieldsR
90 -> Opaleye.Select fieldsL3
91 -> Opaleye.Select fieldsL2
92 -> Opaleye.Select fieldsL1
93 -> ((fieldsL3, fieldsR) -> Column PGBool)
94 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
95 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
96 -> Opaleye.Select (fieldsL1, nullableFieldsR3)
97 leftJoin4 q1 q2 q3 q4
98 cond12 cond23 cond34 =
99 leftJoin q4 ( leftJoin q3
100 ( leftJoin q2 q1
101 cond12
102 ) cond23
103 ) cond34
104
105
106 leftJoin5 :: ( Default Unpackspec fieldsL1 fieldsL1,
107 Default Unpackspec fieldsL2 fieldsL2,
108 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
109 Default Unpackspec fieldsL3 fieldsL3,
110 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
111 Default Unpackspec fieldsL4 fieldsL4,
112 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
113 Default Unpackspec fieldsR fieldsR,
114 Default NullMaker fieldsR nullableFieldsR3,
115 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR4,
116 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
117 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2) =>
118 Query fieldsR
119 -> Query fieldsL4
120 -> Query fieldsL3
121 -> Query fieldsL2
122 -> Query fieldsL1
123 -> ((fieldsL4, fieldsR) -> Column PGBool)
124 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
125 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
126 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
127 -> Query (fieldsL1, nullableFieldsR4)
128 leftJoin5 q1 q2 q3 q4 q5
129 cond12 cond23 cond34 cond45 =
130 leftJoin q5 ( leftJoin q4
131 ( leftJoin q3
132 ( leftJoin q2 q1
133 cond12
134 ) cond23
135 ) cond34
136 ) cond45
137
138
139 leftJoin6 :: ( Default Unpackspec fieldsL1 fieldsL1,
140 Default Unpackspec fieldsL2 fieldsL2,
141 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
142 Default Unpackspec fieldsL3 fieldsL3,
143 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
144 Default Unpackspec fieldsL4 fieldsL4,
145 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
146 Default Unpackspec fieldsL5 fieldsL5,
147 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
148 Default Unpackspec fieldsR fieldsR,
149 Default NullMaker fieldsR nullableFieldsR4,
150 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR5,
151 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
152 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
153 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3) =>
154 Query fieldsR
155 -> Query fieldsL5
156 -> Query fieldsL4
157 -> Query fieldsL3
158 -> Query fieldsL2
159 -> Query fieldsL1 -> ((fieldsL5, fieldsR) -> Column PGBool)
160 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
161 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
162 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
163 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
164 -> Query (fieldsL1, nullableFieldsR5)
165 leftJoin6 q1 q2 q3 q4 q5 q6
166 cond12 cond23 cond34 cond45 cond56 =
167 leftJoin q6 ( leftJoin q5
168 ( leftJoin q4
169 ( leftJoin q3
170 ( leftJoin q2 q1
171 cond12
172 ) cond23
173 ) cond34
174 ) cond45
175 ) cond56
176
177
178 leftJoin7
179 :: (Default Unpackspec fieldsL1 fieldsL1,
180 Default Unpackspec fieldsL2 fieldsL2,
181 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
182 Default Unpackspec fieldsL3 fieldsL3,
183 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
184 Default Unpackspec fieldsL4 fieldsL4,
185 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
186 Default Unpackspec fieldsL5 fieldsL5,
187 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
188 Default Unpackspec fieldsL6 fieldsL6,
189 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
190 Default Unpackspec fieldsR fieldsR,
191 Default NullMaker fieldsR nullableFieldsR5,
192 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR6,
193 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
194 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
195 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
196 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4) =>
197 Opaleye.Select fieldsR
198 -> Opaleye.Select fieldsL6
199 -> Opaleye.Select fieldsL5
200 -> Opaleye.Select fieldsL4
201 -> Opaleye.Select fieldsL3
202 -> Opaleye.Select fieldsL2
203 -> Opaleye.Select fieldsL1
204 -> ((fieldsL6, fieldsR) -> Column PGBool)
205 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
206 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
207 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
208 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
209 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
210 -> Opaleye.Select (fieldsL1, nullableFieldsR6)
211 leftJoin7 q1 q2 q3 q4 q5 q6 q7
212 cond12 cond23 cond34 cond45 cond56 cond67 =
213 leftJoin q7 ( leftJoin q6
214 ( leftJoin q5
215 ( leftJoin q4
216 ( leftJoin q3
217 ( leftJoin q2 q1
218 cond12
219 ) cond23
220 ) cond34
221 ) cond45
222 ) cond56
223 ) cond67
224
225
226 leftJoin8
227 :: (Default Unpackspec fieldsL1 fieldsL1,
228 Default Unpackspec fieldsL2 fieldsL2,
229 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
230 Default Unpackspec fieldsL3 fieldsL3,
231 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
232 Default Unpackspec fieldsL4 fieldsL4,
233 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
234 Default Unpackspec fieldsL5 fieldsL5,
235 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
236 Default Unpackspec fieldsL6 fieldsL6,
237 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
238 Default Unpackspec fieldsL7 fieldsL7,
239 Default Unpackspec nullableFieldsR6 nullableFieldsR6,
240 Default Unpackspec fieldsR fieldsR,
241 Default NullMaker fieldsR nullableFieldsR6,
242 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR7,
243 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
244 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
245 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
246 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4,
247 Default NullMaker (fieldsL7, nullableFieldsR6) nullableFieldsR5) =>
248 Opaleye.Select fieldsR
249 -> Opaleye.Select fieldsL7
250 -> Opaleye.Select fieldsL6
251 -> Opaleye.Select fieldsL5
252 -> Opaleye.Select fieldsL4
253 -> Opaleye.Select fieldsL3
254 -> Opaleye.Select fieldsL2
255 -> Opaleye.Select fieldsL1
256 -> ((fieldsL7, fieldsR) -> Column PGBool)
257 -> ((fieldsL6, (fieldsL7, nullableFieldsR6)) -> Column PGBool)
258 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
259 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
260 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
261 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
262 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
263 -> Opaleye.Select (fieldsL1, nullableFieldsR7)
264 leftJoin8 q1 q2 q3 q4 q5 q6 q7 q8
265 cond12 cond23 cond34 cond45 cond56 cond67 cond78 =
266 leftJoin q8 ( leftJoin q7
267 ( leftJoin q6
268 ( leftJoin q5
269 ( leftJoin q4
270 ( leftJoin q3
271 ( leftJoin q2 q1
272 cond12
273 ) cond23
274 ) cond34
275 ) cond45
276 ) cond56
277 ) cond67
278 ) cond78
279
280
281 leftJoin9
282 :: (Default Unpackspec fieldsL1 fieldsL1,
283 Default Unpackspec fieldsL2 fieldsL2,
284 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
285 Default Unpackspec fieldsL3 fieldsL3,
286 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
287 Default Unpackspec fieldsL4 fieldsL4,
288 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
289 Default Unpackspec fieldsL5 fieldsL5,
290 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
291 Default Unpackspec fieldsL6 fieldsL6,
292 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
293 Default Unpackspec fieldsL7 fieldsL7,
294 Default Unpackspec nullableFieldsR6 nullableFieldsR6,
295 Default Unpackspec fieldsL8 fieldsL8,
296 Default Unpackspec nullableFieldsR7 nullableFieldsR7,
297 Default Unpackspec fieldsR fieldsR,
298 Default NullMaker fieldsR nullableFieldsR7,
299 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR8,
300 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
301 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
302 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
303 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4,
304 Default NullMaker (fieldsL7, nullableFieldsR6) nullableFieldsR5,
305 Default NullMaker (fieldsL8, nullableFieldsR7) nullableFieldsR6) =>
306 Opaleye.Select fieldsR
307 -> Opaleye.Select fieldsL8
308 -> Opaleye.Select fieldsL7
309 -> Opaleye.Select fieldsL6
310 -> Opaleye.Select fieldsL5
311 -> Opaleye.Select fieldsL4
312 -> Opaleye.Select fieldsL3
313 -> Opaleye.Select fieldsL2
314 -> Opaleye.Select fieldsL1
315 -> ((fieldsL8, fieldsR) -> Column PGBool)
316 -> ((fieldsL7, (fieldsL8, nullableFieldsR7)) -> Column PGBool)
317 -> ((fieldsL6, (fieldsL7, nullableFieldsR6)) -> Column PGBool)
318 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
319 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
320 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
321 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
322 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
323 -> Opaleye.Select (fieldsL1, nullableFieldsR8)
324 leftJoin9 q1 q2 q3 q4 q5 q6 q7 q8 q9
325 cond12 cond23 cond34 cond45 cond56 cond67 cond78 cond89 =
326 leftJoin q9 ( leftJoin q8
327 ( leftJoin q7
328 ( leftJoin q6
329 ( leftJoin q5
330 ( leftJoin q4
331 ( leftJoin q3
332 ( leftJoin q2 q1
333 cond12
334 ) cond23
335 ) cond34
336 ) cond45
337 ) cond56
338 ) cond67
339 ) cond78
340 ) cond89
341