cleanup suggested by @begriffs

This commit is contained in:
Ruslan Talpa
2015-10-01 10:30:41 +03:00
parent 7f2c39ef94
commit 812135d1e5
9 changed files with 127 additions and 197 deletions
+17 -33
View File
@@ -2,17 +2,10 @@ module Main where
import Paths_postgrest (version)
-- added
import PostgREST.PgStructure
--import Data.Aeson
--import Data.List (find)
--import Data.Maybe (isJust)
import PostgREST.Types
--import Network.HTTP.Types.Status
--import Network.HTTP.Types.Header
import Network.Wai
import PostgREST.App
import PostgREST.Error (errResponse)
import PostgREST.Middleware
@@ -87,37 +80,28 @@ main = do
fail "Cannot run in this PostgreSQL version, PostgREST needs at least 9.2.0"
) supportedOrError
-- read the structure of the database
-- read the structure of the database
let txParam = Just (H.ReadCommitted, Just True)
let txSettings = Just (H.ReadCommitted, Just True)
metadata <- H.session pool $ H.tx txSettings $ do
tabs <- allTables
rels <- allRelations
cols <- allColumns rels
keys <- allPrimaryKeys
return (tabs, rels, cols, keys)
tblsRes <- H.session pool $ H.tx txParam alltables
let allTables = either (fail . show) id tblsRes
dbstructure <- case metadata of
Left e -> fail $ show e
Right (tabs, rels, cols, keys) ->
return $ DbStructure {
tables=tabs
, columns=cols
, relations=rels
, primaryKeys=keys
}
relsRes <- H.session pool $ H.tx txParam allrelations
let allRelations = either (fail . show) id relsRes
colsRes <- H.session pool $ H.tx txParam $ allcolumns allRelations
let allColumns = either (fail . show) id colsRes
pkRes <- H.session pool $ H.tx txParam allprimaryKeys
let allPrimaryKeys = either (fail . show) id pkRes
-- tableAclRes <- H.session pool $ H.tx txParam $ alltablesAcl
-- let allTablesAcl = either (fail . show) id tableAclRes
let dbstructure = DbStructure {
tables=allTables
, columns=allColumns
, relations=allRelations
, primaryKeys=allPrimaryKeys
--, tablesAcl=allTablesAcl
}
runSettings appSettings $ middle $ \ req respond -> do
body <- strictRequestBody req
resOrError <- liftIO $ H.session pool $ H.tx (Just (H.ReadCommitted, Just True)) $
resOrError <- liftIO $ H.session pool $ H.tx txSettings $
authenticated conf (app dbstructure conf body) req
either (respond . errResponse) respond resOrError