Skip to content
This repository has been archived by the owner on Aug 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #10 from projectweekend/master
Browse files Browse the repository at this point in the history
Remove JSON functions
  • Loading branch information
Brian Hines committed Jan 6, 2016
2 parents d2d647a + e1dceda commit dc1b3da
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 18 deletions.
4 changes: 2 additions & 2 deletions pg_table_markdown/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ def cli(database_url, table_schema, output_file):

cursor = db.cursor()
cursor.execute(build_schema_query(table_schema=table_schema))
result = cursor.fetchone()
results = cursor.fetchall()
cursor.close()

parsed = parse_schema_data(schema_data=result[0])
parsed = parse_schema_data(schema_data=results)
with open(output_file, 'w') as f:
for table_name in sorted(parsed.keys()):
f.write(SECTION_HEADING.format(table_name))
Expand Down
9 changes: 8 additions & 1 deletion pg_table_markdown/database.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import psycopg2
from psycopg2.extras import RealDictCursor
try:
from urllib.parse import urlparse
except ImportError:
Expand All @@ -19,7 +20,13 @@ def database_connection(database_url):
database = parsed.path.strip('/')

try:
connection = psycopg2.connect(host=host, port=port, user=user, password=password, database=database)
connection = psycopg2.connect(
host=host,
port=port,
user=user,
password=password,
database=database,
cursor_factory=RealDictCursor)
except psycopg2.OperationalError:
raise UnableToConnectToDatabase
connection.set_session(autocommit=True)
Expand Down
24 changes: 10 additions & 14 deletions pg_table_markdown/queries.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
def build_schema_query(table_schema):
schema_query = """
WITH table_schema_info AS (
SELECT table_name,
column_name,
column_default,
is_nullable,
data_type,
character_maximum_length
FROM information_schema.columns
WHERE table_schema = '{0}'
ORDER BY table_name,
ordinal_position
)
SELECT JSON_AGG(table_schema_info.*)
FROM table_schema_info;
SELECT table_name,
column_name,
column_default,
is_nullable,
data_type,
character_maximum_length
FROM information_schema.columns
WHERE table_schema = '{0}'
ORDER BY table_name,
ordinal_position
""".format(table_schema)
return schema_query
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

setup(
name='pg-table-markdown',
version='1.0.3',
version='1.0.4',
author='Vokal',
author_email='pypi@vokal.io',
description='A command line tool that generates markdown documentation for Postgres tables in a given schema',
Expand Down

0 comments on commit dc1b3da

Please sign in to comment.