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 Data.Text (Text)
31 import Gargantext.Database.Admin.Utils
32 import Gargantext.Database.Schema.Prelude
33 import Prelude hiding (null, id, map, sum)
35 ------------------------------------------------------------------------
36 -- Main polymorphic Node definition
45 Node { _node_id :: !id
46 , _node_typename :: !typename
48 , _node_userId :: !userId
49 , _node_parentId :: !parentId
54 , _node_hyperdata :: !hyperdata
55 } deriving (Show, Generic)
57 ------------------------------------------------------------------------
58 -- Automatic instances derivation
59 $(deriveJSON (unPrefix "_node_") ''NodePoly)
60 $(makeLenses ''NodePoly)
62 $(makeAdaptorAndInstance "pNode" ''NodePoly)
63 $(makeLensesWith abbreviatedFields ''NodePoly)
65 ------------------------------------------------------------------------
66 nodeTable :: Table NodeWrite NodeRead
67 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
68 , _node_typename = required "typename"
69 , _node_userId = required "user_id"
71 , _node_parentId = optional "parent_id"
72 , _node_name = required "name"
73 , _node_date = optional "date"
75 , _node_hyperdata = required "hyperdata"
76 -- ignoring ts_vector field here
80 queryNodeTable :: Query NodeRead
81 queryNodeTable = queryTable nodeTable
82 ------------------------------------------------------------------------
83 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
86 (Maybe (Column PGInt4) )
88 (Maybe (Column PGTimestamptz))
91 type NodeRead = NodePoly (Column PGInt4 )
96 (Column PGTimestamptz )
99 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
100 (Column (Nullable PGInt4))
101 (Column (Nullable PGInt4))
102 (Column (Nullable PGInt4))
103 (Column (Nullable PGText))
104 (Column (Nullable PGTimestamptz))
105 (Column (Nullable PGJsonb))
106 ------------------------------------------------------------------------
107 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
108 -- for full text search only
110 type NodeSearchWrite =
112 (Maybe (Column PGInt4) )
115 (Column (Nullable PGInt4) )
117 (Maybe (Column PGTimestamptz))
119 (Maybe (Column PGTSVector) )
121 type NodeSearchRead =
126 (Column (Nullable PGInt4 ))
128 (Column PGTimestamptz )
132 type NodeSearchReadNull =
134 (Column (Nullable PGInt4) )
135 (Column (Nullable PGInt4) )
136 (Column (Nullable PGInt4) )
137 (Column (Nullable PGInt4) )
138 (Column (Nullable PGText) )
139 (Column (Nullable PGTimestamptz))
140 (Column (Nullable PGJsonb) )
141 (Column (Nullable PGTSVector) )
144 data NodePolySearch id
152 NodeSearch { _ns_id :: id
153 , _ns_typename :: typename
154 , _ns_userId :: userId
155 -- , nodeUniqId :: shaId
156 , _ns_parentId :: parentId
160 , _ns_hyperdata :: hyperdata
161 , _ns_search :: search
162 } deriving (Show, Generic)
164 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
165 $(makeLensesWith abbreviatedFields ''NodePolySearch)
166 $(deriveJSON (unPrefix "_ns_") ''NodePolySearch)
167 $(makeLenses ''NodePolySearch)
169 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
170 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
171 , _ns_typename = required "typename"
172 , _ns_userId = required "user_id"
174 , _ns_parentId = required "parent_id"
175 , _ns_name = required "name"
176 , _ns_date = optional "date"
178 , _ns_hyperdata = required "hyperdata"
179 , _ns_search = optional "search"
182 ------------------------------------------------------------------------