Commit 004b6085 authored by Yoelis Acourt's avatar Yoelis Acourt

feat: persist new hyperdata

parent 4ab275a3
...@@ -67,6 +67,7 @@ instance ToNamedRecord Document where ...@@ -67,6 +67,7 @@ instance ToNamedRecord Document where
, "Publication Year" .= _hd_publication_year _node_hyperdata , "Publication Year" .= _hd_publication_year _node_hyperdata
, "Authors" .= _hd_authors _node_hyperdata , "Authors" .= _hd_authors _node_hyperdata
, "Title" .= _hd_title _node_hyperdata , "Title" .= _hd_title _node_hyperdata
, "Country" .= _hd_from_country _node_hyperdata
, "Source" .= (TE.encodeUtf8 <$> _hd_source _node_hyperdata) , "Source" .= (TE.encodeUtf8 <$> _hd_source _node_hyperdata)
, "Abstract" .= (TE.encodeUtf8 <$> _hd_abstract _node_hyperdata) ] , "Abstract" .= (TE.encodeUtf8 <$> _hd_abstract _node_hyperdata) ]
......
...@@ -267,7 +267,7 @@ getHeaders bl del = do ...@@ -267,7 +267,7 @@ getHeaders bl del = do
readTSVFile :: FilePath -> IO (Either Text (Header, Vector TsvDoc)) readTSVFile :: FilePath -> IO (Either Text (Header, Vector TsvDoc))
readTSVFile fp = do readTSVFile fp = do
file <- BL.readFile fp file <- BL.readFile fp
case (testCorrectFile file) of case testCorrectFile file of
Left _err -> pure $ Left _err Left _err -> pure $ Left _err
Right del -> pure $ readTsvLazyBS del file Right del -> pure $ readTsvLazyBS del file
...@@ -406,7 +406,7 @@ tsv2doc (TsvDoc { .. }) ...@@ -406,7 +406,7 @@ tsv2doc (TsvDoc { .. })
, _hd_page = Nothing , _hd_page = Nothing
, _hd_title = Just tsv_title , _hd_title = Just tsv_title
, _hd_authors = Just tsv_authors , _hd_authors = Just tsv_authors
, _hd_from_country = Nothing , _hd_from_country = tsv_from_country
, _hd_institutes = Nothing , _hd_institutes = Nothing
, _hd_source = Just tsv_source , _hd_source = Just tsv_source
, _hd_abstract = Just tsv_abstract , _hd_abstract = Just tsv_abstract
......
...@@ -73,7 +73,7 @@ import Gargantext.Database.Schema.Node (NodePoly(..)) ...@@ -73,7 +73,7 @@ import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Defaults qualified as Defaults import Gargantext.Defaults qualified as Defaults
import Gargantext.Prelude hiding (hash, toLower) import Gargantext.Prelude hiding (hash, toLower)
import Gargantext.Prelude.Crypto.Hash (hash) import Gargantext.Prelude.Crypto.Hash (hash)
import Debug.Pretty.Simple
{-| To Print result query {-| To Print result query
import Data.ByteString.Internal (ByteString) import Data.ByteString.Internal (ByteString)
import Database.PostgreSQL.Simple (formatQuery) import Database.PostgreSQL.Simple (formatQuery)
...@@ -87,10 +87,24 @@ import Database.PostgreSQL.Simple (formatQuery) ...@@ -87,10 +87,24 @@ import Database.PostgreSQL.Simple (formatQuery)
-- ParentId : folder ID which is parent of the inserted documents -- ParentId : folder ID which is parent of the inserted documents
-- Administrator of the database has to create a uniq index as following SQL command: -- Administrator of the database has to create a uniq index as following SQL command:
-- `create unique index on contexts table (typename, parent_id, (hyperdata ->> 'uniqId'));` -- `create unique index on contexts table (typename, parent_id, (hyperdata ->> 'uniqId'));`
-- insertDb :: (InsertDb a, HasDBid NodeType) => UserId -> Maybe ParentId -> [a] -> DBCmd err [ReturnId]
-- insertDb u p = pTraceShow ("HELLO", fields) $
-- runPGSQuery queryInsert . Only . Values fields . map (insertDb' u p)
-- where
-- fields = map (QualifiedIdentifier Nothing) inputSqlTypes
insertDb :: (InsertDb a, HasDBid NodeType) => UserId -> Maybe ParentId -> [a] -> DBCmd err [ReturnId] insertDb :: (InsertDb a, HasDBid NodeType) => UserId -> Maybe ParentId -> [a] -> DBCmd err [ReturnId]
insertDb u p = runPGSQuery queryInsert . Only . Values fields . map (insertDb' u p) insertDb userId parentId items =
where let
fields = map (QualifiedIdentifier Nothing) inputSqlTypes preparedItems = map (insertDb' userId parentId) items
fields = map (QualifiedIdentifier Nothing) inputSqlTypes
sqlValues = Values fields preparedItems
in
pTraceShow ("LOOK", preparedItems) $
runPGSQuery queryInsert (Only sqlValues)
class InsertDb a class InsertDb a
where where
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment