diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-03-20 20:12:26 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2012-03-20 20:12:26 -0400 |
| commit | 565b5dc537e8c155fb85878d477180a4c954b81f (patch) | |
| tree | 7b9d412a3e4c20f4f5aaa1c801ca055d940c6973 /lib/sqlalchemy | |
| parent | 39034288416c19a89d1809da9021910c12f250fe (diff) | |
| download | sqlalchemy-565b5dc537e8c155fb85878d477180a4c954b81f.tar.gz | |
- 0.7.7
- [feature] Added prefix_with() method
to Query, calls upon select().prefix_with()
to allow placement of MySQL SELECT
directives in statements. Courtesy
Diana Clarke [ticket:2443]
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/__init__.py | 2 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 32 |
2 files changed, 32 insertions, 2 deletions
diff --git a/lib/sqlalchemy/__init__.py b/lib/sqlalchemy/__init__.py index 03293b5dd..4e00437ea 100644 --- a/lib/sqlalchemy/__init__.py +++ b/lib/sqlalchemy/__init__.py @@ -117,7 +117,7 @@ from sqlalchemy.engine import create_engine, engine_from_config __all__ = sorted(name for name, obj in locals().items() if not (name.startswith('_') or inspect.ismodule(obj))) -__version__ = '0.7.6' +__version__ = '0.7.7' del inspect, sys diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index aa3dd0173..56d377f18 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -77,6 +77,7 @@ class Query(object): _group_by = False _having = None _distinct = False + _prefixes = None _offset = None _limit = None _statement = None @@ -917,7 +918,8 @@ class Query(object): '_order_by', '_group_by', '_limit', '_offset', '_joinpath', '_joinpoint', - '_distinct', '_having' + '_distinct', '_having', + '_prefixes', ): self.__dict__.pop(attr, None) self._set_select_from(fromclause) @@ -2057,6 +2059,33 @@ class Query(object): else: self._distinct = criterion + @_generative() + def prefix_with(self, *prefixes): + """Apply the prefixes to the query and return the newly resulting + ``Query``. + + :param \*prefixes: optional prefixes, typically strings, + not using any commas. In particular is useful for MySQL keywords. + + e.g.:: + + query = sess.query(User.name).\\ + prefix_with('HIGH_PRIORITY').\\ + prefix_with('SQL_SMALL_RESULT', 'ALL') + + Would render:: + + SELECT HIGH_PRIORITY SQL_SMALL_RESULT ALL users.name AS users_name + FROM users + + New in 0.7.7. + + """ + if self._prefixes: + self._prefixes += prefixes + else: + self._prefixes = prefixes + def all(self): """Return the results represented by this ``Query`` as a list. @@ -2468,6 +2497,7 @@ class Query(object): 'limit':self._limit, 'offset':self._offset, 'distinct':self._distinct, + 'prefixes':self._prefixes, 'group_by':self._group_by or None, 'having':self._having } |
