Commit bfd3789f authored by Alexandre Delanoë's avatar Alexandre Delanoë

[BASHQL] value ok + returning value ok.

parent 856eb6d2
......@@ -60,7 +60,7 @@ module Gargantext.Database ( module Gargantext.Database.Utils
, get
, ls , ls'
, home, home'
, post, post'
, post, post', postR'
, del , del'
)
where
......@@ -107,6 +107,12 @@ post _ [] _ = pure 0
post _ _ [] = pure 0
post c pth ns = mkNode c (last pth) ns
postR :: Connection -> PWD -> [NodeWrite'] -> IO [Int]
postR _ [] _ = pure [0]
postR _ _ [] = pure [0]
postR c pth ns = mkNodeR c (last pth) ns
rm :: Connection -> PWD -> [NodeId] -> IO Int
rm = del
......@@ -159,6 +165,21 @@ post' = do
data Children a = NoChildren | Children a
postR' :: IO [Int]
postR' = do
c <- connectGargandb "gargantext.ini"
h <- home c
let userId = 1
postR c h [ node userId (last h) Corpus "name" "{}"
, node userId (last h) Project "name" "{}"
]
del' :: [NodeId] -> IO Int
del' ns = do
c <- connectGargandb "gargantext.ini"
......
......@@ -21,7 +21,7 @@ Portability : POSIX
module Gargantext.Database.Node where
import Data.ByteString (ByteString)
import GHC.Int (Int64)
import Data.Maybe
import Data.Time (UTCTime)
......@@ -48,7 +48,11 @@ import Data.Maybe (Maybe, fromMaybe)
import Data.Text (Text)
import Data.Profunctor.Product.TH (makeAdaptorAndInstance)
import Data.Typeable (Typeable)
import qualified Data.ByteString.Internal as DBI
import qualified Data.ByteString as DB
import qualified Data.ByteString.Lazy as DBL
import Data.ByteString (ByteString)
import Database.PostgreSQL.Simple (Connection)
import Opaleye hiding (FromField)
import Opaleye.Internal.QueryArr (Query(..))
......@@ -84,7 +88,7 @@ instance QueryRunnerColumnDefault PGJsonb HyperdataUser where
fromField' :: (Typeable b, FromJSON b) => Field -> Maybe DBI.ByteString -> Conversion b
fromField' :: (Typeable b, FromJSON b) => Field -> Maybe DB.ByteString -> Conversion b
fromField' field mb = do
v <- fromField field mb
valueToHyperdata v
......@@ -236,12 +240,11 @@ type NodeWrite' = NodePoly (Maybe Int) Int Int (ParentId) Text (Maybe UTCTime) B
type TypeId = Int
--node :: UserId -> ParentId -> NodeType -> Text -> Value -> NodeWrite'
node :: UserId -> ParentId -> NodeType -> Text -> ByteString -> NodeWrite'
node :: UserId -> ParentId -> NodeType -> Text -> Value -> NodeWrite'
node userId parentId nodeType name nodeData = Node Nothing typeId userId parentId name Nothing byteData
where
typeId = nodeTypeId nodeType
byteData = nodeData
--byteData = encode nodeData
byteData = DB.pack $ DBL.unpack $ encode nodeData
node2write pid (Node id tn ud _ nm dt hp) = ((pgInt4 <$> id)
,(pgInt4 tn)
......@@ -255,3 +258,10 @@ node2write pid (Node id tn ud _ nm dt hp) = ((pgInt4 <$> id)
mkNode :: Connection -> ParentId -> [NodeWrite'] -> IO Int64
mkNode conn pid ns = runInsertMany conn nodeTable' $ map (node2write pid) ns
mkNodeR :: Connection -> ParentId -> [NodeWrite'] -> IO [Int]
mkNodeR conn pid ns = runInsertManyReturning conn nodeTable' (map (node2write pid) ns) (\(i,_,_,_,_,_,_) -> i)
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