]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/Node.hs
[RESEARCH] thx to Gabriel Gonzales work n Fibonacci.
[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 instance FromField HyperdataAny where
43 fromField = fromField'
44
45 instance FromField HyperdataCorpus
46 where
47 fromField = fromField'
48
49 instance FromField HyperdataDocument
50 where
51 fromField = fromField'
52
53 instance FromField HyperdataDocumentV3
54 where
55 fromField = fromField'
56
57 instance FromField HyperData
58 where
59 fromField = fromField'
60
61 instance FromField HyperdataListModel
62 where
63 fromField = fromField'
64
65 instance FromField HyperdataGraph
66 where
67 fromField = fromField'
68
69 instance FromField HyperdataPhylo
70 where
71 fromField = fromField'
72
73 instance FromField HyperdataAnnuaire
74 where
75 fromField = fromField'
76
77 instance FromField HyperdataList
78 where
79 fromField = fromField'
80
81 instance FromField (NodeId, Text)
82 where
83 fromField = fromField'
84 ------------------------------------------------------------------------
85 instance QueryRunnerColumnDefault PGJsonb HyperdataAny
86 where
87 queryRunnerColumnDefault = fieldQueryRunnerColumn
88
89 instance QueryRunnerColumnDefault PGJsonb HyperdataList
90 where
91 queryRunnerColumnDefault = fieldQueryRunnerColumn
92
93 instance QueryRunnerColumnDefault PGJsonb HyperData
94 where
95 queryRunnerColumnDefault = fieldQueryRunnerColumn
96
97
98 instance QueryRunnerColumnDefault PGJsonb HyperdataDocument
99 where
100 queryRunnerColumnDefault = fieldQueryRunnerColumn
101
102 instance QueryRunnerColumnDefault PGJsonb HyperdataDocumentV3
103 where
104 queryRunnerColumnDefault = fieldQueryRunnerColumn
105
106 instance QueryRunnerColumnDefault PGJsonb HyperdataCorpus
107 where
108 queryRunnerColumnDefault = fieldQueryRunnerColumn
109
110 instance QueryRunnerColumnDefault PGJsonb HyperdataListModel
111 where
112 queryRunnerColumnDefault = fieldQueryRunnerColumn
113
114 instance QueryRunnerColumnDefault PGJsonb HyperdataGraph
115 where
116 queryRunnerColumnDefault = fieldQueryRunnerColumn
117
118 instance QueryRunnerColumnDefault PGJsonb HyperdataPhylo
119 where
120 queryRunnerColumnDefault = fieldQueryRunnerColumn
121
122 instance QueryRunnerColumnDefault PGJsonb HyperdataAnnuaire
123 where
124 queryRunnerColumnDefault = fieldQueryRunnerColumn
125
126 instance QueryRunnerColumnDefault PGTSVector (Maybe TSVector)
127 where
128 queryRunnerColumnDefault = fieldQueryRunnerColumn
129
130 instance QueryRunnerColumnDefault PGInt4 (Maybe NodeId)
131 where
132 queryRunnerColumnDefault = fieldQueryRunnerColumn
133
134 instance QueryRunnerColumnDefault PGInt4 NodeId
135 where
136 queryRunnerColumnDefault = fieldQueryRunnerColumn
137
138 instance QueryRunnerColumnDefault (Nullable PGInt4) NodeId
139 where
140 queryRunnerColumnDefault = fieldQueryRunnerColumn
141
142
143 ------------------------------------------------------------------------
144 $(makeAdaptorAndInstance "pNode" ''NodePoly)
145 $(makeLensesWith abbreviatedFields ''NodePoly)
146
147 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
148 $(makeLensesWith abbreviatedFields ''NodePolySearch)
149
150 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
151 (Column PGInt4)
152 (Column PGInt4)
153 (Maybe (Column PGInt4) )
154 (Column PGText)
155 (Maybe (Column PGTimestamptz))
156 (Column PGJsonb)
157
158 type NodeRead = NodePoly (Column PGInt4 )
159 (Column PGInt4 )
160 (Column PGInt4 )
161 (Column PGInt4 )
162 (Column PGText )
163 (Column PGTimestamptz )
164 (Column PGJsonb )
165
166 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
167 (Column (Nullable PGInt4))
168 (Column (Nullable PGInt4))
169 (Column (Nullable PGInt4))
170 (Column (Nullable PGText))
171 (Column (Nullable PGTimestamptz))
172 (Column (Nullable PGJsonb))
173
174 nodeTable :: Table NodeWrite NodeRead
175 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
176 , _node_typename = required "typename"
177 , _node_userId = required "user_id"
178
179 , _node_parentId = optional "parent_id"
180 , _node_name = required "name"
181 , _node_date = optional "date"
182
183 , _node_hyperdata = required "hyperdata"
184 }
185 )
186
187 queryNodeTable :: Query NodeRead
188 queryNodeTable = queryTable nodeTable
189
190 ------------------------------------------------------------------------
191 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
192 -- for full text search only
193 type NodeSearchWrite =
194 NodePolySearch
195 (Maybe (Column PGInt4) )
196 (Column PGInt4 )
197 (Column PGInt4 )
198 (Column (Nullable PGInt4) )
199 (Column PGText )
200 (Maybe (Column PGTimestamptz))
201 (Column PGJsonb )
202 (Maybe (Column PGTSVector) )
203
204 type NodeSearchRead =
205 NodePolySearch
206 (Column PGInt4 )
207 (Column PGInt4 )
208 (Column PGInt4 )
209 (Column (Nullable PGInt4 ))
210 (Column PGText )
211 (Column PGTimestamptz )
212 (Column PGJsonb )
213 (Column PGTSVector )
214
215 type NodeSearchReadNull =
216 NodePolySearch
217 (Column (Nullable PGInt4) )
218 (Column (Nullable PGInt4) )
219 (Column (Nullable PGInt4) )
220 (Column (Nullable PGInt4) )
221 (Column (Nullable PGText) )
222 (Column (Nullable PGTimestamptz))
223 (Column (Nullable PGJsonb) )
224 (Column (Nullable PGTSVector) )
225
226 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
227 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
228 , _ns_typename = required "typename"
229 , _ns_userId = required "user_id"
230
231 , _ns_parentId = required "parent_id"
232 , _ns_name = required "name"
233 , _ns_date = optional "date"
234
235 , _ns_hyperdata = required "hyperdata"
236 , _ns_search = optional "search"
237 }
238 )
239
240