MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / with_session

Method with_session

lib/sqlalchemy/orm/query.py:1360–1384  ·  view source on GitHub ↗

Return a :class:`_query.Query` that will use the given :class:`.Session`. While the :class:`_query.Query` object is normally instantiated using the :meth:`.Session.query` method, it is legal to build the :class:`_query.Query` directly without necessar

(self, session: Session)

Source from the content-addressed store, hash-verified

1358
1359 @_generative
1360 def with_session(self, session: Session) -> Self:
1361 """Return a :class:`_query.Query` that will use the given
1362 :class:`.Session`.
1363
1364 While the :class:`_query.Query`
1365 object is normally instantiated using the
1366 :meth:`.Session.query` method, it is legal to build the
1367 :class:`_query.Query`
1368 directly without necessarily using a :class:`.Session`. Such a
1369 :class:`_query.Query` object, or any :class:`_query.Query`
1370 already associated
1371 with a different :class:`.Session`, can produce a new
1372 :class:`_query.Query`
1373 object associated with a target session using this method::
1374
1375 from sqlalchemy.orm import Query
1376
1377 query = Query([MyClass]).filter(MyClass.id == 5)
1378
1379 result = query.with_session(my_session).one()
1380
1381 """
1382
1383 self.session = session
1384 return self
1385
1386 def _legacy_from_self(
1387 self, *entities: _ColumnsClauseArgument[Any]

Callers 5

_retrieve_baked_queryMethod · 0.80
_loadMethod · 0.80
test_with_sessionMethod · 0.80
_testMethod · 0.80

Calls

no outgoing calls

Tested by 3

test_with_sessionMethod · 0.64
_testMethod · 0.64