]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Queries/Join.hs
[FIX] PubMed api ok.
[gargantext.git] / src / Gargantext / Database / Queries / Join.hs
1 {-|
2 Module : Gargantext.Database.Queries.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 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 #-}
28 ------------------------------------------------------------------------
29 module Gargantext.Database.Queries.Join
30 where
31 ------------------------------------------------------------------------
32
33 import Control.Applicative ((<*>))
34 import Control.Arrow ((>>>))
35 import Data.Profunctor.Product.Default
36 import Gargantext.Prelude
37 import Opaleye
38 import Opaleye.Internal.Join (NullMaker(..))
39 import qualified Opaleye.Internal.Unpackspec()
40
41
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
51
52 ------------------------------------------------------------------------
53
54 leftJoin3
55 :: (Default Unpackspec fieldsL1 fieldsL1,
56 Default Unpackspec fieldsL2 fieldsL2,
57 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
58 Default Unpackspec fieldsR fieldsR,
59 Default NullMaker fieldsR nullableFieldsR1,
60 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR2) =>
61 Opaleye.Select fieldsR
62 -> Opaleye.Select fieldsL2
63 -> Opaleye.Select fieldsL1
64 -> ((fieldsL2, fieldsR) -> Column PGBool)
65 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
66 -> Opaleye.Select (fieldsL1, nullableFieldsR2)
67 leftJoin3 q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q2 q1 cond12) cond23
68
69
70 leftJoin4
71 :: (Default Unpackspec fieldsL1 fieldsL1,
72 Default Unpackspec fieldsL2 fieldsL2,
73 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
74 Default Unpackspec fieldsL3 fieldsL3,
75 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
76 Default Unpackspec fieldsR fieldsR,
77 Default NullMaker fieldsR nullableFieldsR2,
78 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR3,
79 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1) =>
80 Opaleye.Select fieldsR
81 -> Opaleye.Select fieldsL3
82 -> Opaleye.Select fieldsL2
83 -> Opaleye.Select fieldsL1
84 -> ((fieldsL3, fieldsR) -> Column PGBool)
85 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
86 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
87 -> Opaleye.Select (fieldsL1, nullableFieldsR3)
88 leftJoin4 q1 q2 q3 q4 cond12 cond23 cond34 = leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34
89
90
91 leftJoin5 :: ( Default Unpackspec fieldsL1 fieldsL1,
92 Default Unpackspec fieldsL2 fieldsL2,
93 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
94 Default Unpackspec fieldsL3 fieldsL3,
95 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
96 Default Unpackspec fieldsL4 fieldsL4,
97 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
98 Default Unpackspec fieldsR fieldsR,
99 Default NullMaker fieldsR nullableFieldsR3,
100 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR4,
101 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
102 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2) =>
103 Query fieldsR
104 -> Query fieldsL4
105 -> Query fieldsL3
106 -> Query fieldsL2
107 -> Query fieldsL1
108 -> ((fieldsL4, fieldsR) -> Column PGBool)
109 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
110 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
111 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
112 -> Query (fieldsL1, nullableFieldsR4)
113 leftJoin5 q1 q2 q3 q4 q5 cond12 cond23 cond34 cond45 = leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45
114
115
116 leftJoin6 :: ( Default Unpackspec fieldsL1 fieldsL1,
117 Default Unpackspec fieldsL2 fieldsL2,
118 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
119 Default Unpackspec fieldsL3 fieldsL3,
120 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
121 Default Unpackspec fieldsL4 fieldsL4,
122 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
123 Default Unpackspec fieldsL5 fieldsL5,
124 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
125 Default Unpackspec fieldsR fieldsR,
126 Default NullMaker fieldsR nullableFieldsR4,
127 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR5,
128 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
129 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
130 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3) =>
131 Query fieldsR
132 -> Query fieldsL5
133 -> Query fieldsL4
134 -> Query fieldsL3
135 -> Query fieldsL2
136 -> Query fieldsL1 -> ((fieldsL5, fieldsR) -> Column PGBool)
137 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
138 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
139 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
140 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
141 -> Query (fieldsL1, nullableFieldsR5)
142 leftJoin6 q1 q2 q3 q4 q5 q6 cond12 cond23 cond34 cond45 cond56 = leftJoin q6 (leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45) cond56
143
144
145 leftJoin7
146 :: (Default Unpackspec fieldsL1 fieldsL1,
147 Default Unpackspec fieldsL2 fieldsL2,
148 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
149 Default Unpackspec fieldsL3 fieldsL3,
150 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
151 Default Unpackspec fieldsL4 fieldsL4,
152 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
153 Default Unpackspec fieldsL5 fieldsL5,
154 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
155 Default Unpackspec fieldsL6 fieldsL6,
156 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
157 Default Unpackspec fieldsR fieldsR,
158 Default NullMaker fieldsR nullableFieldsR5,
159 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR6,
160 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
161 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
162 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
163 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4) =>
164 Opaleye.Select fieldsR
165 -> Opaleye.Select fieldsL6
166 -> Opaleye.Select fieldsL5
167 -> Opaleye.Select fieldsL4
168 -> Opaleye.Select fieldsL3
169 -> Opaleye.Select fieldsL2
170 -> Opaleye.Select fieldsL1
171 -> ((fieldsL6, fieldsR) -> Column PGBool)
172 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
173 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
174 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
175 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
176 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
177 -> Opaleye.Select (fieldsL1, nullableFieldsR6)
178 leftJoin7 q1 q2 q3 q4 q5 q6 q7 cond12 cond23 cond34 cond45 cond56 cond67 = leftJoin q7 (leftJoin q6 (leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45) cond56) cond67
179
180
181 leftJoin8
182 :: (Default Unpackspec fieldsL1 fieldsL1,
183 Default Unpackspec fieldsL2 fieldsL2,
184 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
185 Default Unpackspec fieldsL3 fieldsL3,
186 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
187 Default Unpackspec fieldsL4 fieldsL4,
188 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
189 Default Unpackspec fieldsL5 fieldsL5,
190 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
191 Default Unpackspec fieldsL6 fieldsL6,
192 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
193 Default Unpackspec fieldsL7 fieldsL7,
194 Default Unpackspec nullableFieldsR6 nullableFieldsR6,
195 Default Unpackspec fieldsR fieldsR,
196 Default NullMaker fieldsR nullableFieldsR6,
197 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR7,
198 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
199 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
200 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
201 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4,
202 Default NullMaker (fieldsL7, nullableFieldsR6) nullableFieldsR5) =>
203 Opaleye.Select fieldsR
204 -> Opaleye.Select fieldsL7
205 -> Opaleye.Select fieldsL6
206 -> Opaleye.Select fieldsL5
207 -> Opaleye.Select fieldsL4
208 -> Opaleye.Select fieldsL3
209 -> Opaleye.Select fieldsL2
210 -> Opaleye.Select fieldsL1
211 -> ((fieldsL7, fieldsR) -> Column PGBool)
212 -> ((fieldsL6, (fieldsL7, nullableFieldsR6)) -> Column PGBool)
213 -> ((fieldsL5, (fieldsL6, nullableFieldsR5)) -> Column PGBool)
214 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
215 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
216 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
217 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
218 -> Opaleye.Select (fieldsL1, nullableFieldsR7)
219 leftJoin8 q1 q2 q3 q4 q5 q6 q7 q8 cond12 cond23 cond34 cond45 cond56 cond67 cond78 = leftJoin q8 (leftJoin q7 (leftJoin q6 (leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45) cond56) cond67) cond78
220
221
222 leftJoin9
223 :: (Default Unpackspec fieldsL1 fieldsL1,
224 Default Unpackspec fieldsL2 fieldsL2,
225 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
226 Default Unpackspec fieldsL3 fieldsL3,
227 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
228 Default Unpackspec fieldsL4 fieldsL4,
229 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
230 Default Unpackspec fieldsL5 fieldsL5,
231 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
232 Default Unpackspec fieldsL6 fieldsL6,
233 Default Unpackspec nullableFieldsR5 nullableFieldsR5,
234 Default Unpackspec fieldsL7 fieldsL7,
235 Default Unpackspec nullableFieldsR6 nullableFieldsR6,
236 Default Unpackspec fieldsL8 fieldsL8,
237 Default Unpackspec nullableFieldsR7 nullableFieldsR7,
238 Default Unpackspec fieldsR fieldsR,
239 Default NullMaker fieldsR nullableFieldsR7,
240 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR8,
241 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
242 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
243 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3,
244 Default NullMaker (fieldsL6, nullableFieldsR5) nullableFieldsR4,
245 Default NullMaker (fieldsL7, nullableFieldsR6) nullableFieldsR5,
246 Default NullMaker (fieldsL8, nullableFieldsR7) nullableFieldsR6) =>
247 Opaleye.Select fieldsR
248 -> Opaleye.Select fieldsL8
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 -> ((fieldsL8, fieldsR) -> Column PGBool)
257 -> ((fieldsL7, (fieldsL8, nullableFieldsR7)) -> 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, nullableFieldsR8)
265 leftJoin9 q1 q2 q3 q4 q5 q6 q7 q8 q9 cond12 cond23 cond34 cond45 cond56 cond67 cond78 cond89 = leftJoin q9 (leftJoin q8 (leftJoin q7 (leftJoin q6 (leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45) cond56) cond67) cond78) cond89
266