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
12 {-# LANGUAGE Arrows #-}
13 {-# LANGUAGE LambdaCase #-}
15 module Gargantext.Database.Query.Table.Node.Select
18 import Control.Arrow (returnA)
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
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)