]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Schema/NodeNodeNgrams2.hs
[DB/FACT] fix warnings
[gargantext.git] / src / Gargantext / Database / Schema / NodeNodeNgrams2.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 FlexibleContexts #-}
16 {-# LANGUAGE FlexibleInstances #-}
17 {-# LANGUAGE FunctionalDependencies #-}
18 {-# LANGUAGE MultiParamTypeClasses #-}
19 {-# LANGUAGE NoImplicitPrelude #-}
20 {-# LANGUAGE RankNTypes #-}
21 {-# LANGUAGE TemplateHaskell #-}
22
23 module Gargantext.Database.Schema.NodeNodeNgrams2
24 where
25
26 import Gargantext.Database.Schema.Prelude
27 import Gargantext.Database.Schema.NodeNgrams (NodeNgramsId)
28 import Gargantext.Database.Admin.Types.Node (pgNodeId)
29 import Gargantext.Database.Admin.Types.Node
30 import Gargantext.Database.Admin.Utils (Cmd, mkCmd)
31 import Prelude
32
33 data NodeNodeNgrams2Poly node_id nodengrams_id w
34 = NodeNodeNgrams2 { _nnng2_node_id :: !node_id
35 , _nnng2_nodengrams_id :: !nodengrams_id
36 , _nnng2_weight :: !w
37 } deriving (Show)
38
39 type NodeNodeNgrams2Write =
40 NodeNodeNgrams2Poly (Column PGInt4 )
41 (Column PGInt4 )
42 (Column PGFloat8)
43
44 type NodeNodeNgrams2Read =
45 NodeNodeNgrams2Poly (Column PGInt4 )
46 (Column PGInt4 )
47 (Column PGFloat8)
48
49 type NodeNodeNgrams2ReadNull =
50 NodeNodeNgrams2Poly (Column (Nullable PGInt4 ))
51 (Column (Nullable PGInt4 ))
52 (Column (Nullable PGFloat8))
53
54 type NodeNodeNgrams2 =
55 NodeNodeNgrams2Poly DocId NodeNgramsId Double
56
57 $(makeAdaptorAndInstance "pNodeNodeNgrams2" ''NodeNodeNgrams2Poly)
58 makeLenses ''NodeNodeNgrams2Poly
59
60
61 nodeNodeNgrams2Table :: Table NodeNodeNgrams2Write NodeNodeNgrams2Read
62 nodeNodeNgrams2Table = Table "node_node_ngrams2"
63 ( pNodeNodeNgrams2 NodeNodeNgrams2
64 { _nnng2_node_id = required "node_id"
65 , _nnng2_nodengrams_id = required "nodengrams_id"
66 , _nnng2_weight = required "weight"
67 }
68 )
69
70 queryNodeNodeNgrams2Table :: Query NodeNodeNgrams2Read
71 queryNodeNodeNgrams2Table = queryTable nodeNodeNgrams2Table
72
73 -- | Insert utils
74 insertNodeNodeNgrams2 :: [NodeNodeNgrams2] -> Cmd err Int
75 insertNodeNodeNgrams2 = insertNodeNodeNgrams2W
76 . map (\(NodeNodeNgrams2 n1 n2 w) ->
77 NodeNodeNgrams2 (pgNodeId n1)
78 (pgInt4 n2)
79 (pgDouble w)
80 )
81
82 insertNodeNodeNgrams2W :: [NodeNodeNgrams2Write] -> Cmd err Int
83 insertNodeNodeNgrams2W nnnw =
84 mkCmd $ \c -> fromIntegral <$> runInsert_ c insertNothing
85 where
86 insertNothing = Insert { iTable = nodeNodeNgrams2Table
87 , iRows = nnnw
88 , iReturning = rCount
89 , iOnConflict = (Just DoNothing)
90 }