Skip to content

Commit 1b6a9d7

Browse files
author
percious
committed
better postgres support, interactive mode provides a bit more information before you play with it.
1 parent 073aaea commit 1b6a9d7

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

sqlautocode/constants.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ def getModel(metadata):
4747
model = Model()
4848
"""
4949

50+
PG_IMPORT = """\
51+
from sqlalchemy.databases.postgres import *
52+
"""
53+
5054
FOOTER_Z3C = """
5155
return model
5256
"""
@@ -102,6 +106,7 @@ def getModel(metadata):
102106
try:
103107
from IPython.Shell import IPShellEmbed
104108
print 'Success! Type <ctrl-d> to exit.'
109+
print 'Available models:%%s'%%%s
105110
ipshell = IPShellEmbed()
106111
ipshell()
107112
except:

sqlautocode/declarative.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,8 @@ def __repr__(self):
113113
if not isinstance(engine, basestring):
114114
engine = str(engine.url)
115115
s.write(constants.HEADER_DECL%engine)
116+
if 'postgres' in engine:
117+
s.write(constants.PG_IMPORT)
116118
for table in tables:
117119
s.write('%s = %s\n\n'%(table.name, self._table_repr(table)))
118120

@@ -123,7 +125,7 @@ def __repr__(self):
123125
if self.config.example or self.config.interactive:
124126
s.write(constants.EXAMPLE_DECL%models[0].__name__)
125127
if self.config.interactive:
126-
s.write(constants.INTERACTIVE)
128+
s.write(constants.INTERACTIVE%[model.__name__ for model in models])
127129
return s.getvalue()
128130

129131
@property

0 commit comments

Comments
 (0)