diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-04-23 18:38:01 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2011-04-23 18:38:01 -0400 |
| commit | 02fa8bacaa69f1a4b246bed0f0b89998e33ae847 (patch) | |
| tree | 4879a8c0384d659cca11229e4f4f9023775ac57a /lib/sqlalchemy/orm/query.py | |
| parent | 24e6c56da8cd38a203021639172da0f6fad87f3b (diff) | |
| download | sqlalchemy-02fa8bacaa69f1a4b246bed0f0b89998e33ae847.tar.gz | |
- added Query.with_session() method, switches
Query to use a different session.
- horizontal shard query should use execution
options per connection as per [ticket:2131]
Diffstat (limited to 'lib/sqlalchemy/orm/query.py')
| -rw-r--r-- | lib/sqlalchemy/orm/query.py | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/lib/sqlalchemy/orm/query.py b/lib/sqlalchemy/orm/query.py index ef42e0d3a..75fd5870e 100644 --- a/lib/sqlalchemy/orm/query.py +++ b/lib/sqlalchemy/orm/query.py @@ -773,6 +773,14 @@ class Query(object): m = _MapperEntity(self, entity) self._setup_aliasizers([m]) + @_generative() + def with_session(self, session): + """Return a :class:`Query` that will use the given :class:`.Session`. + + """ + + self.session = session + def from_self(self, *entities): """return a Query that selects from this Query's SELECT statement. @@ -1766,13 +1774,18 @@ class Query(object): self.session._autoflush() return self._execute_and_instances(context) - def _execute_and_instances(self, querycontext): + def _connection_from_session(self, **kw): conn = self.session.connection( + **kw) + if self._execution_options: + conn = conn.execution_options(**self._execution_options) + return conn + + def _execute_and_instances(self, querycontext): + conn = self._connection_from_session( mapper = self._mapper_zero_or_none(), clause = querycontext.statement, close_with_result=True) - if self._execution_options: - conn = conn.execution_options(**self._execution_options) result = conn.execute(querycontext.statement, self._params) return self.instances(result, querycontext) |
