]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Action/Query/Node/Select.hs
[DB|WIP] fixing imports still.
[gargantext.git] / src / Gargantext / Database / Action / Query / 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.Action.Query.Node.Select
18 where
19
20 import Control.Arrow (returnA)
21 import Gargantext.Core.Types
22 import Gargantext.Core.Types.Individu (Username)
23 import Gargantext.Database.Admin.Config
24 import Gargantext.Database.Admin.Utils
25 import Gargantext.Database.Schema.Node
26 import Gargantext.Database.Schema.User
27 import Gargantext.Database.Action.Query.User
28 import Gargantext.Database.Action.Query.Node
29 import Opaleye
30
31 selectNodesWithUsername :: NodeType -> Username -> Cmd err [NodeId]
32 selectNodesWithUsername nt u = runOpaQuery (q u)
33 where
34 q u' = proc () -> do
35 (n,usrs) <- join -< ()
36 restrict -< user_username usrs .== (toNullable $ pgStrictText u')
37 restrict -< _node_typename n .== (pgInt4 $ nodeTypeId nt)
38 returnA -< _node_id n
39
40 join :: Query (NodeRead, UserReadNull)
41 join = leftJoin queryNodeTable queryUserTable on1
42 where
43 on1 (n,us) = _node_userId n .== user_id us
44