]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Node/Select.hs
Merge branch 'dev' of ssh://delanoe.org/haskell-gargantext into dev
[gargantext.git] / src / Gargantext / Database / Node / Select.hs
1 {-|
2 Module : Gargantext.Database.Node.Select
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
8 Portability : POSIX
9 -}
10
11
12 {-# LANGUAGE Arrows #-}
13 {-# LANGUAGE FlexibleInstances #-}
14 {-# LANGUAGE FlexibleContexts #-}
15 {-# LANGUAGE RankNTypes #-}
16
17 module Gargantext.Database.Node.Select where
18
19 import Opaleye
20 import Gargantext.Core.Types
21 import Gargantext.Database.Schema.Node
22 import Gargantext.Database.Utils
23 import Gargantext.Database.Config
24 import Gargantext.Database.Schema.User
25 import Gargantext.Core.Types.Individu (Username)
26 import Control.Arrow (returnA)
27
28 selectNodesWithUsername :: NodeType -> Username -> Cmd err [NodeId]
29 selectNodesWithUsername nt u = runOpaQuery (q u)
30 where
31 q u' = proc () -> do
32 (n,usrs) <- join -< ()
33 restrict -< user_username usrs .== (toNullable $ pgStrictText u')
34 restrict -< _node_typename n .== (pgInt4 $ nodeTypeId nt)
35 returnA -< _node_id n
36
37 join :: Query (NodeRead, UserReadNull)
38 join = leftJoin queryNodeTable queryUserTable on1
39 where
40 on1 (n,us) = _node_userId n .== user_id us
41