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 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 #-}
27 module Gargantext.Database.Schema.Node where
29 import Control.Lens hiding (elements, (&))
30 import Gargantext.Database.Schema.Prelude
31 import Prelude hiding (null, id, map, sum)
33 ------------------------------------------------------------------------
34 -- Main polymorphic Node definition
43 Node { _node_id :: !id
44 , _node_typename :: !typename
46 , _node_userId :: !userId
47 , _node_parentId :: !parentId
52 , _node_hyperdata :: !hyperdata
53 } deriving (Show, Generic)
55 ------------------------------------------------------------------------
56 -- Automatic instances derivation
57 $(deriveJSON (unPrefix "_node_") ''NodePoly)
58 $(makeLenses ''NodePoly)
60 $(makeAdaptorAndInstance "pNode" ''NodePoly)
61 $(makeLensesWith abbreviatedFields ''NodePoly)
63 ------------------------------------------------------------------------
64 nodeTable :: Table NodeWrite NodeRead
65 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
66 , _node_typename = required "typename"
67 , _node_userId = required "user_id"
69 , _node_parentId = optional "parent_id"
70 , _node_name = required "name"
71 , _node_date = optional "date"
73 , _node_hyperdata = required "hyperdata"
74 -- ignoring ts_vector field here
78 queryNodeTable :: Query NodeRead
79 queryNodeTable = queryTable nodeTable
80 ------------------------------------------------------------------------
81 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
84 (Maybe (Column PGInt4) )
86 (Maybe (Column PGTimestamptz))
89 type NodeRead = NodePoly (Column PGInt4 )
94 (Column PGTimestamptz )
97 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
98 (Column (Nullable PGInt4))
99 (Column (Nullable PGInt4))
100 (Column (Nullable PGInt4))
101 (Column (Nullable PGText))
102 (Column (Nullable PGTimestamptz))
103 (Column (Nullable PGJsonb))
104 ------------------------------------------------------------------------
105 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
106 -- for full text search only
108 type NodeSearchWrite =
110 (Maybe (Column PGInt4) )
113 (Column (Nullable PGInt4) )
115 (Maybe (Column PGTimestamptz))
117 (Maybe (Column PGTSVector) )
119 type NodeSearchRead =
124 (Column (Nullable PGInt4 ))
126 (Column PGTimestamptz )
130 type NodeSearchReadNull =
132 (Column (Nullable PGInt4) )
133 (Column (Nullable PGInt4) )
134 (Column (Nullable PGInt4) )
135 (Column (Nullable PGInt4) )
136 (Column (Nullable PGText) )
137 (Column (Nullable PGTimestamptz))
138 (Column (Nullable PGJsonb) )
139 (Column (Nullable PGTSVector) )
142 data NodePolySearch id
150 NodeSearch { _ns_id :: id
151 , _ns_typename :: typename
152 , _ns_userId :: userId
153 -- , nodeUniqId :: shaId
154 , _ns_parentId :: parentId
158 , _ns_hyperdata :: hyperdata
159 , _ns_search :: search
160 } deriving (Show, Generic)
162 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
163 $(makeLensesWith abbreviatedFields ''NodePolySearch)
164 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
165 $(makeLenses ''NodePolySearch)
167 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
168 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
169 , _ns_typename = required "typename"
170 , _ns_userId = required "user_id"
172 , _ns_parentId = required "parent_id"
173 , _ns_name = required "name"
174 , _ns_date = optional "date"
176 , _ns_hyperdata = required "hyperdata"
177 , _ns_search = optional "search"
180 ------------------------------------------------------------------------