Refactor DbStructure

- Rename `dbstructure` to `db` in App.hs
- Rename PgStructure* to DbStructure*
- Move `DbStructure` creation to DbStructure.hs
This commit is contained in:
calebmer
2015-11-11 09:03:06 -05:00
parent 3f1d2d8ed9
commit 7560fafbab
11 changed files with 81 additions and 99 deletions
+4 -17
View File
@@ -30,8 +30,7 @@ import PostgREST.App (app)
import PostgREST.Config (AppConfig(..))
import PostgREST.Middleware
import PostgREST.Error(errResponse)
import PostgREST.PgStructure
import PostgREST.Types
import PostgREST.DbStructure
dbString :: String
dbString = "postgres://postgrest_test@localhost:5432/postgrest_test"
@@ -55,25 +54,13 @@ withApp perform = do
<- H.acquirePool pgSettings testPoolOpts
let txSettings = Just (H.ReadCommitted, Just True)
metadata <- H.session pool $ H.tx txSettings $ do
rels <- allRelations
cols <- allColumns rels
keys <- allPrimaryKeys
return (rels, cols, keys)
dbstructure <- case metadata of
Left e -> fail $ show e
Right (rels, cols, keys) ->
return DbStructure {
columns=cols
, relations=rels
, primaryKeys=keys
}
dbOrError <- H.session pool $ H.tx txSettings createDbStructure
db <- either (fail . show) return dbOrError
perform $ middle $ \req resp -> do
body <- strictRequestBody req
result <- liftIO $ H.session pool $ H.tx txSettings
$ runWithClaims cfg (app dbstructure cfg body) req
$ runWithClaims cfg (app db cfg body) req
either (resp . errResponse) resp result
where middle = defaultMiddle