2 Module : Gargantext.Database.Queries
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
11 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
13 {-# LANGUAGE Arrows #-}
14 {-# LANGUAGE DeriveGeneric #-}
15 {-# LANGUAGE FlexibleInstances #-}
16 {-# LANGUAGE FunctionalDependencies #-}
17 {-# LANGUAGE MultiParamTypeClasses #-}
18 {-# LANGUAGE NoImplicitPrelude #-}
19 {-# LANGUAGE TemplateHaskell #-}
20 {-# OPTIONS_GHC -fno-warn-orphans #-}
22 module Gargantext.Database.Queries where
24 import Gargantext.Prelude
25 import Gargantext.Core.Types (Limit, Offset, NodePoly)
26 import Data.Maybe (Maybe, maybe)
27 import Control.Arrow ((>>>))
28 import Control.Applicative ((<*>))
30 -- (Query, limit, offset)
33 type NodeWrite = NodePoly (Maybe (Column PGInt4 ))
36 (Column (Nullable PGInt4 ))
38 (Maybe (Column PGTimestamptz))
40 (Maybe (Column PGTSVector))
42 type NodeRead = NodePoly (Column PGInt4 )
45 (Column (Nullable PGInt4 ))
47 (Column PGTimestamptz )
52 type NodeReadNull = NodePoly (Column (Nullable PGInt4 ))
53 (Column (Nullable PGInt4 ))
54 (Column (Nullable PGInt4 ))
55 (Column (Nullable PGInt4 ))
56 (Column (Nullable PGText ))
57 (Column (Nullable PGTimestamptz ))
58 (Column (Nullable PGJsonb))
59 (Column (Nullable PGTSVector))
62 join3 :: Query columnsA -> Query columnsB -> Query columnsC
63 -> ((columnsA, columnsB, columnsC) -> Column PGBool)
64 -> Query (columnsA, columnsB, columnsC)
65 join3 q1 q2 q3 cond = ((,,) <$> q1 <*> q2 <*> q3) >>> keepWhen cond
68 --leftJoin3 :: Query columnsL1 -> Query columnsR -> Query columnsL
69 -- -> ((columnsL1, columnsR) -> Column PGBool)
70 -- -> ((columnsL, (columnsL1, nullableColumnsR1)) -> Column PGBool)
71 -- -> Query (columnsL, nullableColumnsR)
72 --leftJoin3 q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q1 q2 cond12) cond23
74 limit' :: Maybe Limit -> Query a -> Query a
75 limit' maybeLimit query = maybe query (\l -> limit l query) maybeLimit
77 offset' :: Maybe Offset -> Query a -> Query a
78 offset' maybeOffset query = maybe query (\o -> offset o query) maybeOffset