@@ -55,7 +55,7 @@ app config req respond = do
|
|||||||
[] -> responseLBS status200 [json] <$> (printTables ver =<< conn)
|
[] -> responseLBS status200 [json] <$> (printTables ver =<< conn)
|
||||||
[table] -> responseLBS status200 [json] <$>
|
[table] -> responseLBS status200 [json] <$>
|
||||||
( if verb == methodOptions
|
( if verb == methodOptions
|
||||||
then printColumns table =<< conn
|
then printColumns ver table =<< conn
|
||||||
else selectWhere (T.pack $ show ver) table qq =<< conn )
|
else selectWhere (T.pack $ show ver) table qq =<< conn )
|
||||||
_ -> return $ responseLBS status404 [] ""
|
_ -> return $ responseLBS status404 [] ""
|
||||||
|
|
||||||
|
|||||||
+6
-5
@@ -71,14 +71,15 @@ tables s conn = do
|
|||||||
(toBool (fromSql insertable))
|
(toBool (fromSql insertable))
|
||||||
mkTable _ = Nothing
|
mkTable _ = Nothing
|
||||||
|
|
||||||
columns :: T.Text -> Connection -> IO [Column]
|
columns :: Int -> T.Text -> Connection -> IO [Column]
|
||||||
columns t conn = do
|
columns s t conn = do
|
||||||
r <- quickQuery conn
|
r <- quickQuery conn
|
||||||
"select table_schema, table_name, column_name, ordinal_position,\
|
"select table_schema, table_name, column_name, ordinal_position,\
|
||||||
\ is_nullable, data_type, is_updatable,\
|
\ is_nullable, data_type, is_updatable,\
|
||||||
\ character_maximum_length, numeric_precision\
|
\ character_maximum_length, numeric_precision\
|
||||||
\ from information_schema.columns\
|
\ from information_schema.columns\
|
||||||
\ where table_name = ?" [toSql t]
|
\ where table_schema = ?\
|
||||||
|
\ and table_name = ?" [toSql (show s), toSql t]
|
||||||
return $ mapMaybe mkColumn r
|
return $ mapMaybe mkColumn r
|
||||||
|
|
||||||
where
|
where
|
||||||
@@ -100,5 +101,5 @@ namedColumnHash = fromList . (Prelude.zip =<< Prelude.map colName)
|
|||||||
printTables :: Int -> Connection -> IO BL.ByteString
|
printTables :: Int -> Connection -> IO BL.ByteString
|
||||||
printTables schema conn = JSON.encode <$> tables (show schema) conn
|
printTables schema conn = JSON.encode <$> tables (show schema) conn
|
||||||
|
|
||||||
printColumns :: T.Text -> Connection -> IO BL.ByteString
|
printColumns :: Int -> T.Text -> Connection -> IO BL.ByteString
|
||||||
printColumns table conn = JSON.encode . namedColumnHash <$> columns table conn
|
printColumns schema table conn = JSON.encode . namedColumnHash <$> columns schema table conn
|
||||||
|
|||||||
Reference in New Issue
Block a user