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 = optionalTableField "id"
59 , _node_hash_id = optionalTableField "hash_id"
60 , _node_typename = requiredTableField "typename"
61 , _node_user_id = requiredTableField "user_id"
63 , _node_parent_id = optionalTableField "parent_id"
64 , _node_name = requiredTableField "name"
65 , _node_date = optionalTableField "date"
67 , _node_hyperdata = requiredTableField "hyperdata"
68 -- ignoring ts_vector field here
72 queryNodeTable :: Query NodeRead
73 queryNodeTable = selectTable nodeTable
74 ------------------------------------------------------------------------
75 type NodeWrite = NodePoly (Maybe (Field SqlInt4) )
76 (Maybe (Field SqlText) )
79 (Maybe (Field SqlInt4) )
81 (Maybe (Field SqlTimestamptz))
84 type NodeRead = NodePoly (Field SqlInt4 )
90 (Field SqlTimestamptz )
92 ------------------------------------------------------------------------
93 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
94 -- for full text search only
96 type NodeSearchWrite =
98 (Maybe (Field SqlInt4) )
101 (FieldNullable SqlInt4)
103 (Maybe (Field SqlTimestamptz))
105 (Maybe (Field SqlTSVector) )
107 type NodeSearchRead =
112 (FieldNullable SqlInt4 )
114 (Field SqlTimestamptz )
119 data NodePolySearch id
127 NodeSearch { _ns_id :: id
128 , _ns_typename :: typename
129 , _ns_user_id :: user_id
130 -- , nodeUniqId :: shaId
131 , _ns_parent_id :: parent_id
135 , _ns_hyperdata :: hyperdata
136 , _ns_search :: search
137 } deriving (Show, Generic)
139 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
140 $(makeLensesWith abbreviatedFields ''NodePolySearch)
141 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
142 $(makeLenses ''NodePolySearch)
144 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
145 nodeTableSearch = Table "nodes" ( pNodeSearch
146 NodeSearch { _ns_id = optionalTableField "id"
147 , _ns_typename = requiredTableField "typename"
148 , _ns_user_id = requiredTableField "user_id"
150 , _ns_parent_id = requiredTableField "parent_id"
151 , _ns_name = requiredTableField "name"
152 , _ns_date = optionalTableField "date"
154 , _ns_hyperdata = requiredTableField "hyperdata"
155 , _ns_search = optionalTableField "search"
158 ------------------------------------------------------------------------