From 5f68e80d940396b5e8709c85db55d97f5bbb5b54 Mon Sep 17 00:00:00 2001 From: Pavel Vavilin Date: Mon, 21 Sep 2026 12:03:01 +0500 Subject: [PATCH] Essential SQLAlchemy: Chapter 8 (P.I) --- Essential-SQLAlchemy-2nd.org | 39 +++++++++++++++++++++++++++++++++--- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/Essential-SQLAlchemy-2nd.org b/Essential-SQLAlchemy-2nd.org index 05d9e88..6e8aed8 100644 --- a/Essential-SQLAlchemy-2nd.org +++ b/Essential-SQLAlchemy-2nd.org @@ -1,5 +1,10 @@ #+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:{} _:{} -:t f:t *:t <:t todo:t #+KEYWORDS: sqlalchemy alembic orm +#+PROPERTY: header-args :eval never-export :exports both :noweb yes +#+INFOJS_OPT: view:t toc:t ltoc:t mouse:underline buttons:0 path:org-info.js +#+HTML_HEAD: +#+HTML_LINK_HOME: https://pimiento.github.io/ +#+HTML_LINK_UP: https://pimiento.github.io/ #+TITLE: Essential SQLAlchemy (v1/v2) * Chapter 1: Schema and Types @@ -144,7 +149,7 @@ #+END_SRC #+NAME: E1 -#+BEGIN_SRC python :session ch1 :results none :tangle ch1-v1.py :noweb tangle :shebang "#!/usr/bin/env python3" +#+BEGIN_SRC python :session ch1 :results none :tangle ch1-v1.py :shebang "#!/usr/bin/env python3" <> <> <> @@ -157,7 +162,7 @@ ** SQLAlchemy v2 -#+BEGIN_SRC python :results none :tangle ch1-v2.py :noweb tangle :shebang "#!/usr/bin/env python3" +#+BEGIN_SRC python :results none :tangle ch1-v2.py :shebang "#!/usr/bin/env python3" #!/usr/bin/env python3 from datetime import datetime from decimal import Decimal @@ -3865,7 +3870,7 @@ Table( session = Session() #+END_SRC -#+BEGIN_SRC python :noweb yes :results none +#+BEGIN_SRC python :results none <> <> <> @@ -4864,3 +4869,31 @@ Table( for u in session.scalars(stmt): print(u) #+END_SRC + +* Chapter 8: Understanding the Session and Exceptions + +** SQLAlchemy v1 +:PROPERTIES: +:header-args:python: :session *ch8-v1* :tangle ch8-v1.py :cache yes +:END: + +#+BEGIN_SRC python :shebang "#!/usr/bin/env python3" :results none + from sqlalchemy import create_engine + from sqlalchemy.orm import sessionmaker + + engine = create_engine("sqlite:///:memory:") + Session = sessionmaker(bind=engine) + session = Session() + + <> + <> + <> + <> + + Base.metadata.create_all(engine) +#+END_SRC + +** SQLAlchemy v2 +:PROPERTIES: +:header-args:python: :session *ch8-v2* :tangle ch8-v2.py :cache yes +:END: