Use versioned schemas in all requests

Fixes #7
This commit is contained in:
Joe Nelson
2014-07-18 21:13:14 -07:00
parent dd1547adea
commit 57af2bf511
2 changed files with 7 additions and 6 deletions
+1 -1
View File
@@ -55,7 +55,7 @@ app config req respond = do
[] -> responseLBS status200 [json] <$> (printTables ver =<< conn)
[table] -> responseLBS status200 [json] <$>
( if verb == methodOptions
then printColumns table =<< conn
then printColumns ver table =<< conn
else selectWhere (T.pack $ show ver) table qq =<< conn )
_ -> return $ responseLBS status404 [] ""
+6 -5
View File
@@ -71,14 +71,15 @@ tables s conn = do
(toBool (fromSql insertable))
mkTable _ = Nothing
columns :: T.Text -> Connection -> IO [Column]
columns t conn = do
columns :: Int -> T.Text -> Connection -> IO [Column]
columns s t conn = do
r <- quickQuery conn
"select table_schema, table_name, column_name, ordinal_position,\
\ is_nullable, data_type, is_updatable,\
\ character_maximum_length, numeric_precision\
\ from information_schema.columns\
\ where table_name = ?" [toSql t]
\ where table_schema = ?\
\ and table_name = ?" [toSql (show s), toSql t]
return $ mapMaybe mkColumn r
where
@@ -100,5 +101,5 @@ namedColumnHash = fromList . (Prelude.zip =<< Prelude.map colName)
printTables :: Int -> Connection -> IO BL.ByteString
printTables schema conn = JSON.encode <$> tables (show schema) conn
printColumns :: T.Text -> Connection -> IO BL.ByteString
printColumns table conn = JSON.encode . namedColumnHash <$> columns table conn
printColumns :: Int -> T.Text -> Connection -> IO BL.ByteString
printColumns schema table conn = JSON.encode . namedColumnHash <$> columns schema table conn