]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Queries/Join.hs
[NGRAMS-TABLE] Attempt at fixing updateNodeNgrams query
[gargantext.git] / src / Gargantext / Database / Queries / Join.hs
1 {-|
2 Module : Gargantext.Database.Queries.Join
3 Description : Main requests of Node to the database
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9 -}
10
11 {-# OPTIONS_GHC -fno-warn-orphans #-}
12 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
13
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE FlexibleContexts #-}
17 {-# LANGUAGE FlexibleInstances #-}
18 {-# LANGUAGE FunctionalDependencies #-}
19 {-# LANGUAGE MultiParamTypeClasses #-}
20 {-# LANGUAGE QuasiQuotes #-}
21 {-# LANGUAGE NoImplicitPrelude #-}
22 {-# LANGUAGE NoMonomorphismRestriction #-}
23 {-# LANGUAGE OverloadedStrings #-}
24 {-# LANGUAGE TemplateHaskell #-}
25 ------------------------------------------------------------------------
26 module Gargantext.Database.Queries.Join
27 where
28 ------------------------------------------------------------------------
29
30 import Control.Applicative ((<*>))
31 import Control.Arrow ((>>>))
32 import Data.Profunctor.Product.Default
33 import Gargantext.Database.Schema.Ngrams
34 import Gargantext.Database.Schema.Node
35 import Gargantext.Database.Schema.NodeNode
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 leftJoin3Ex :: Query (NodeRead, (NodeNodeReadNull, NodeReadNull))
55 leftJoin3Ex = leftJoin3 queryNodeNodeTable queryNodeTable queryNodeTable cond12 cond23
56 where
57 cond12 = undefined
58 cond23 :: (NodeRead, (NodeNodeRead, NodeReadNull)) -> Column PGBool
59 cond23 = undefined
60
61
62 leftJoin3 :: ( Default Unpackspec columnsL1 columnsL1
63 , Default Unpackspec columnsL2 columnsL2
64 , Default Unpackspec columnsL3 columnsL3
65
66 , Default Unpackspec nullableColumnsL2 nullableColumnsL2
67
68 , Default NullMaker columnsL2 nullableColumnsL2
69 , Default NullMaker (columnsL1, nullableColumnsL2) nullableColumnsL3
70 )
71 =>
72 Query columnsL1 -> Query columnsL2 -> Query columnsL3
73 -> ((columnsL1, columnsL2) -> Column PGBool)
74 -> ((columnsL3, (columnsL1, nullableColumnsL2)) -> Column PGBool)
75 -> Query (columnsL3, nullableColumnsL3)
76 leftJoin3 q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q1 q2 cond12) cond23
77
78
79 leftJoin3'
80 :: (Default Unpackspec fieldsL1 fieldsL1,
81 Default Unpackspec fieldsL2 fieldsL2,
82 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
83 Default Unpackspec fieldsR fieldsR,
84 Default NullMaker fieldsR nullableFieldsR1,
85 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR2) =>
86 Opaleye.Select fieldsR
87 -> Opaleye.Select fieldsL2
88 -> Opaleye.Select fieldsL1
89 -> ((fieldsL2, fieldsR) -> Column PGBool)
90 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
91 -> Opaleye.Select (fieldsL1, nullableFieldsR2)
92 leftJoin3' q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q2 q1 cond12) cond23
93
94 --{-
95 leftJoin4' :: Query (NodeRead, (NodeReadNull, (NgramsReadNull, NodeReadNull)))
96 leftJoin4' = leftJoin4 queryNgramsTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34
97 where
98 cond12 :: (NgramsRead, NodeRead) -> Column PGBool
99 cond12 = undefined
100
101 cond23 :: (NodeRead, (NgramsRead, NodeReadNull)) -> Column PGBool
102 cond23 = undefined
103
104 cond34 :: (NodeRead, (NodeRead, (NgramsReadNull, NodeReadNull))) -> Column PGBool
105 cond34 = undefined
106
107 {-
108 rightJoin4' :: Query (((NodeReadNull, NodeReadNull), NodeReadNull), NodeRead)
109 rightJoin4' = rightJoin4 queryNodeTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34
110 where
111 cond12 :: (NodeRead, NodeRead) -> Column PGBool
112 cond12 = undefined
113
114 cond23 :: ((NodeReadNull, NodeRead), NodeRead) -> Column PGBool
115 cond23 = undefined
116
117 cond34 :: (((NodeReadNull, NodeReadNull), NodeRead), NodeRead) -> Column PGBool
118 cond34 = undefined
119
120 --}
121
122
123 leftJoin4
124 :: (Default Unpackspec fieldsL1 fieldsL1,
125 Default Unpackspec fieldsL2 fieldsL2,
126 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
127 Default Unpackspec fieldsL3 fieldsL3,
128 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
129 Default Unpackspec fieldsR fieldsR,
130 Default NullMaker fieldsR nullableFieldsR2,
131 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR3,
132 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1) =>
133 Opaleye.Select fieldsL3
134 -> Opaleye.Select fieldsR
135 -> Opaleye.Select fieldsL2
136 -> Opaleye.Select fieldsL1
137 -> ((fieldsL3, fieldsR) -> Column PGBool)
138 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
139 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
140 -> Opaleye.Select (fieldsL1, nullableFieldsR3)
141 leftJoin4 q1 q2 q3 q4 cond12 cond23 cond34 = leftJoin q4 (leftJoin q3 (leftJoin q1 q2 cond12) cond23) cond34
142
143
144 -- rightJoin4 q1 q2 q3 q4 cond12 cond23 cond34 = rightJoin q4 (rightJoin q3 (rightJoin q1 q2 cond12) cond23) cond34
145
146 --{-
147 leftJoin5' :: Query (NodeRead, (NodeReadNull, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull))))
148 leftJoin5' = leftJoin5 queryNodeSearchTable queryNodeNodeTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34 cond45
149 where
150 cond12 :: (NodeNodeRead, NodeSearchRead) -> Column PGBool
151 cond12 = undefined
152
153 cond23 :: (NodeRead, (NodeNodeRead, NodeSearchReadNull)) -> Column PGBool
154 cond23 = undefined
155
156 cond34 :: (NodeRead, (NodeRead, (NodeNodeReadNull, NodeSearchReadNull))) -> Column PGBool
157 cond34 = undefined
158
159 cond45 :: (NodeRead, (NodeRead, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull)))) -> Column PGBool
160 cond45 = undefined
161 --}
162
163 leftJoin5 :: ( Default Unpackspec fieldsL1 fieldsL1,
164 Default Unpackspec fieldsL2 fieldsL2,
165 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
166 Default Unpackspec fieldsL3 fieldsL3,
167 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
168 Default Unpackspec fieldsL4 fieldsL4,
169 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
170 Default Unpackspec fieldsR fieldsR,
171 Default NullMaker fieldsR nullableFieldsR3,
172 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR4,
173 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
174 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2) =>
175 Query fieldsR
176 -> Query fieldsL4
177 -> Query fieldsL3
178 -> Query fieldsL2
179 -> Query fieldsL1
180 -> ((fieldsL4, fieldsR) -> Column PGBool)
181 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
182 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
183 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
184 -> Query (fieldsL1, nullableFieldsR4)
185 leftJoin5 q1 q2 q3 q4 q5 cond12 cond23 cond34 cond45 = leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45
186
187
188 leftJoin6 :: ( Default Unpackspec fieldsL1 fieldsL1,
189 Default Unpackspec fieldsL2 fieldsL2,
190 Default Unpackspec nullableFieldsR1 nullableFieldsR1,
191 Default Unpackspec fieldsL3 fieldsL3,
192 Default Unpackspec nullableFieldsR2 nullableFieldsR2,
193 Default Unpackspec fieldsL4 fieldsL4,
194 Default Unpackspec nullableFieldsR3 nullableFieldsR3,
195 Default Unpackspec fieldsL5 fieldsL5,
196 Default Unpackspec nullableFieldsR4 nullableFieldsR4,
197 Default Unpackspec fieldsR fieldsR,
198 Default NullMaker fieldsR nullableFieldsR4,
199 Default NullMaker (fieldsL2, nullableFieldsR1) nullableFieldsR5,
200 Default NullMaker (fieldsL3, nullableFieldsR2) nullableFieldsR1,
201 Default NullMaker (fieldsL4, nullableFieldsR3) nullableFieldsR2,
202 Default NullMaker (fieldsL5, nullableFieldsR4) nullableFieldsR3) =>
203 Query fieldsR
204 -> Query fieldsL5
205 -> Query fieldsL4
206 -> Query fieldsL3
207 -> Query fieldsL2
208 -> Query fieldsL1 -> ((fieldsL5, fieldsR) -> Column PGBool)
209 -> ((fieldsL4, (fieldsL5, nullableFieldsR4)) -> Column PGBool)
210 -> ((fieldsL3, (fieldsL4, nullableFieldsR3)) -> Column PGBool)
211 -> ((fieldsL2, (fieldsL3, nullableFieldsR2)) -> Column PGBool)
212 -> ((fieldsL1, (fieldsL2, nullableFieldsR1)) -> Column PGBool)
213 -> Query (fieldsL1, nullableFieldsR5)
214 leftJoin6 q1 q2 q3 q4 q5 q6 cond12 cond23 cond34 cond45 cond56 =
215 leftJoin q6 (leftJoin q5 (leftJoin q4 (leftJoin q3 (leftJoin q2 q1 cond12) cond23) cond34) cond45) cond56
216
217 --{-
218 leftJoin6' :: Query (NodeRead, (NodeReadNull, (NodeReadNull, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull)))))
219 leftJoin6' = leftJoin6 queryNodeSearchTable queryNodeNodeTable queryNodeTable queryNodeTable queryNodeTable queryNodeTable cond12 cond23 cond34 cond45 cond56
220 where
221 cond12 :: (NodeNodeRead, NodeSearchRead) -> Column PGBool
222 cond12 = undefined
223
224 cond23 :: (NodeRead, (NodeNodeRead, NodeSearchReadNull)) -> Column PGBool
225 cond23 = undefined
226
227 cond34 :: (NodeRead, (NodeRead, (NodeNodeReadNull, NodeSearchReadNull))) -> Column PGBool
228 cond34 = undefined
229
230 cond45 :: (NodeRead, (NodeRead, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull)))) -> Column PGBool
231 cond45 = undefined
232
233 cond56 :: (NodeRead, (NodeRead, (NodeReadNull, (NodeReadNull, (NodeNodeReadNull, NodeSearchReadNull))))) -> Column PGBool
234 cond56 = undefined
235
236 --}
237
238