MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / create_session

Function create_session

lib/sqlalchemy/orm/_orm_constructors.py:2116–2151  ·  view source on GitHub ↗

r"""Create a new :class:`.Session` with no automation enabled by default. This function is used primarily for testing. The usual route to :class:`.Session` creation is via its constructor or the :func:`.sessionmaker` function. :param bind: optional, a single Connectable to us

(
    bind: Optional[_SessionBind] = None, **kwargs: Any
)

Source from the content-addressed store, hash-verified

2114
2115
2116def create_session(
2117 bind: Optional[_SessionBind] = None, **kwargs: Any
2118) -> Session:
2119 r"""Create a new :class:`.Session`
2120 with no automation enabled by default.
2121
2122 This function is used primarily for testing. The usual
2123 route to :class:`.Session` creation is via its constructor
2124 or the :func:`.sessionmaker` function.
2125
2126 :param bind: optional, a single Connectable to use for all
2127 database access in the created
2128 :class:`~sqlalchemy.orm.session.Session`.
2129
2130 :param \*\*kwargs: optional, passed through to the
2131 :class:`.Session` constructor.
2132
2133 :returns: an :class:`~sqlalchemy.orm.session.Session` instance
2134
2135 The defaults of create_session() are the opposite of that of
2136 :func:`sessionmaker`; ``autoflush`` and ``expire_on_commit`` are
2137 False.
2138
2139 Usage::
2140
2141 >>> from sqlalchemy.orm import create_session
2142 >>> session = create_session()
2143
2144 It is recommended to use :func:`sessionmaker` instead of
2145 create_session().
2146
2147 """
2148
2149 kwargs.setdefault("autoflush", False)
2150 kwargs.setdefault("expire_on_commit", False)
2151 return Session(bind=bind, **kwargs)
2152
2153
2154def _mapper_fn(*arg: Any, **kw: Any) -> NoReturn:

Callers

nothing calls this directly

Calls 2

SessionClass · 0.85
setdefaultMethod · 0.45

Tested by

no test coverage detected