{-# LANGUAGE TemplateHaskell #-} module Gargantext.Database.NodeStory where import Data.Map.Strict (Map) import Data.Map.Strict.Patch (PatchMap) import Gargantext.Core.NodeStory (Archive(..), NodeStory(..)) import Gargantext.Core.Types (NodeId) import Gargantext.Core.Types.Ngrams (NgramsTableMap, NgramsTablePatch) import Gargantext.Database.Prelude (Cmd) import Gargantext.Database.Query.Table.Ngrams (NgramsType) import Gargantext.Database.Schema.Ngrams (NgramsType(..)) import Gargantext.Prelude import Opaleye getNodeStory :: NodeId -> Cmd err [NodeStory] getNodeStory nodeId = runOpaQuery query where query = do restrict -< _node_id --queryNodeStories :: Select (Node) type NodeListStory = NodeStory NgramsState' NgramsStatePatch' data NodeStory' a b = NodeStory' { node_id :: a , archive :: b } type NodeListStoryQ = NodeStory' Int (Archive NgramsState' NgramsStatePatch') type NgramsState' = Map NgramsType NgramsTableMap type NgramsStatePatch' = PatchMap NgramsType NgramsTablePatch type NodeStoryField = NodeStory' (Field SqlInt4) (Field SqlJsonb) $(makeAdaptorAndInstance "pNodeStory" ''NodeStory') nodeStoryTable :: Table NodeStoryField NodeStoryField nodeStoryTable = Table "node_stories" ( pNodeStory NodeListStoryQ { node_id = tableField "node_id" , archive = tableField "archive" } ) nodeStorySelect :: Select NodeStoryField nodeStorySelect = selectTable nodeStoryTable