Python
  • index
  • Basic - 1
  • Basic - 2
  • SQLAlchemy
  • Decorator
  • @property
  • __dict__
  • pathlib
  • class
  • flask
  • Jupyter Notebook
  • PyQt
  • UD - FLASK - PY Basic
  • UD - FLASK - REST
  • UD - FLASK - vanilla SQL
  • UD - FLASK - SQLAlchemy
  • UD - FLASK - JWT
  • UD - FLASK - Serialization
Powered by GitBook
On this page
  • 1. Engines: db connection
  • Pool = to improve performance.
  • Dialects = adopt to different DB.
  • 2. Session vs Connection
  • 3. Sessions: sync orm & db
  • 4. Base: base class for all models

Was this helpful?

SQLAlchemy

PreviousBasic - 2NextDecorator

Last updated 5 years ago

Was this helpful?

1. Engines: db connection

Engines = manage Pools and Dialects.

engine = create_engine('postgresql://usr:pass@localhost:5432/sqlalchemy')

creating an engine does not connect to the database instantly

Pool = to improve performance.

  1. Opening and maintaining new connections is expensive

  2. Easier management of # of connections simultaneously.

Dialects = adopt to different DB.

2. Session vs Connection

session = exec ORM sql query

connection = exec RAW sql query

3. Sessions: sync orm & db

  1. modifications ORM tracked & applied to DB.

  2. guarantee the database consistency.

# create a configured "Session" class
Session = sessionmaker(bind=engine)

# create a Session
session = Session()

4. Base: base class for all models

Base = declarative_base()
https://auth0.com/blog/sqlalchemy-orm-tutorial-for-python-developers/