import Control.Exception
import Control.Lens (Getter, view)
--- import Control.Monad.Error.Class -- (MonadError(..), Error)
import Control.Monad.Except
-import Control.Monad.Reader
import Control.Monad.Random
+import Control.Monad.Reader
import Control.Monad.Trans.Control (MonadBaseControl)
import Data.Aeson (Result(Error,Success), fromJSON, FromJSON)
import Data.ByteString.Char8 (hPutStrLn)
import Data.Ini (readIniFile, lookupValue)
import Data.Pool (Pool, withResource)
import Data.Profunctor.Product.Default (Default)
-import Data.Text (unpack, pack)
+import Data.Text (unpack, pack, Text)
import Data.Word (Word16)
import Database.PostgreSQL.Simple (Connection, connect)
import Database.PostgreSQL.Simple.FromField ( Conversion, ResultError(ConversionFailed), fromField, returnError)
import Database.PostgreSQL.Simple.Internal (Field)
+import Gargantext.Prelude
+import Gargantext.Prelude.Config (GargConfig())
import Opaleye (Query, Unpackspec, showSqlForPostgres, FromFields, Select, runQuery, PGJsonb, QueryRunnerColumnDefault)
import Opaleye.Aggregate (countRows)
import System.IO (FilePath)
import qualified Data.List as DL
import qualified Database.PostgreSQL.Simple as PGS
-import Gargantext.Prelude
-import Gargantext.Prelude.Config (GargConfig())
-
-------------------------------------------------------
class HasConnectionPool env where
connPool :: Getter env (Pool Connection)
hPutStrLn stderr q'
throw (SomeException e)
+-- | TODO catch error
+runPGSQuery_ :: ( CmdM env err m
+ , PGS.FromRow r
+ )
+ => PGS.Query -> m [r]
+runPGSQuery_ q = mkCmd $ \conn -> catch (PGS.query_ conn q) printError
+ where
+ printError (SomeException e) = do
+ printDebug "[G.D.P.runPGSQuery_]" ("TODO: format query error query" :: Text)
+ throw (SomeException e)
+
+
execPGSQuery :: PGS.ToRow a => PGS.Query -> a -> Cmd err Int64
execPGSQuery q a = mkCmd $ \conn -> PGS.execute conn q a