Repaso
EspaƱol
Backend & APIsIntermediateAPI-14

In SQLAlchemy, what is the Session primarily?

Options

  1. An HTTP session that identifies the user who is logged in
  2. A unit of work that tracks loaded objects and flushes changes (Correct option)
  3. A connection string that points to the database server
  4. A migration tool that changes the schema of the database

Answer

A unit of work that tracks loaded objects and flushes changes in a transaction

Why

The SQLAlchemy Session keeps track of the objects you loaded or added. When you change them, it remembers what changed.

On commit(), it sends all the changes to the database together as one transaction.

Use one session per request (or unit of work), and never share a session between threads.

Remember

Session = tracks your changes and commits them together.

Key terms

Practice this question in Repaso