]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/Node.hs
[DB/FACTO] G.D.S.Prelude (with issue)
[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 hiding (elements, (&))
30 import Data.Text (Text)
31 import Gargantext.Database.Admin.Utils
32 import Gargantext.Database.Schema.Prelude
33 import Prelude hiding (null, id, map, sum)
34
35 ------------------------------------------------------------------------
36 -- Main polymorphic Node definition
37
38 data NodePoly id
39 typename
40 userId
41 parentId
42 name
43 date
44 hyperdata =
45 Node { _node_id :: !id
46 , _node_typename :: !typename
47
48 , _node_userId :: !userId
49 , _node_parentId :: !parentId
50
51 , _node_name :: !name
52 , _node_date :: !date
53
54 , _node_hyperdata :: !hyperdata
55 } deriving (Show, Generic)
56
57 ------------------------------------------------------------------------
58 -- Automatic instances derivation
59 $(deriveJSON (unPrefix "_node_") ''NodePoly)
60 $(makeLenses ''NodePoly)
61
62 $(makeAdaptorAndInstance "pNode" ''NodePoly)
63 $(makeLensesWith abbreviatedFields ''NodePoly)
64
65 ------------------------------------------------------------------------
66 nodeTable :: Table NodeWrite NodeRead
67 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
68 , _node_typename = required "typename"
69 , _node_userId = required "user_id"
70
71 , _node_parentId = optional "parent_id"
72 , _node_name = required "name"
73 , _node_date = optional "date"
74
75 , _node_hyperdata = required "hyperdata"
76 -- ignoring ts_vector field here
77 }
78 )
79
80 queryNodeTable :: Query NodeRead
81 queryNodeTable = queryTable nodeTable
82 ------------------------------------------------------------------------
83 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
84 (Column PGInt4)
85 (Column PGInt4)
86 (Maybe (Column PGInt4) )
87 (Column PGText)
88 (Maybe (Column PGTimestamptz))
89 (Column PGJsonb)
90
91 type NodeRead = NodePoly (Column PGInt4 )
92 (Column PGInt4 )
93 (Column PGInt4 )
94 (Column PGInt4 )
95 (Column PGText )
96 (Column PGTimestamptz )
97 (Column PGJsonb )
98
99 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
100 (Column (Nullable PGInt4))
101 (Column (Nullable PGInt4))
102 (Column (Nullable PGInt4))
103 (Column (Nullable PGText))
104 (Column (Nullable PGTimestamptz))
105 (Column (Nullable PGJsonb))
106 ------------------------------------------------------------------------
107 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
108 -- for full text search only
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 data NodePolySearch id
145 typename
146 userId
147 parentId
148 name
149 date
150 hyperdata
151 search =
152 NodeSearch { _ns_id :: id
153 , _ns_typename :: typename
154 , _ns_userId :: userId
155 -- , nodeUniqId :: shaId
156 , _ns_parentId :: parentId
157 , _ns_name :: name
158 , _ns_date :: date
159
160 , _ns_hyperdata :: hyperdata
161 , _ns_search :: search
162 } deriving (Show, Generic)
163
164 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
165 $(makeLensesWith abbreviatedFields ''NodePolySearch)
166 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
167 $(makeLenses ''NodePolySearch)
168
169 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
170 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
171 , _ns_typename = required "typename"
172 , _ns_userId = required "user_id"
173
174 , _ns_parentId = required "parent_id"
175 , _ns_name = required "name"
176 , _ns_date = optional "date"
177
178 , _ns_hyperdata = required "hyperdata"
179 , _ns_search = optional "search"
180 }
181 )
182 ------------------------------------------------------------------------