Created
February 16, 2009 07:48
-
-
Save inklesspen/65068 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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