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
35 Node { _node_id :: !id
36 , _node_typename :: !typename
38 , _node_userId :: !userId
39 , _node_parentId :: !parentId
44 , _node_hyperdata :: !hyperdata
45 } deriving (Show, Generic)
47 ------------------------------------------------------------------------
48 -- Automatic instances derivation
49 $(deriveJSON (unPrefix "_node_") ''NodePoly)
50 $(makeLenses ''NodePoly)
52 $(makeAdaptorAndInstance "pNode" ''NodePoly)
53 $(makeLensesWith abbreviatedFields ''NodePoly)
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"
60 , _node_parentId = optional "parent_id"
61 , _node_name = required "name"
62 , _node_date = optional "date"
64 , _node_hyperdata = required "hyperdata"
65 -- ignoring ts_vector field here
69 queryNodeTable :: Query NodeRead
70 queryNodeTable = queryTable nodeTable
71 ------------------------------------------------------------------------
72 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
75 (Maybe (Column PGInt4) )
77 (Maybe (Column PGTimestamptz))
80 type NodeRead = NodePoly (Column PGInt4 )
85 (Column PGTimestamptz )
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
99 type NodeSearchWrite =
101 (Maybe (Column PGInt4) )
104 (Column (Nullable PGInt4) )
106 (Maybe (Column PGTimestamptz))
108 (Maybe (Column PGTSVector) )
110 type NodeSearchRead =
115 (Column (Nullable PGInt4 ))
117 (Column PGTimestamptz )
121 type NodeSearchReadNull =
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) )
133 data NodePolySearch id
141 NodeSearch { _ns_id :: id
142 , _ns_typename :: typename
143 , _ns_userId :: userId
144 -- , nodeUniqId :: shaId
145 , _ns_parentId :: parentId
149 , _ns_hyperdata :: hyperdata
150 , _ns_search :: search
151 } deriving (Show, Generic)
153 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
154 $(makeLensesWith abbreviatedFields ''NodePolySearch)
155 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
156 $(makeLenses ''NodePolySearch)
158 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
159 nodeTableSearch = Table "nodes" ( pNodeSearch
160 NodeSearch { _ns_id = optional "id"
161 , _ns_typename = required "typename"
162 , _ns_userId = required "user_id"
164 , _ns_parentId = required "parent_id"
165 , _ns_name = required "name"
166 , _ns_date = optional "date"
168 , _ns_hyperdata = required "hyperdata"
169 , _ns_search = optional "search"
172 ------------------------------------------------------------------------