1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{-|
Module : Gargantext.Database.Schema.Node
Description : Main requests of Node to the database
Copyright : (c) CNRS, 2017-Present
License : AGPL + CECILL v3
Maintainer : team@gargantext.org
Stability : experimental
Portability : POSIX
-}
{-# LANGUAGE Arrows #-}
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE TypeFamilies #-}
module Gargantext.Database.Schema.Context where
import Control.Lens hiding (elements, (&), Context)
import Gargantext.Database.Schema.Prelude
import Prelude hiding (null, id, map, sum)
------------------------------------------------------------------------
-- Main polymorphic Node definition
data ContextPoly id
hash_id
typename
user_id
parent_id
name
date
hyperdata =
Context { _context_id :: !id
, _context_hash_id :: !hash_id
, _context_typename :: !typename
, _context_user_id :: !user_id
, _context_parent_id :: !parent_id
, _context_name :: !name
, _context_date :: !date
, _context_hyperdata :: !hyperdata
} deriving (Show, Generic)
------------------------------------------------------------------------
-- Automatic instances derivation
$(deriveJSON (unPrefix "_context_") ''ContextPoly)
$(makeLenses ''ContextPoly)
$(makeAdaptorAndInstance "pContext" ''ContextPoly)
$(makeLensesWith abbreviatedFields ''ContextPoly)
contextTable :: Table ContextWrite ContextRead
contextTable = Table "contexts" (pContext Context { _context_id = optionalTableField "id"
, _context_hash_id = optionalTableField "hash_id"
, _context_typename = requiredTableField "typename"
, _context_user_id = requiredTableField "user_id"
, _context_parent_id = optionalTableField "parent_id"
, _context_name = requiredTableField "name"
, _context_date = optionalTableField "date"
, _context_hyperdata = requiredTableField "hyperdata"
-- ignoring ts_vector field here
}
)
queryContextTable :: Query ContextRead
queryContextTable = selectTable contextTable
------------------------------------------------------------------------
type ContextWrite = ContextPoly (Maybe (Field SqlInt4) )
(Maybe (Field SqlText) )
(Field SqlInt4)
(Field SqlInt4)
(Maybe (Field SqlInt4) )
(Field SqlText)
(Maybe (Field SqlTimestamptz))
(Field SqlJsonb)
type ContextRead = ContextPoly (Field SqlInt4 )
(Field SqlText )
(Field SqlInt4 )
(Field SqlInt4 )
(Field SqlInt4 )
(Field SqlText )
(Field SqlTimestamptz )
(Field SqlJsonb )
------------------------------------------------------------------------
-- | Context(Read|Write)Search is slower than Context(Write|Read) use it
-- for full text search only
type ContextSearchWrite =
ContextPolySearch
(Maybe (Field SqlInt4) )
(Field SqlInt4 )
(Field SqlInt4 )
(FieldNullable SqlInt4)
(Field SqlText )
(Maybe (Field SqlTimestamptz))
(Field SqlJsonb )
(Maybe (Field SqlTSVector) )
type ContextSearchRead =
ContextPolySearch
(Field SqlInt4 )
(Field SqlInt4 )
(Field SqlInt4 )
(FieldNullable SqlInt4 )
(Field SqlText )
(Field SqlTimestamptz )
(Field SqlJsonb )
(Field SqlTSVector )
data ContextPolySearch id
typename
user_id
parent_id
name
date
hyperdata
search =
ContextSearch { _cs_id :: id
, _cs_typename :: typename
, _cs_user_id :: user_id
-- , ContextUniqId :: shaId
, _cs_parent_id :: parent_id
, _cs_name :: name
, _cs_date :: date
, _cs_hyperdata :: hyperdata
, _cs_search :: search
} deriving (Show, Generic)
$(makeAdaptorAndInstance "pContextSearch" ''ContextPolySearch)
$(makeLensesWith abbreviatedFields ''ContextPolySearch)
$(deriveJSON (unPrefix "_cs_") ''ContextPolySearch)
$(makeLenses ''ContextPolySearch)
contextTableSearch :: Table ContextSearchWrite ContextSearchRead
contextTableSearch = Table "contexts" ( pContextSearch
ContextSearch { _cs_id = optionalTableField "id"
, _cs_typename = requiredTableField "typename"
, _cs_user_id = requiredTableField "user_id"
, _cs_parent_id = requiredTableField "parent_id"
, _cs_name = requiredTableField "name"
, _cs_date = optionalTableField "date"
, _cs_hyperdata = requiredTableField "hyperdata"
, _cs_search = optionalTableField "search"
}
)
------------------------------------------------------------------------