Skip to content

Commit

Permalink
Magic table!
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 25, 2011
1 parent 7e0e936 commit 61b6702
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ Version 0.10
an RuntimeError instead of being None.
- added session options to constructor.
- fixed a broken `__repr__`
- `db.Table` is now a factor function that creates table objects.
This makes it possible to omit the metadata.

Version 0.9
```````````
Expand Down
10 changes: 10 additions & 0 deletions flaskext/sqlalchemy.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,21 @@ def _create_scoped_session(db, options):
return orm.scoped_session(partial(_SignallingSession, db, **options))


def _make_table(db):
def _make_table(*args, **kwargs):
if len(args) > 1 and isinstance(args[1], db.Column):
args = (args[0], db.metadata) + args[2:]
return sqlalchemy.Table(*args, **kwargs)
return _make_table



def _include_sqlalchemy(obj):
for module in sqlalchemy, sqlalchemy.orm:
for key in module.__all__:
if not hasattr(obj, key):
setattr(obj, key, getattr(module, key))
obj.Table = _make_table(obj)


class _DebugQueryTuple(tuple):
Expand Down

0 comments on commit 61b6702

Please sign in to comment.