diff --git a/src/Main.hs b/src/Main.hs index 32a5334c7..3b01f9356 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -93,7 +93,7 @@ app config req respond = do ([table], "POST") -> jsonBodyAction req (\row -> responseLBS status200 [jsonContentType] <$> ( - insert (pack $ show ver) table row conn)) + insert ver table row conn)) (_, _) -> return $ responseLBS status404 [] "" diff --git a/src/PgQuery.hs b/src/PgQuery.hs index 8702520f7..6d19cbf5e 100644 --- a/src/PgQuery.hs +++ b/src/PgQuery.hs @@ -104,9 +104,9 @@ jsonArrayRows :: QuotedSql -> QuotedSql jsonArrayRows q = ("array_to_json(array_agg(row_to_json(t))) from (", []) <> q <> (") t", []) -insert :: Text -> Text -> SqlRow -> Connection -> IO BL.ByteString +insert :: Int -> Text -> SqlRow -> Connection -> IO BL.ByteString insert schema table row conn = do - query <- populateSql conn ("insert into %I.%I ("++colIds++")", map toSql $ schema:table:cols) + query <- populateSql conn ("insert into %I.%I ("++colIds++")", map toSql $ (show schema):table:cols) stmt <- prepare conn (query ++ " values ("++phs++") returning *") _ <- execute stmt values commit conn diff --git a/src/PgStructure.hs b/src/PgStructure.hs index 6eaecb18d..bf46b2dfa 100644 --- a/src/PgStructure.hs +++ b/src/PgStructure.hs @@ -1,5 +1,8 @@ +-- {{{ Imports + {-# LANGUAGE OverloadedStrings #-} + module PgStructure where import Data.Functor ( (<$>) ) @@ -18,6 +21,8 @@ import Database.HDBC.PostgreSQL import Data.Aeson ((.=)) +-- }}} + data Table = Table { tableSchema :: String , tableName :: String