]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/Node.hs
[ngrams] add r_history %~ mempty to ngrams POST
[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 ConstraintKinds #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE TemplateHaskell #-}
18 {-# LANGUAGE TypeFamilies #-}
19
20 module Gargantext.Database.Schema.Node where
21
22 import Control.Lens hiding (elements, (&))
23 import Gargantext.Database.Schema.Prelude
24 import Prelude hiding (null, id, map, sum)
25
26 ------------------------------------------------------------------------
27 -- Main polymorphic Node definition
28 data NodePoly id
29 typename
30 userId
31 parentId
32 name
33 date
34 hyperdata =
35 Node { _node_id :: !id
36 , _node_typename :: !typename
37
38 , _node_userId :: !userId
39 , _node_parentId :: !parentId
40
41 , _node_name :: !name
42 , _node_date :: !date
43
44 , _node_hyperdata :: !hyperdata
45 } deriving (Show, Generic)
46
47 ------------------------------------------------------------------------
48 -- Automatic instances derivation
49 $(deriveJSON (unPrefix "_node_") ''NodePoly)
50 $(makeLenses ''NodePoly)
51
52 $(makeAdaptorAndInstance "pNode" ''NodePoly)
53 $(makeLensesWith abbreviatedFields ''NodePoly)
54
55 nodeTable :: Table NodeWrite NodeRead
56 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
57 , _node_typename = required "typename"
58 , _node_userId = required "user_id"
59
60 , _node_parentId = optional "parent_id"
61 , _node_name = required "name"
62 , _node_date = optional "date"
63
64 , _node_hyperdata = required "hyperdata"
65 -- ignoring ts_vector field here
66 }
67 )
68
69 queryNodeTable :: Query NodeRead
70 queryNodeTable = queryTable nodeTable
71 ------------------------------------------------------------------------
72 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
73 (Column PGInt4)
74 (Column PGInt4)
75 (Maybe (Column PGInt4) )
76 (Column PGText)
77 (Maybe (Column PGTimestamptz))
78 (Column PGJsonb)
79
80 type NodeRead = NodePoly (Column PGInt4 )
81 (Column PGInt4 )
82 (Column PGInt4 )
83 (Column PGInt4 )
84 (Column PGText )
85 (Column PGTimestamptz )
86 (Column PGJsonb )
87
88 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
89 (Column (Nullable PGInt4))
90 (Column (Nullable PGInt4))
91 (Column (Nullable PGInt4))
92 (Column (Nullable PGText))
93 (Column (Nullable PGTimestamptz))
94 (Column (Nullable PGJsonb))
95 ------------------------------------------------------------------------
96 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
97 -- for full text search only
98
99 type NodeSearchWrite =
100 NodePolySearch
101 (Maybe (Column PGInt4) )
102 (Column PGInt4 )
103 (Column PGInt4 )
104 (Column (Nullable PGInt4) )
105 (Column PGText )
106 (Maybe (Column PGTimestamptz))
107 (Column PGJsonb )
108 (Maybe (Column PGTSVector) )
109
110 type NodeSearchRead =
111 NodePolySearch
112 (Column PGInt4 )
113 (Column PGInt4 )
114 (Column PGInt4 )
115 (Column (Nullable PGInt4 ))
116 (Column PGText )
117 (Column PGTimestamptz )
118 (Column PGJsonb )
119 (Column PGTSVector )
120
121 type NodeSearchReadNull =
122 NodePolySearch
123 (Column (Nullable PGInt4) )
124 (Column (Nullable PGInt4) )
125 (Column (Nullable PGInt4) )
126 (Column (Nullable PGInt4) )
127 (Column (Nullable PGText) )
128 (Column (Nullable PGTimestamptz))
129 (Column (Nullable PGJsonb) )
130 (Column (Nullable PGTSVector) )
131
132
133 data NodePolySearch id
134 typename
135 userId
136 parentId
137 name
138 date
139 hyperdata
140 search =
141 NodeSearch { _ns_id :: id
142 , _ns_typename :: typename
143 , _ns_userId :: userId
144 -- , nodeUniqId :: shaId
145 , _ns_parentId :: parentId
146 , _ns_name :: name
147 , _ns_date :: date
148
149 , _ns_hyperdata :: hyperdata
150 , _ns_search :: search
151 } deriving (Show, Generic)
152
153 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
154 $(makeLensesWith abbreviatedFields ''NodePolySearch)
155 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
156 $(makeLenses ''NodePolySearch)
157
158 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
159 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
160 , _ns_typename = required "typename"
161 , _ns_userId = required "user_id"
162
163 , _ns_parentId = required "parent_id"
164 , _ns_name = required "name"
165 , _ns_date = optional "date"
166
167 , _ns_hyperdata = required "hyperdata"
168 , _ns_search = optional "search"
169 }
170 )
171 ------------------------------------------------------------------------