reformat raw sql for readability

This commit is contained in:
Adam C. Baker
2014-10-09 14:11:35 -07:00
parent ea17642f08
commit ef6b38ea1e
+26 -25
View File
@@ -117,31 +117,32 @@ tables s conn = do
columns :: String -> String -> Connection -> IO [Column] columns :: String -> String -> Connection -> IO [Column]
columns s t conn = do columns s t conn = do
r <- quickQuery conn r <- quickQuery conn
" select info.table_schema as schema, info.table_name as table_name, \ "select info.table_schema as schema, info.table_name as table_name, \
\ info.column_name as name, info.ordinal_position as position, \ \ info.column_name as name, info.ordinal_position as position, \
\ info.is_nullable as nullable, info.data_type as col_type, \ \ info.is_nullable as nullable, info.data_type as col_type, \
\ info.is_updatable as updatable, info.character_maximum_length as max_len, \ \ info.is_updatable as updatable, \
\ info.numeric_precision as precision, info.column_default as default_value,\ \ info.character_maximum_length as max_len, \
\ array_to_string(enum_info.vals, ',') as enum \ \ info.numeric_precision as precision, \
\ from ( \ \ info.column_default as default_value, \
\ select table_schema, table_name, column_name, ordinal_position, \ \ array_to_string(enum_info.vals, ',') as enum \
\ is_nullable, data_type, is_updatable, \ \ from ( \
\ character_maximum_length, numeric_precision, \ \ select table_schema, table_name, column_name, ordinal_position, \
\ column_default, udt_name \ \ is_nullable, data_type, is_updatable, \
\ from information_schema.columns \ \ character_maximum_length, numeric_precision, \
\ where table_schema = ? \ \ column_default, udt_name \
\ and table_name = ? \ \ from information_schema.columns \
\ ) as info \ \ where table_schema = ? and table_name = ? \
\ left outer join ( \ \ ) as info \
\ select n.nspname as s, \ \ left outer join ( \
\ t.typname as n, \ \ select n.nspname as s, \
\ array_agg(e.enumlabel) as vals \ \ t.typname as n, \
\ from pg_type t \ \ array_agg(e.enumlabel) as vals \
\ join pg_enum e on t.oid = e.enumtypid \ \ from pg_type t \
\ join pg_catalog.pg_namespace n ON n.oid = t.typnamespace \ \ join pg_enum e on t.oid = e.enumtypid \
\ group by s, n \ \ join pg_catalog.pg_namespace n ON n.oid = t.typnamespace \
\ ) as enum_info \ \ group by s, n \
\ on (info.udt_name = enum_info.n) \ \ ) as enum_info \
\ on (info.udt_name = enum_info.n) \
\order by position" [toSql s, toSql t] \order by position" [toSql s, toSql t]
fks <- foreignKeys s t conn fks <- foreignKeys s t conn
let lookupFK (_:_:name:_) = Map.lookup (fromSql name) fks let lookupFK (_:_:name:_) = Map.lookup (fromSql name) fks