]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/Node.hs
[TEXT FLOW] checking all
[gargantext.git] / src / Gargantext / Database / Schema / Node.hs
1 {-|
2 Module : Gargantext.Database.Schema.Node
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-name-shadowing #-}
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE DeriveGeneric #-}
16 {-# LANGUAGE ConstraintKinds #-}
17 {-# LANGUAGE FlexibleContexts #-}
18 {-# LANGUAGE FlexibleInstances #-}
19 {-# LANGUAGE FunctionalDependencies #-}
20 {-# LANGUAGE OverloadedStrings #-}
21 {-# LANGUAGE MultiParamTypeClasses #-}
22 {-# LANGUAGE NoImplicitPrelude #-}
23 {-# LANGUAGE RankNTypes #-}
24 {-# LANGUAGE TemplateHaskell #-}
25 {-# LANGUAGE TypeFamilies #-}
26
27 module Gargantext.Database.Schema.Node where
28
29 import Control.Lens.TH (makeLensesWith, abbreviatedFields)
30 import Data.Maybe (Maybe(..))
31 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
32 import Data.Text (Text)
33 import Database.PostgreSQL.Simple.FromField (FromField, fromField)
34 import Gargantext.Core.Types
35 import Gargantext.Database.Admin.Utils
36 import Gargantext.Viz.Graph (HyperdataGraph(..))
37 import Opaleye hiding (FromField)
38 import Opaleye.Internal.QueryArr (Query)
39 import Prelude hiding (null, id, map, sum)
40
41 ------------------------------------------------------------------------
42
43 $(makeAdaptorAndInstance "pNode" ''NodePoly)
44 $(makeLensesWith abbreviatedFields ''NodePoly)
45
46 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
47 $(makeLensesWith abbreviatedFields ''NodePolySearch)
48
49 ------------------------------------------------------------------------
50 nodeTable :: Table NodeWrite NodeRead
51 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
52 , _node_typename = required "typename"
53 , _node_userId = required "user_id"
54
55 , _node_parentId = optional "parent_id"
56 , _node_name = required "name"
57 , _node_date = optional "date"
58
59 , _node_hyperdata = required "hyperdata"
60 -- ignoring ts_vector field here
61 }
62 )
63
64 queryNodeTable :: Query NodeRead
65 queryNodeTable = queryTable nodeTable
66 ------------------------------------------------------------------------
67 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
68 (Column PGInt4)
69 (Column PGInt4)
70 (Maybe (Column PGInt4) )
71 (Column PGText)
72 (Maybe (Column PGTimestamptz))
73 (Column PGJsonb)
74
75 type NodeRead = NodePoly (Column PGInt4 )
76 (Column PGInt4 )
77 (Column PGInt4 )
78 (Column PGInt4 )
79 (Column PGText )
80 (Column PGTimestamptz )
81 (Column PGJsonb )
82
83 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
84 (Column (Nullable PGInt4))
85 (Column (Nullable PGInt4))
86 (Column (Nullable PGInt4))
87 (Column (Nullable PGText))
88 (Column (Nullable PGTimestamptz))
89 (Column (Nullable PGJsonb))
90
91 ------------------------------------------------------------------------
92 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
93 -- for full text search only
94 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
95 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
96 , _ns_typename = required "typename"
97 , _ns_userId = required "user_id"
98
99 , _ns_parentId = required "parent_id"
100 , _ns_name = required "name"
101 , _ns_date = optional "date"
102
103 , _ns_hyperdata = required "hyperdata"
104 , _ns_search = optional "search"
105 }
106 )
107
108
109
110 type NodeSearchWrite =
111 NodePolySearch
112 (Maybe (Column PGInt4) )
113 (Column PGInt4 )
114 (Column PGInt4 )
115 (Column (Nullable PGInt4) )
116 (Column PGText )
117 (Maybe (Column PGTimestamptz))
118 (Column PGJsonb )
119 (Maybe (Column PGTSVector) )
120
121 type NodeSearchRead =
122 NodePolySearch
123 (Column PGInt4 )
124 (Column PGInt4 )
125 (Column PGInt4 )
126 (Column (Nullable PGInt4 ))
127 (Column PGText )
128 (Column PGTimestamptz )
129 (Column PGJsonb )
130 (Column PGTSVector )
131
132 type NodeSearchReadNull =
133 NodePolySearch
134 (Column (Nullable PGInt4) )
135 (Column (Nullable PGInt4) )
136 (Column (Nullable PGInt4) )
137 (Column (Nullable PGInt4) )
138 (Column (Nullable PGText) )
139 (Column (Nullable PGTimestamptz))
140 (Column (Nullable PGJsonb) )
141 (Column (Nullable PGTSVector) )
142
143 ------------------------------------------------------------------------
144 ------------------------------------------------------------------------
145 -- Instances
146 ------------------------------------------------------------------------
147
148 instance FromField HyperdataAny where
149 fromField = fromField'
150
151 instance FromField HyperdataCorpus
152 where
153 fromField = fromField'
154
155 instance FromField HyperdataDocument
156 where
157 fromField = fromField'
158
159 instance FromField HyperdataDocumentV3
160 where
161 fromField = fromField'
162
163 instance FromField HyperData
164 where
165 fromField = fromField'
166
167 instance FromField HyperdataListModel
168 where
169 fromField = fromField'
170
171 instance FromField HyperdataGraph
172 where
173 fromField = fromField'
174
175 instance FromField HyperdataPhylo
176 where
177 fromField = fromField'
178
179 instance FromField HyperdataAnnuaire
180 where
181 fromField = fromField'
182
183 instance FromField HyperdataList
184 where
185 fromField = fromField'
186
187 instance FromField (NodeId, Text)
188 where
189 fromField = fromField'
190 ------------------------------------------------------------------------
191 instance QueryRunnerColumnDefault PGJsonb HyperdataAny
192 where
193 queryRunnerColumnDefault = fieldQueryRunnerColumn
194
195 instance QueryRunnerColumnDefault PGJsonb HyperdataList
196 where
197 queryRunnerColumnDefault = fieldQueryRunnerColumn
198
199 instance QueryRunnerColumnDefault PGJsonb HyperData
200 where
201 queryRunnerColumnDefault = fieldQueryRunnerColumn
202
203
204 instance QueryRunnerColumnDefault PGJsonb HyperdataDocument
205 where
206 queryRunnerColumnDefault = fieldQueryRunnerColumn
207
208 instance QueryRunnerColumnDefault PGJsonb HyperdataDocumentV3
209 where
210 queryRunnerColumnDefault = fieldQueryRunnerColumn
211
212 instance QueryRunnerColumnDefault PGJsonb HyperdataCorpus
213 where
214 queryRunnerColumnDefault = fieldQueryRunnerColumn
215
216 instance QueryRunnerColumnDefault PGJsonb HyperdataListModel
217 where
218 queryRunnerColumnDefault = fieldQueryRunnerColumn
219
220 instance QueryRunnerColumnDefault PGJsonb HyperdataGraph
221 where
222 queryRunnerColumnDefault = fieldQueryRunnerColumn
223
224 instance QueryRunnerColumnDefault PGJsonb HyperdataPhylo
225 where
226 queryRunnerColumnDefault = fieldQueryRunnerColumn
227
228 instance QueryRunnerColumnDefault PGJsonb HyperdataAnnuaire
229 where
230 queryRunnerColumnDefault = fieldQueryRunnerColumn
231
232 instance QueryRunnerColumnDefault PGTSVector (Maybe TSVector)
233 where
234 queryRunnerColumnDefault = fieldQueryRunnerColumn
235
236 instance QueryRunnerColumnDefault PGInt4 (Maybe NodeId)
237 where
238 queryRunnerColumnDefault = fieldQueryRunnerColumn
239
240 instance QueryRunnerColumnDefault PGInt4 NodeId
241 where
242 queryRunnerColumnDefault = fieldQueryRunnerColumn
243
244 instance QueryRunnerColumnDefault (Nullable PGInt4) NodeId
245 where
246 queryRunnerColumnDefault = fieldQueryRunnerColumn
247
248
249