]> Git — Sourcephile - gargantext.git/blob - src/Gargantext/Database/Queries.hs
[DOC] distances.
[gargantext.git] / src / Gargantext / Database / Queries.hs
1 {-|
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
8 Portability : POSIX
9 -}
10
11 {-# OPTIONS_GHC -fno-warn-name-shadowing #-}
12
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 #-}
21
22 module Gargantext.Database.Queries where
23
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 ((<*>))
29 import Opaleye
30 -- (Query, limit, offset)
31
32
33 type NodeWrite = NodePoly (Maybe (Column PGInt4 ))
34 (Column PGInt4 )
35 (Column PGInt4 )
36 (Column (Nullable PGInt4 ))
37 (Column (PGText ))
38 (Maybe (Column PGTimestamptz))
39 (Column PGJsonb )
40 -- (Maybe (Column PGTSVector))
41
42 type NodeRead = NodePoly (Column PGInt4 )
43 (Column PGInt4 )
44 (Column PGInt4 )
45 (Column (Nullable PGInt4 ))
46 (Column (PGText ))
47 (Column PGTimestamptz )
48 (Column PGJsonb)
49 -- (Column PGTSVector)
50
51
52
53 type NodeReadNull = NodePoly (Column (Nullable PGInt4 ))
54 (Column (Nullable PGInt4 ))
55 (Column (Nullable PGInt4 ))
56 (Column (Nullable PGInt4 ))
57 (Column (Nullable PGText ))
58 (Column (Nullable PGTimestamptz ))
59 (Column (Nullable PGJsonb))
60
61
62
63
64 join3 :: Query columnsA -> Query columnsB -> Query columnsC
65 -> ((columnsA, columnsB, columnsC) -> Column PGBool)
66 -> Query (columnsA, columnsB, columnsC)
67 join3 q1 q2 q3 cond = ((,,) <$> q1 <*> q2 <*> q3) >>> keepWhen cond
68
69
70 --leftJoin3 :: Query columnsL1 -> Query columnsR -> Query columnsL
71 -- -> ((columnsL1, columnsR) -> Column PGBool)
72 -- -> ((columnsL, (columnsL1, nullableColumnsR1)) -> Column PGBool)
73 -- -> Query (columnsL, nullableColumnsR)
74 --leftJoin3 q1 q2 q3 cond12 cond23 = leftJoin q3 (leftJoin q1 q2 cond12) cond23
75
76 limit' :: Maybe Limit -> Query a -> Query a
77 limit' maybeLimit query = maybe query (\l -> limit l query) maybeLimit
78
79 offset' :: Maybe Offset -> Query a -> Query a
80 offset' maybeOffset query = maybe query (\o -> offset o query) maybeOffset
81
82
83