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