List table columns as array, not hash
This commit is contained in:
+3
-8
@@ -10,8 +10,6 @@ import Data.Maybe (mapMaybe)
|
||||
|
||||
import Control.Applicative ( (<*>) )
|
||||
|
||||
import Data.HashMap.Strict hiding (map)
|
||||
|
||||
import qualified Data.ByteString.Lazy as BL
|
||||
|
||||
import qualified Data.Aeson as JSON
|
||||
@@ -62,7 +60,7 @@ instance JSON.ToJSON Column where
|
||||
, "precision" .= colPrecision c ]
|
||||
|
||||
data TableOptions = TableOptions {
|
||||
tblOptcolumns :: HashMap String Column
|
||||
tblOptcolumns :: [Column]
|
||||
, tblOptpkey :: [String]
|
||||
}
|
||||
|
||||
@@ -112,9 +110,6 @@ columns s t conn = do
|
||||
(fromSql precision)
|
||||
mkColumn _ = Nothing
|
||||
|
||||
namedColumnHash :: [Column] -> HashMap String Column
|
||||
namedColumnHash = fromList . (Prelude.zip =<< Prelude.map colName)
|
||||
|
||||
printTables :: String -> Connection -> IO BL.ByteString
|
||||
printTables schema conn = JSON.encode <$> tables schema conn
|
||||
|
||||
@@ -122,8 +117,8 @@ printColumns :: String -> String -> Connection -> IO BL.ByteString
|
||||
printColumns schema table conn =
|
||||
JSON.encode <$> (TableOptions <$> cols <*> pkey)
|
||||
where
|
||||
cols :: IO (HashMap String Column)
|
||||
cols = namedColumnHash <$> columns schema table conn
|
||||
cols :: IO [Column]
|
||||
cols = columns schema table conn
|
||||
pkey :: IO [String]
|
||||
pkey = primaryKeyColumns schema table conn
|
||||
|
||||
|
||||
@@ -29,42 +29,44 @@ spec = around appWithFixture $ do
|
||||
request methodOptions "/auto_incrementing_pk" [] "" `shouldRespondWith` [json|
|
||||
{
|
||||
"pkey":["id"],
|
||||
"columns":{
|
||||
"inserted_at":{
|
||||
"precision":null,
|
||||
"updatable":true,
|
||||
"schema":"1",
|
||||
"name":"inserted_at",
|
||||
"type":"timestamp with time zone",
|
||||
"maxLen":null,
|
||||
"nullable":true,
|
||||
"position":4},
|
||||
"id":{
|
||||
"precision":32,
|
||||
"updatable":true,
|
||||
"schema":"1",
|
||||
"name":"id",
|
||||
"type":"integer",
|
||||
"maxLen":null,
|
||||
"nullable":false,
|
||||
"position":1},
|
||||
"non_nullable_string":{
|
||||
"precision":null,
|
||||
"updatable":true,
|
||||
"schema":"1",
|
||||
"name":"non_nullable_string",
|
||||
"type":"character varying",
|
||||
"maxLen":null,
|
||||
"nullable":false,
|
||||
"position":3},
|
||||
"nullable_string":{
|
||||
"precision":null,
|
||||
"updatable":true,
|
||||
"schema":"1",
|
||||
"name":"nullable_string",
|
||||
"type":"character varying",
|
||||
"maxLen":null,
|
||||
"nullable":true,
|
||||
"position":2}}
|
||||
"columns":[
|
||||
{
|
||||
"precision": 32,
|
||||
"updatable": true,
|
||||
"schema": "1",
|
||||
"name": "id",
|
||||
"type": "integer",
|
||||
"maxLen": null,
|
||||
"nullable": false,
|
||||
"position": 1
|
||||
}, {
|
||||
"precision": null,
|
||||
"updatable": true,
|
||||
"schema": "1",
|
||||
"name": "nullable_string",
|
||||
"type": "character varying",
|
||||
"maxLen": null,
|
||||
"nullable": true,
|
||||
"position": 2
|
||||
}, {
|
||||
"precision": null,
|
||||
"updatable": true,
|
||||
"schema": "1",
|
||||
"name": "non_nullable_string",
|
||||
"type": "character varying",
|
||||
"maxLen": null,
|
||||
"nullable": false,
|
||||
"position": 3
|
||||
}, {
|
||||
"precision": null,
|
||||
"updatable": true,
|
||||
"schema": "1",
|
||||
"name": "inserted_at",
|
||||
"type": "timestamp with time zone",
|
||||
"maxLen": null,
|
||||
"nullable": true,
|
||||
"position": 4
|
||||
}
|
||||
]
|
||||
}
|
||||
|]
|
||||
|
||||
Reference in New Issue
Block a user