Participer au site avec un Tip
Rechercher
 

Améliorations / Corrections

Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.

Emplacement :

Description des améliorations :

Vous êtes un professionnel et vous avez besoin d'une formation ? RAG (Retrieval-Augmented Generation)
et Fine Tuning d'un LLM
Voir le programme détaillé
Module « sqlalchemy.orm »

Classe « Session »

Informations générales

Héritage

builtins.object
    EventTarget
builtins.object
    _SessionClassMethods
        Session

Définition

class Session(_SessionClassMethods, EventTarget):

help(Session)

Manages persistence operations for ORM-mapped objects.

The :class:`_orm.Session` is **not safe for use in concurrent threads.**.
See :ref:`session_faq_threadsafe` for background.

The Session's usage paradigm is described at :doc:`/orm/session`.


Constructeur(s)

Signature du constructeur Description
__init__(self, bind: 'Optional[_SessionBind]' = None, *, autoflush: 'bool' = True, future: 'Literal[True]' = True, expire_on_commit: 'bool' = True, autobegin: 'bool' = True, twophase: 'bool' = False, binds: 'Optional[Dict[_SessionBindKey, _SessionBind]]' = None, enable_baked_queries: 'bool' = True, info: 'Optional[_InfoType]' = None, query_cls: 'Optional[Type[Query[Any]]]' = None, autocommit: 'Literal[False]' = False, join_transaction_mode: 'JoinTransactionMode' = 'conditional_savepoint', close_resets_only: 'Union[bool, _NoArg]' = _NoArg.NO_ARG) Construct a new :class:`_orm.Session`. [extrait de __init__.__doc__]

Liste des attributs statiques

Nom de l'attribut Valeur
connection_callableNone
dispatch<sqlalchemy.event.base.SessionEventsDispatch object at 0x0000020DA13367A0>
info<sqlalchemy.util.langhelpers._memoized_property object at 0x0000020DA126E690>
no_autoflush<sqlalchemy.util.langhelpers._non_memoized_property object at 0x0000020DA126E6F0>

Liste des propriétés

Nom de la propriétéDescription
deletedThe set of all instances marked as 'deleted' within this ``Session`` [extrait de deleted.__doc__]
dirtyThe set of all persistent instances considered dirty. [extrait de dirty.__doc__]
is_activeTrue if this :class:`.Session` not in "partial rollback" state. [extrait de is_active.__doc__]
newThe set of all instances marked as 'new' within this ``Session``. [extrait de new.__doc__]

Liste des opérateurs

Signature de l'opérateur Description
__contains__(self, instance: 'object') -> 'bool' Return True if the instance is associated with this session. [extrait de __contains__.__doc__]

Opérateurs hérités de la classe object

__eq__, __ge__, __gt__, __le__, __lt__, __ne__

Liste des méthodes

Toutes les méthodes Méthodes d'instance Méthodes statiques Méthodes dépréciées
Signature de la méthodeDescription
__enter__(self: '_S') -> '_S'
__exit__(self, type_: 'Any', value: 'Any', traceback: 'Any') -> 'None'
__iter__(self) -> 'Iterator[object]' Iterate over all pending or persistent instances within this [extrait de __iter__.__doc__]
add(self, instance: 'object', _warn: 'bool' = True) -> 'None' Place an object into this :class:`_orm.Session`. [extrait de add.__doc__]
add_all(self, instances: 'Iterable[object]') -> 'None' Add the given collection of instances to this :class:`_orm.Session`. [extrait de add_all.__doc__]
begin(self, nested: 'bool' = False) -> 'SessionTransaction' Begin a transaction, or nested transaction, [extrait de begin.__doc__]
begin_nested(self) -> 'SessionTransaction' Begin a "nested" transaction on this Session, e.g. SAVEPOINT. [extrait de begin_nested.__doc__]
bind_mapper(self, mapper: '_EntityBindKey[_O]', bind: '_SessionBind') -> 'None' Associate a :class:`_orm.Mapper` or arbitrary Python class with a [extrait de bind_mapper.__doc__]
bind_table(self, table: 'TableClause', bind: '_SessionBind') -> 'None' Associate a :class:`_schema.Table` with a "bind", e.g. an [extrait de bind_table.__doc__]
bulk_insert_mappings(self, mapper: 'Mapper[Any]', mappings: 'Iterable[Dict[str, Any]]', return_defaults: 'bool' = False, render_nulls: 'bool' = False) -> 'None' Perform a bulk insert of the given list of mapping dictionaries. [extrait de bulk_insert_mappings.__doc__]
bulk_save_objects(self, objects: 'Iterable[object]', return_defaults: 'bool' = False, update_changed_only: 'bool' = True, preserve_order: 'bool' = True) -> 'None' Perform a bulk save of the given list of objects. [extrait de bulk_save_objects.__doc__]
bulk_update_mappings(self, mapper: 'Mapper[Any]', mappings: 'Iterable[Dict[str, Any]]') -> 'None' Perform a bulk update of the given list of mapping dictionaries. [extrait de bulk_update_mappings.__doc__]
close(self) -> 'None' Close out the transactional resources and ORM objects used by this [extrait de close.__doc__]
commit(self) -> 'None' Flush pending changes and commit the current transaction. [extrait de commit.__doc__]
connection(self, bind_arguments: 'Optional[_BindArguments]' = None, execution_options: 'Optional[CoreExecuteOptionsParameter]' = None) -> 'Connection' Return a :class:`_engine.Connection` object corresponding to this [extrait de connection.__doc__]
delete(self, instance: 'object') -> 'None' Mark an instance as deleted. [extrait de delete.__doc__]
enable_relationship_loading(self, obj: 'object') -> 'None' Associate an object with this :class:`.Session` for related [extrait de enable_relationship_loading.__doc__]
execute(self, statement: 'Executable', params: 'Optional[_CoreAnyExecuteParams]' = None, *, execution_options: 'OrmExecuteOptionsParameter' = immutabledict({}), bind_arguments: 'Optional[_BindArguments]' = None, _parent_execute_state: 'Optional[Any]' = None, _add_event: 'Optional[Any]' = None) -> 'Result[Any]' Execute a SQL expression construct. [extrait de execute.__doc__]
expire(self, instance: 'object', attribute_names: 'Optional[Iterable[str]]' = None) -> 'None' Expire the attributes on an instance. [extrait de expire.__doc__]
expire_all(self) -> 'None' Expires all persistent instances within this Session. [extrait de expire_all.__doc__]
expunge(self, instance: 'object') -> 'None' Remove the `instance` from this ``Session``. [extrait de expunge.__doc__]
expunge_all(self) -> 'None' Remove all object instances from this ``Session``. [extrait de expunge_all.__doc__]
flush(self, objects: 'Optional[Sequence[Any]]' = None) -> 'None' Flush all the object changes to the database. [extrait de flush.__doc__]
get(self, entity: '_EntityBindKey[_O]', ident: '_PKIdentityArgument', *, options: 'Optional[Sequence[ORMOption]]' = None, populate_existing: 'bool' = False, with_for_update: 'ForUpdateParameter' = None, identity_token: 'Optional[Any]' = None, execution_options: 'OrmExecuteOptionsParameter' = immutabledict({}), bind_arguments: 'Optional[_BindArguments]' = None) -> 'Optional[_O]' Return an instance based on the given primary key identifier, [extrait de get.__doc__]
get_bind(self, mapper: 'Optional[_EntityBindKey[_O]]' = None, *, clause: 'Optional[ClauseElement]' = None, bind: 'Optional[_SessionBind]' = None, _sa_skip_events: 'Optional[bool]' = None, _sa_skip_for_implicit_returning: 'bool' = False, **kw: 'Any') -> 'Union[Engine, Connection]' Return a "bind" to which this :class:`.Session` is bound. [extrait de get_bind.__doc__]
get_nested_transaction(self) -> 'Optional[SessionTransaction]' Return the current nested transaction in progress, if any. [extrait de get_nested_transaction.__doc__]
get_one(self, entity: '_EntityBindKey[_O]', ident: '_PKIdentityArgument', *, options: 'Optional[Sequence[ORMOption]]' = None, populate_existing: 'bool' = False, with_for_update: 'ForUpdateParameter' = None, identity_token: 'Optional[Any]' = None, execution_options: 'OrmExecuteOptionsParameter' = immutabledict({}), bind_arguments: 'Optional[_BindArguments]' = None) -> '_O' Return exactly one instance based on the given primary key [extrait de get_one.__doc__]
get_transaction(self) -> 'Optional[SessionTransaction]' Return the current root transaction in progress, if any. [extrait de get_transaction.__doc__]
in_nested_transaction(self) -> 'bool' Return True if this :class:`_orm.Session` has begun a nested [extrait de in_nested_transaction.__doc__]
in_transaction(self) -> 'bool' Return True if this :class:`_orm.Session` has begun a transaction. [extrait de in_transaction.__doc__]
invalidate(self) -> 'None' Close this Session, using connection invalidation. [extrait de invalidate.__doc__]
is_modified(self, instance: 'object', include_collections: 'bool' = True) -> 'bool' Return ``True`` if the given instance has locally [extrait de is_modified.__doc__]
merge(self, instance: '_O', *, load: 'bool' = True, options: 'Optional[Sequence[ORMOption]]' = None) -> '_O' Copy the state of a given instance into a corresponding instance [extrait de merge.__doc__]
prepare(self) -> 'None' Prepare the current transaction in progress for two phase commit. [extrait de prepare.__doc__]
query(self, *entities: '_ColumnsClauseArgument[Any]', **kwargs: 'Any') -> 'Query[Any]' Return a new :class:`_query.Query` object corresponding to this [extrait de query.__doc__]
refresh(self, instance: 'object', attribute_names: 'Optional[Iterable[str]]' = None, with_for_update: 'ForUpdateParameter' = None) -> 'None' Expire and refresh attributes on the given instance. [extrait de refresh.__doc__]
reset(self) -> 'None' Close out the transactional resources and ORM objects used by this [extrait de reset.__doc__]
rollback(self) -> 'None' Rollback the current transaction in progress. [extrait de rollback.__doc__]
scalar(self, statement: 'Executable', params: 'Optional[_CoreSingleExecuteParams]' = None, *, execution_options: 'OrmExecuteOptionsParameter' = immutabledict({}), bind_arguments: 'Optional[_BindArguments]' = None, **kw: 'Any') -> 'Any' Execute a statement and return a scalar result. [extrait de scalar.__doc__]
scalars(self, statement: 'Executable', params: 'Optional[_CoreAnyExecuteParams]' = None, *, execution_options: 'OrmExecuteOptionsParameter' = immutabledict({}), bind_arguments: 'Optional[_BindArguments]' = None, **kw: 'Any') -> 'ScalarResult[Any]' Execute a statement and return the results as scalars. [extrait de scalars.__doc__]

Méthodes héritées de la classe EventTarget

__init_subclass__, __subclasshook__

Méthodes héritées de la classe _SessionClassMethods

close_all, identity_key, object_session

Méthodes héritées de la classe object

__delattr__, __dir__, __format__, __getattribute__, __getstate__, __hash__, __reduce__, __reduce_ex__, __repr__, __setattr__, __sizeof__, __str__

Vous êtes un professionnel et vous avez besoin d'une formation ? Programmation Python
Les compléments
Voir le programme détaillé