]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Query/Table/Node/Select.hs
resolve the conflict
[gargantext.git] / src / Gargantext / Database / Query / Table / 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 LambdaCase #-}
14
15 module Gargantext.Database.Query.Table.Node.Select
16 where
17
18 import Control.Arrow (returnA)
19 import Opaleye
20 import Protolude
21
22 import Gargantext.Core
23 import Gargantext.Core.Types
24 import Gargantext.Core.Types.Individu (Username)
25 import Gargantext.Database.Prelude
26 import Gargantext.Database.Schema.Node
27 import Gargantext.Database.Schema.User
28 import Gargantext.Database.Query.Table.User
29
30 selectNodesWithUsername :: (HasDBid NodeType) => NodeType -> Username -> Cmd err [NodeId]
31 selectNodesWithUsername nt u = runOpaQuery $ proc () -> do
32 n <- queryNodeTable -< ()
33 usrs <- optionalRestrict queryUserTable -<
34 (\us' -> _node_user_id n .== user_id us')
35 restrict -< matchMaybe usrs $ \case
36 Nothing -> toFields True
37 Just us -> user_username us .== sqlStrictText u
38 restrict -< _node_typename n .== sqlInt4 (toDBid nt)
39 returnA -< _node_id n