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
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_hash_id :: !hash_id
38 , _node_typename :: !typename
40 , _node_user_id :: !user_id
41 , _node_parent_id :: !parent_id
46 , _node_hyperdata :: !hyperdata
47 } deriving (Show, Generic)
49 ------------------------------------------------------------------------
50 -- Automatic instances derivation
51 $(deriveJSON (unPrefix "_node_") ''NodePoly)
52 $(makeLenses ''NodePoly)
54 $(makeAdaptorAndInstance "pNode" ''NodePoly)
55 $(makeLensesWith abbreviatedFields ''NodePoly)
57 nodeTable :: Table NodeWrite NodeRead
58 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
59 , _node_hash_id = optional "hash_id"
60 , _node_typename = required "typename"
61 , _node_user_id = required "user_id"
63 , _node_parent_id = optional "parent_id"
64 , _node_name = required "name"
65 , _node_date = optional "date"
67 , _node_hyperdata = required "hyperdata"
68 -- ignoring ts_vector field here
72 queryNodeTable :: Query NodeRead
73 queryNodeTable = queryTable nodeTable
74 ------------------------------------------------------------------------
75 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
76 (Maybe (Column PGText) )
79 (Maybe (Column PGInt4) )
81 (Maybe (Column PGTimestamptz))
84 type NodeRead = NodePoly (Column PGInt4 )
90 (Column PGTimestamptz )
93 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
94 (Column (Nullable PGText))
95 (Column (Nullable PGInt4))
96 (Column (Nullable PGInt4))
97 (Column (Nullable PGInt4))
98 (Column (Nullable PGText))
99 (Column (Nullable PGTimestamptz))
100 (Column (Nullable PGJsonb))
101 ------------------------------------------------------------------------
102 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
103 -- for full text search only
105 type NodeSearchWrite =
107 (Maybe (Column PGInt4) )
110 (Column (Nullable PGInt4) )
112 (Maybe (Column PGTimestamptz))
114 (Maybe (Column PGTSVector) )
116 type NodeSearchRead =
121 (Column (Nullable PGInt4 ))
123 (Column PGTimestamptz )
127 type NodeSearchReadNull =
129 (Column (Nullable PGInt4) )
130 (Column (Nullable PGInt4) )
131 (Column (Nullable PGInt4) )
132 (Column (Nullable PGInt4) )
133 (Column (Nullable PGText) )
134 (Column (Nullable PGTimestamptz))
135 (Column (Nullable PGJsonb) )
136 (Column (Nullable PGTSVector) )
139 data NodePolySearch id
147 NodeSearch { _ns_id :: id
148 , _ns_typename :: typename
149 , _ns_user_id :: user_id
150 -- , nodeUniqId :: shaId
151 , _ns_parent_id :: parent_id
155 , _ns_hyperdata :: hyperdata
156 , _ns_search :: search
157 , _ns_search_title :: search
158 } deriving (Show, Generic)
160 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
161 $(makeLensesWith abbreviatedFields ''NodePolySearch)
162 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
163 $(makeLenses ''NodePolySearch)
165 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
166 nodeTableSearch = Table "nodes" ( pNodeSearch
167 NodeSearch { _ns_id = optional "id"
168 , _ns_typename = required "typename"
169 , _ns_user_id = required "user_id"
171 , _ns_parent_id = required "parent_id"
172 , _ns_name = required "name"
173 , _ns_date = optional "date"
175 , _ns_hyperdata = required "hyperdata"
176 , _ns_search = optional "search"
177 , _ns_search_title = optional "search_title"
180 ------------------------------------------------------------------------