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.TH (makeLensesWith, abbreviatedFields)
30 import Data.Maybe (Maybe(..))
31 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
32 import Data.Text (Text)
33 import Database.PostgreSQL.Simple.FromField (FromField, fromField)
34 import Gargantext.Core.Types
35 import Gargantext.Database.Admin.Utils
36 import Gargantext.Viz.Graph (HyperdataGraph(..))
37 import Opaleye hiding (FromField)
38 import Opaleye.Internal.QueryArr (Query)
39 import Prelude hiding (null, id, map, sum)
41 ------------------------------------------------------------------------
43 $(makeAdaptorAndInstance "pNode" ''NodePoly)
44 $(makeLensesWith abbreviatedFields ''NodePoly)
46 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
47 $(makeLensesWith abbreviatedFields ''NodePolySearch)
49 ------------------------------------------------------------------------
50 nodeTable :: Table NodeWrite NodeRead
51 nodeTable = Table "nodes" (pNode Node { _node_id = optional "id"
52 , _node_typename = required "typename"
53 , _node_userId = required "user_id"
55 , _node_parentId = optional "parent_id"
56 , _node_name = required "name"
57 , _node_date = optional "date"
59 , _node_hyperdata = required "hyperdata"
60 -- ignoring ts_vector field here
64 queryNodeTable :: Query NodeRead
65 queryNodeTable = queryTable nodeTable
66 ------------------------------------------------------------------------
67 type NodeWrite = NodePoly (Maybe (Column PGInt4) )
70 (Maybe (Column PGInt4) )
72 (Maybe (Column PGTimestamptz))
75 type NodeRead = NodePoly (Column PGInt4 )
80 (Column PGTimestamptz )
83 type NodeReadNull = NodePoly (Column (Nullable PGInt4))
84 (Column (Nullable PGInt4))
85 (Column (Nullable PGInt4))
86 (Column (Nullable PGInt4))
87 (Column (Nullable PGText))
88 (Column (Nullable PGTimestamptz))
89 (Column (Nullable PGJsonb))
91 ------------------------------------------------------------------------
92 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
93 -- for full text search only
94 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
95 nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id = optional "id"
96 , _ns_typename = required "typename"
97 , _ns_userId = required "user_id"
99 , _ns_parentId = required "parent_id"
100 , _ns_name = required "name"
101 , _ns_date = optional "date"
103 , _ns_hyperdata = required "hyperdata"
104 , _ns_search = optional "search"
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) )
143 ------------------------------------------------------------------------
144 ------------------------------------------------------------------------
146 ------------------------------------------------------------------------
148 instance FromField HyperdataAny where
149 fromField = fromField'
151 instance FromField HyperdataCorpus
153 fromField = fromField'
155 instance FromField HyperdataDocument
157 fromField = fromField'
159 instance FromField HyperdataDocumentV3
161 fromField = fromField'
163 instance FromField HyperData
165 fromField = fromField'
167 instance FromField HyperdataListModel
169 fromField = fromField'
171 instance FromField HyperdataGraph
173 fromField = fromField'
175 instance FromField HyperdataPhylo
177 fromField = fromField'
179 instance FromField HyperdataAnnuaire
181 fromField = fromField'
183 instance FromField HyperdataList
185 fromField = fromField'
187 instance FromField (NodeId, Text)
189 fromField = fromField'
190 ------------------------------------------------------------------------
191 instance QueryRunnerColumnDefault PGJsonb HyperdataAny
193 queryRunnerColumnDefault = fieldQueryRunnerColumn
195 instance QueryRunnerColumnDefault PGJsonb HyperdataList
197 queryRunnerColumnDefault = fieldQueryRunnerColumn
199 instance QueryRunnerColumnDefault PGJsonb HyperData
201 queryRunnerColumnDefault = fieldQueryRunnerColumn
204 instance QueryRunnerColumnDefault PGJsonb HyperdataDocument
206 queryRunnerColumnDefault = fieldQueryRunnerColumn
208 instance QueryRunnerColumnDefault PGJsonb HyperdataDocumentV3
210 queryRunnerColumnDefault = fieldQueryRunnerColumn
212 instance QueryRunnerColumnDefault PGJsonb HyperdataCorpus
214 queryRunnerColumnDefault = fieldQueryRunnerColumn
216 instance QueryRunnerColumnDefault PGJsonb HyperdataListModel
218 queryRunnerColumnDefault = fieldQueryRunnerColumn
220 instance QueryRunnerColumnDefault PGJsonb HyperdataGraph
222 queryRunnerColumnDefault = fieldQueryRunnerColumn
224 instance QueryRunnerColumnDefault PGJsonb HyperdataPhylo
226 queryRunnerColumnDefault = fieldQueryRunnerColumn
228 instance QueryRunnerColumnDefault PGJsonb HyperdataAnnuaire
230 queryRunnerColumnDefault = fieldQueryRunnerColumn
232 instance QueryRunnerColumnDefault PGTSVector (Maybe TSVector)
234 queryRunnerColumnDefault = fieldQueryRunnerColumn
236 instance QueryRunnerColumnDefault PGInt4 (Maybe NodeId)
238 queryRunnerColumnDefault = fieldQueryRunnerColumn
240 instance QueryRunnerColumnDefault PGInt4 NodeId
242 queryRunnerColumnDefault = fieldQueryRunnerColumn
244 instance QueryRunnerColumnDefault (Nullable PGInt4) NodeId
246 queryRunnerColumnDefault = fieldQueryRunnerColumn