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