Essential SQLAlchemy: Chapter 8 (P.I)
This commit is contained in:
@@ -1,5 +1,10 @@
|
|||||||
#+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:{} _:{} -:t f:t *:t <:t todo:t
|
#+OPTIONS: H:3 num:t toc:t \n:nil @:t ::t |:t ^:{} _:{} -:t f:t *:t <:t todo:t
|
||||||
#+KEYWORDS: sqlalchemy alembic orm
|
#+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: <link rel="stylesheet" type="text/css" href="solarized-dark.css" />
|
||||||
|
#+HTML_LINK_HOME: https://pimiento.github.io/
|
||||||
|
#+HTML_LINK_UP: https://pimiento.github.io/
|
||||||
#+TITLE: Essential SQLAlchemy (v1/v2)
|
#+TITLE: Essential SQLAlchemy (v1/v2)
|
||||||
|
|
||||||
* Chapter 1: Schema and Types
|
* Chapter 1: Schema and Types
|
||||||
@@ -144,7 +149,7 @@
|
|||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
#+NAME: E1
|
#+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"
|
||||||
<<A1>>
|
<<A1>>
|
||||||
<<B1>>
|
<<B1>>
|
||||||
<<C1>>
|
<<C1>>
|
||||||
@@ -157,7 +162,7 @@
|
|||||||
|
|
||||||
|
|
||||||
** SQLAlchemy v2
|
** 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
|
#!/usr/bin/env python3
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
@@ -3865,7 +3870,7 @@ Table(
|
|||||||
session = Session()
|
session = Session()
|
||||||
#+END_SRC
|
#+END_SRC
|
||||||
|
|
||||||
#+BEGIN_SRC python :noweb yes :results none
|
#+BEGIN_SRC python :results none
|
||||||
<<MyBase>>
|
<<MyBase>>
|
||||||
<<User>>
|
<<User>>
|
||||||
<<Order>>
|
<<Order>>
|
||||||
@@ -4864,3 +4869,31 @@ Table(
|
|||||||
for u in session.scalars(stmt):
|
for u in session.scalars(stmt):
|
||||||
print(u)
|
print(u)
|
||||||
#+END_SRC
|
#+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()
|
||||||
|
|
||||||
|
<<MyBase>>
|
||||||
|
<<User>>
|
||||||
|
<<Order>>
|
||||||
|
<<LineItem>>
|
||||||
|
|
||||||
|
Base.metadata.create_all(engine)
|
||||||
|
#+END_SRC
|
||||||
|
|
||||||
|
** SQLAlchemy v2
|
||||||
|
:PROPERTIES:
|
||||||
|
:header-args:python: :session *ch8-v2* :tangle ch8-v2.py :cache yes
|
||||||
|
:END:
|
||||||
|
|||||||
Reference in New Issue
Block a user