Skip to content

Instantly share code, notes, and snippets.

@inklesspen
Created February 16, 2009 07:48
Show Gist options
  • Save inklesspen/65068 to your computer and use it in GitHub Desktop.
Save inklesspen/65068 to your computer and use it in GitHub Desktop.
class FakeConnection(object):
def __init__(self):
self.storage = None
def execute(self, ddl):
self.storage = ddl
def __str__(self):
return self.storage
useless = {}
dialects = {}
exec "from sqlalchemy.databases import *" in useless, dialects
def collect_ddl(obj, dialect):
# you can pass in either the dialect object itself, or the name of the database
if isinstance(dialect, basestring):
dialect = dialects[dialect].dialect
conn = FakeConnection()
dialect.schemagenerator(dialect(), conn).traverse(obj)
return str(conn).strip()
__all__ = ['collect_ddl']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment