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

feat: persist new hyperdata

parent 4ab275a3
......@@ -67,6 +67,7 @@ instance ToNamedRecord Document where
, "Publication Year" .= _hd_publication_year _node_hyperdata
, "Authors" .= _hd_authors _node_hyperdata
, "Title" .= _hd_title _node_hyperdata
, "Country" .= _hd_from_country _node_hyperdata
, "Source" .= (TE.encodeUtf8 <$> _hd_source _node_hyperdata)
, "Abstract" .= (TE.encodeUtf8 <$> _hd_abstract _node_hyperdata) ]
......
......@@ -267,7 +267,7 @@ getHeaders bl del = do
readTSVFile :: FilePath -> IO (Either Text (Header, Vector TsvDoc))
readTSVFile fp = do
file <- BL.readFile fp
case (testCorrectFile file) of
case testCorrectFile file of
Left _err -> pure $ Left _err
Right del -> pure $ readTsvLazyBS del file
......@@ -406,7 +406,7 @@ tsv2doc (TsvDoc { .. })
, _hd_page = Nothing
, _hd_title = Just tsv_title
, _hd_authors = Just tsv_authors
, _hd_from_country = Nothing
, _hd_from_country = tsv_from_country
, _hd_institutes = Nothing
, _hd_source = Just tsv_source
, _hd_abstract = Just tsv_abstract
......
......@@ -73,7 +73,7 @@ import Gargantext.Database.Schema.Node (NodePoly(..))
import Gargantext.Defaults qualified as Defaults
import Gargantext.Prelude hiding (hash, toLower)
import Gargantext.Prelude.Crypto.Hash (hash)
import Debug.Pretty.Simple
{-| To Print result query
import Data.ByteString.Internal (ByteString)
import Database.PostgreSQL.Simple (formatQuery)
......@@ -87,11 +87,25 @@ import Database.PostgreSQL.Simple (formatQuery)
-- ParentId : folder ID which is parent of the inserted documents
-- 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'));`
-- 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 u p = runPGSQuery queryInsert . Only . Values fields . map (insertDb' u p)
where
insertDb userId parentId items =
let
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
where
insertDb' :: HasDBid NodeType => UserId -> Maybe ParentId -> a -> [Action]
......
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