2 Module : Gargantext.Database.Select.Table.NodeContext_NodeContext
4 Copyright : (c) CNRS, 2017-Present
5 License : AGPL + CECILL v3
6 Maintainer : team@gargantext.org
7 Stability : experimental
11 {-# LANGUAGE Arrows #-}
12 {-# LANGUAGE QuasiQuotes #-}
13 {-# LANGUAGE TemplateHaskell #-}
15 module Gargantext.Database.Query.Table.NodeContext_NodeContext
16 ( module Gargantext.Database.Schema.NodeContext_NodeContext
17 -- , query_NodeContext_NodeContext_Table
18 , insertNodeContext_NodeContext
22 import Data.Text (Text)
23 import Gargantext.Core.Types
24 import Gargantext.Database.Prelude
25 import Gargantext.Database.Schema.NodeContext_NodeContext
26 import Gargantext.Database.Schema.Prelude hiding (sum)
27 import Gargantext.Prelude
28 import qualified Database.PostgreSQL.Simple as PGS
31 queryNodeContext_NodeContextTable :: Select NodeContext_NodeContextRead
32 queryNodeContext_NodeContextTable = selectTable nodeContext_NodeContextTable
35 insertNodeContext_NodeContext :: [(CorpusId, DocId, AnnuaireId, ContactId)] -> Cmd err [Int]
36 insertNodeContext_NodeContext contexts = do
38 fields = map (\t -> QualifiedIdentifier Nothing t) $ snd fields_name
39 fields_name :: ( [Text], [Text])
40 fields_name = ( ["corpus_id", "doc_id", "annuaire_id", "contact_id"]
41 , ["int4" , "int4" , "int4" , "int4" ]
43 result <- map (\(PGS.Only a) -> a) <$> runPGSQuery queryInsert (PGS.Only $ Values fields contexts)
46 queryInsert :: PGS.Query
48 WITH input(corpus_id, doc_id, annuaire_id, contact_id) AS (?)
49 INSERT into nodescontexts_nodescontexts (nodescontexts1, nodescontexts2)
50 SELECT context1.id, context2.id FROM input
51 INNER JOIN nodes_contexts context1 ON context1.node_id = input.corpus_id
52 INNER JOIN nodes_contexts context2 ON context2.node_id = input.annuaire_id
53 WHERE context1.context_id = input.doc_id
54 AND context2.context_id = input.contact_id
55 ON CONFLICT (nodescontexts1, nodescontexts2) DO Nothing