]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNodeNgrams.hs
[FIX] Graph concurrency.
[gargantext.git] / src / Gargantext / Database / Schema / NodeNodeNgrams.hs
1 {-|
2 Module : Gargantext.Database.Schema.NodeNodeNgrams
3 Description : TODO: remove this module and table in database
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
8 Portability : POSIX
9
10 -}
11
12 {-# OPTIONS_GHC -fno-warn-orphans #-}
13
14 {-# LANGUAGE Arrows #-}
15 {-# LANGUAGE FlexibleInstances #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE MultiParamTypeClasses #-}
18 {-# LANGUAGE NoImplicitPrelude #-}
19 {-# LANGUAGE RankNTypes #-}
20 {-# LANGUAGE TemplateHaskell #-}
21
22 module Gargantext.Database.Schema.NodeNodeNgrams
23 where
24
25 import Prelude
26 import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
27 import Control.Lens.TH (makeLenses)
28 import Gargantext.Database.Utils (Cmd, mkCmd)
29 import Gargantext.Database.Schema.Ngrams (NgramsTypeId, pgNgramsTypeId, NgramsId)
30 import Gargantext.Database.Schema.Node (pgNodeId)
31 import Gargantext.Database.Types.Node
32 import Opaleye
33
34 data NodeNodeNgramsPoly n1 n2 ngrams_id ngt w
35 = NodeNodeNgrams { _nnng_node1_id :: n1
36 , _nnng_node2_id :: n2
37 , _nnng_ngrams_id :: ngrams_id
38 , _nnng_ngramsType :: ngt
39 , _nnng_weight :: w
40 } deriving (Show)
41
42 type NodeNodeNgramsWrite =
43 NodeNodeNgramsPoly (Column PGInt4 )
44 (Column PGInt4 )
45 (Column PGInt4 )
46 (Column PGInt4 )
47 (Column PGFloat8)
48
49 type NodeNodeNgramsRead =
50 NodeNodeNgramsPoly (Column PGInt4 )
51 (Column PGInt4 )
52 (Column PGInt4 )
53 (Column PGInt4 )
54 (Column PGFloat8)
55
56 type NodeNodeNgramsReadNull =
57 NodeNodeNgramsPoly (Column (Nullable PGInt4 ))
58 (Column (Nullable PGInt4 ))
59 (Column (Nullable PGInt4 ))
60 (Column (Nullable PGInt4 ))
61 (Column (Nullable PGFloat8))
62
63 type NodeNodeNgrams =
64 NodeNodeNgramsPoly CorpusId DocId NgramsId NgramsTypeId Double
65
66 $(makeAdaptorAndInstance "pNodeNodeNgrams" ''NodeNodeNgramsPoly)
67 makeLenses ''NodeNodeNgramsPoly
68
69
70 nodeNodeNgramsTable :: Table NodeNodeNgramsWrite NodeNodeNgramsRead
71 nodeNodeNgramsTable = Table "node_node_ngrams"
72 ( pNodeNodeNgrams NodeNodeNgrams
73 { _nnng_node1_id = required "node1_id"
74 , _nnng_node2_id = required "node2_id"
75 , _nnng_ngrams_id = required "ngrams_id"
76 , _nnng_ngramsType = required "ngrams_type"
77 , _nnng_weight = required "weight"
78 }
79 )
80
81 ------------------------------------------------
82
83 queryNodeNodeNgramsTable :: Query NodeNodeNgramsRead
84 queryNodeNodeNgramsTable = queryTable nodeNodeNgramsTable
85
86 -- | Insert utils
87 insertNodeNodeNgrams :: [NodeNodeNgrams] -> Cmd err Int
88 insertNodeNodeNgrams = insertNodeNodeNgramsW
89 . map (\(NodeNodeNgrams n1 n2 ng nt w) ->
90 NodeNodeNgrams (pgNodeId n1)
91 (pgNodeId n2)
92 (pgInt4 ng)
93 (pgNgramsTypeId nt)
94 (pgDouble w)
95 )
96
97 insertNodeNodeNgramsW :: [NodeNodeNgramsWrite] -> Cmd err Int
98 insertNodeNodeNgramsW nnnw =
99 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
100 where
101 insertNothing = (Insert { iTable = nodeNodeNgramsTable
102 , iRows = nnnw
103 , iReturning = rCount
104 , iOnConflict = (Just DoNothing)
105 })
106