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
11 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE ConstraintKinds #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE TemplateHaskell #-}
18 {-# LANGUAGE TypeFamilies #-}
20 module Gargantext.Database.Schema.Node where
22 import Control.Lens hiding (elements, (&))
23 import Gargantext.Database.Schema.Prelude
24 import Prelude hiding (null, id, map, sum)
26 ------------------------------------------------------------------------
27 -- Main polymorphic Node definition
36 Node { _node_id :: !id
37 , _node_typename :: !typename
39 , _node_userId :: !userId
40 , _node_parentId :: !parentId
45 , _node_hyperdata :: !hyperdata
46 } deriving (Show, Generic)
48 ------------------------------------------------------------------------
49 -- Automatic instances derivation
50 $(deriveJSON (unPrefix "_node_") ''NodePoly)
51 $(makeLenses ''NodePoly)
53 $(makeAdaptorAndInstance "pNode" ''NodePoly)
54 $(makeLensesWith abbreviatedFields ''NodePoly)
56 ------------------------------------------------------------------------
57 nodeTable :: Table NodeWrite NodeRead
58 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
59 , _node_typename = required "typename"
60 , _node_userId = required "user_id"
62 , _node_parentId = optional "parent_id"
63 , _node_name = required "name"
64 , _node_date = optional "date"
66 , _node_hyperdata = required "hyperdata"
67 -- ignoring ts_vector field here
71 queryNodeTable :: Query NodeRead
72 queryNodeTable = queryTable nodeTable
73 ------------------------------------------------------------------------
74 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
77 (Maybe (Column PGInt4) )
79 (Maybe (Column PGTimestamptz))
82 type NodeRead = NodePoly (Column PGInt4 )
87 (Column PGTimestamptz )
90 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
91 (Column (Nullable PGInt4))
92 (Column (Nullable PGInt4))
93 (Column (Nullable PGInt4))
94 (Column (Nullable PGText))
95 (Column (Nullable PGTimestamptz))
96 (Column (Nullable PGJsonb))
97 ------------------------------------------------------------------------
98 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
99 -- for full text search only
101 type NodeSearchWrite =
103 (Maybe (Column PGInt4) )
106 (Column (Nullable PGInt4) )
108 (Maybe (Column PGTimestamptz))
110 (Maybe (Column PGTSVector) )
112 type NodeSearchRead =
117 (Column (Nullable PGInt4 ))
119 (Column PGTimestamptz )
123 type NodeSearchReadNull =
125 (Column (Nullable PGInt4) )
126 (Column (Nullable PGInt4) )
127 (Column (Nullable PGInt4) )
128 (Column (Nullable PGInt4) )
129 (Column (Nullable PGText) )
130 (Column (Nullable PGTimestamptz))
131 (Column (Nullable PGJsonb) )
132 (Column (Nullable PGTSVector) )
135 data NodePolySearch id
143 NodeSearch { _ns_id :: id
144 , _ns_typename :: typename
145 , _ns_userId :: userId
146 -- , nodeUniqId :: shaId
147 , _ns_parentId :: parentId
151 , _ns_hyperdata :: hyperdata
152 , _ns_search :: search
153 } deriving (Show, Generic)
155 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
156 $(makeLensesWith abbreviatedFields ''NodePolySearch)
157 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
158 $(makeLenses ''NodePolySearch)
160 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
161 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
162 , _ns_typename = required "typename"
163 , _ns_userId = required "user_id"
165 , _ns_parentId = required "parent_id"
166 , _ns_name = required "name"
167 , _ns_date = optional "date"
169 , _ns_hyperdata = required "hyperdata"
170 , _ns_search = optional "search"
173 ------------------------------------------------------------------------