Documentation for stdnet 0.8.2. For development docs, go here.

Sessions

A Session is a lightweight component which establishes all conversations with backend databases. It is the middleware between Model and Router on one side and the stdnet.BackendDataServer on the other side.

Obtaining a session

Session is a regular Python class which is obtained from a Router via the Router.session() method. We continue to use the models router created for our tutorial application:

session = models.session()
session2 = models.session()

Query a model

Once a session is obtained, one can create a query on a model by simply invoking the Session.query() method:

query = session.query(models.fund)

A less verbose way of obtaining a query is to use the Manager.query() method directly:

query = models.fund.query()

Transactional State

A Session is said to be in a transactional state when its Session.transaction attribute is not None. A transactional state is obtained via the Session.begin() method:

transaction = session.begin()

The returned transaction instance is the same as the value stored at the Session.transaction attribute. Note that if we try to obtain a new transaction from a session already in a transactional state an InvalidTransaction exception will occur.

Table Of Contents

Previous topic

Full text search

Next topic

A twitter clone

This Page