[FIX] Clean Text before sending it to NLP micro services + tests + clean code for...
[gargantext.git] / src / Gargantext / Database / Schema / Node.hs
index ff1027a46f4c299ce98a84746812ac50685caecb..2859b1aa1ea0ef60d64192af99d85bfcb494f9b9 100644 (file)
@@ -8,7 +8,7 @@ Stability   : experimental
 Portability : POSIX
 -}
 
-{-# OPTIONS_GHC -fno-warn-name-shadowing #-}
+
 {-# OPTIONS_GHC -fno-warn-orphans        #-}
 
 {-# LANGUAGE Arrows                 #-}
@@ -25,19 +25,20 @@ import Prelude hiding (null, id, map, sum)
 
 ------------------------------------------------------------------------
 -- Main polymorphic Node definition
-
 data NodePoly id
+              hash_id
               typename
-              userId
-              parentId
+              user_id
+              parent_id
               name
               date
               hyperdata  =
      Node { _node_id        :: !id
+          , _node_hash_id   :: !hash_id
           , _node_typename  :: !typename
 
-          , _node_userId    :: !userId
-          , _node_parentId  :: !parentId
+          , _node_user_id    :: !user_id
+          , _node_parent_id  :: !parent_id
 
           , _node_name      :: !name
           , _node_date      :: !date
@@ -53,103 +54,86 @@ $(makeLenses ''NodePoly)
 $(makeAdaptorAndInstance "pNode"   ''NodePoly)
 $(makeLensesWith abbreviatedFields ''NodePoly)
 
-------------------------------------------------------------------------
 nodeTable :: Table NodeWrite NodeRead
-nodeTable = Table "nodes" (pNode Node { _node_id         = optional "id"
-                                      , _node_typename   = required "typename"
-                                      , _node_userId     = required "user_id"
+nodeTable = Table "nodes" (pNode Node { _node_id         = optionalTableField "id"
+                                      , _node_hash_id    = optionalTableField "hash_id"
+                                      , _node_typename   = requiredTableField "typename"
+                                      , _node_user_id    = requiredTableField "user_id"
 
-                                      , _node_parentId   = optional "parent_id"
-                                      , _node_name       = required "name"
-                                      , _node_date       = optional "date"
+                                      , _node_parent_id  = optionalTableField "parent_id"
+                                      , _node_name       = requiredTableField "name"
+                                      , _node_date       = optionalTableField "date"
 
-                                      , _node_hyperdata  = required "hyperdata"
+                                      , _node_hyperdata  = requiredTableField "hyperdata"
                                       -- ignoring ts_vector field here
                                       }
                             )
 
 queryNodeTable :: Query NodeRead
-queryNodeTable = queryTable nodeTable
+queryNodeTable = selectTable nodeTable
 ------------------------------------------------------------------------
-type NodeWrite = NodePoly (Maybe (Column PGInt4)      )
-                                 (Column PGInt4)
-                                 (Column PGInt4)
-                          (Maybe (Column PGInt4)      )
-                                 (Column PGText)
-                          (Maybe (Column PGTimestamptz))
-                                 (Column PGJsonb)
-
-type NodeRead = NodePoly (Column PGInt4        )
-                         (Column PGInt4        )
-                         (Column PGInt4        )
-                         (Column PGInt4        )
-                         (Column PGText        )
-                         (Column PGTimestamptz )
-                         (Column PGJsonb       )
-
-type NodeReadNull = NodePoly (Column (Nullable PGInt4))
-                             (Column (Nullable PGInt4))
-                             (Column (Nullable PGInt4))
-                             (Column (Nullable PGInt4))
-                             (Column (Nullable PGText))
-                             (Column (Nullable PGTimestamptz))
-                             (Column (Nullable PGJsonb))
+type NodeWrite = NodePoly (Maybe (Field SqlInt4)      )
+                          (Maybe (Field SqlText)      )
+                                 (Field SqlInt4)
+                                 (Field SqlInt4)
+                          (Maybe (Field SqlInt4)      )
+                                 (Field SqlText)
+                          (Maybe (Field SqlTimestamptz))
+                                 (Field SqlJsonb)
+
+type NodeRead = NodePoly (Field SqlInt4        )
+                         (Field SqlText        )
+                         (Field SqlInt4        )
+                         (Field SqlInt4        )
+                         (Field SqlInt4        )
+                         (Field SqlText        )
+                         (Field SqlTimestamptz )
+                         (Field SqlJsonb       )
 ------------------------------------------------------------------------
 -- | Node(Read|Write)Search is slower than Node(Write|Read) use it
 -- for full text search only
 
 type NodeSearchWrite =
   NodePolySearch
-    (Maybe  (Column  PGInt4)      )
-    (Column  PGInt4               )
-    (Column  PGInt4               )
-    (Column (Nullable PGInt4)     )
-    (Column PGText                )
-    (Maybe  (Column PGTimestamptz))
-    (Column  PGJsonb              )
-    (Maybe  (Column PGTSVector)   )
+    (Maybe  (Field  SqlInt4)      )
+    (Field  SqlInt4               )
+    (Field  SqlInt4               )
+    (FieldNullable SqlInt4)
+    (Field SqlText                )
+    (Maybe  (Field SqlTimestamptz))
+    (Field  SqlJsonb              )
+    (Maybe  (Field SqlTSVector)   )
 
 type NodeSearchRead =
   NodePolySearch
-    (Column  PGInt4           )
-    (Column  PGInt4           )
-    (Column  PGInt4           )
-    (Column (Nullable PGInt4 ))
-    (Column  PGText           )
-    (Column  PGTimestamptz    )
-    (Column  PGJsonb          )
-    (Column  PGTSVector       )
-
-type NodeSearchReadNull =
-  NodePolySearch
-    (Column (Nullable PGInt4)       )
-    (Column (Nullable PGInt4)       )
-    (Column (Nullable PGInt4)       )
-    (Column (Nullable PGInt4)       )
-    (Column (Nullable PGText)       )
-    (Column (Nullable PGTimestamptz))
-    (Column (Nullable PGJsonb)      )
-    (Column (Nullable PGTSVector)   )
+    (Field  SqlInt4           )
+    (Field  SqlInt4           )
+    (Field  SqlInt4           )
+    (FieldNullable SqlInt4 )
+    (Field  SqlText           )
+    (Field  SqlTimestamptz    )
+    (Field  SqlJsonb          )
+    (Field  SqlTSVector       )
 
 
 data NodePolySearch id
                     typename
-                    userId
-                    parentId
+                    user_id
+                    parent_id
                     name
                     date
                     hyperdata
                     search =
-     NodeSearch { _ns_id        :: id
-                , _ns_typename  :: typename
-                , _ns_userId    :: userId
-                                          --   , nodeUniqId    :: shaId
-                , _ns_parentId  :: parentId
-                , _ns_name      :: name
-                , _ns_date      :: date
-
-                , _ns_hyperdata :: hyperdata
-                , _ns_search    :: search
+     NodeSearch { _ns_id           :: id
+                , _ns_typename     :: typename
+                , _ns_user_id      :: user_id
+           --   , nodeUniqId       :: shaId
+                , _ns_parent_id    :: parent_id
+                , _ns_name         :: name
+                , _ns_date         :: date
+
+                , _ns_hyperdata    :: hyperdata
+                , _ns_search       :: search
                 } deriving (Show, Generic)
 
 $(makeAdaptorAndInstance "pNodeSearch" ''NodePolySearch)
@@ -158,16 +142,17 @@ $(deriveJSON (unPrefix "_ns_")     ''NodePolySearch)
 $(makeLenses ''NodePolySearch)
 
 nodeTableSearch :: Table NodeSearchWrite NodeSearchRead
-nodeTableSearch = Table "nodes" (pNodeSearch NodeSearch { _ns_id         = optional "id"
-                                      , _ns_typename   = required "typename"
-                                      , _ns_userId     = required "user_id"
-
-                                      , _ns_parentId   = required "parent_id"
-                                      , _ns_name       = required "name"
-                                      , _ns_date       = optional "date"
-
-                                      , _ns_hyperdata  = required "hyperdata"
-                                      , _ns_search     = optional "search"
-                                      }
-                            )
+nodeTableSearch = Table "nodes" ( pNodeSearch
+                                   NodeSearch { _ns_id           = optionalTableField "id"
+                                              , _ns_typename     = requiredTableField "typename"
+                                              , _ns_user_id      = requiredTableField "user_id"
+
+                                              , _ns_parent_id    = requiredTableField "parent_id"
+                                              , _ns_name         = requiredTableField "name"
+                                              , _ns_date         = optionalTableField "date"
+
+                                              , _ns_hyperdata    = requiredTableField "hyperdata"
+                                              , _ns_search       = optionalTableField "search"
+                                              }
+                                )
 ------------------------------------------------------------------------