Przeglądaj źródła

Publish first article on SQLAlchemy

theenglishway@shineon 7 lat temu
rodzic
commit
efa315d4c2

+ 16 - 8
content/posts/sqlalchemy-intro-en.md

@@ -1,11 +1,12 @@
 Slug: sqlalchemy-intro
 Slug: sqlalchemy-intro
 Title: SQLAlchemy is no sorcery !
 Title: SQLAlchemy is no sorcery !
-Category: Le développement web pour les nuls
-Tags: développement, SQLAlchemy, Python, web
-Summary:
+Category: Je tisse ma toile
+Tags: développement, SQLAlchemy, Python, web, un peu compliqué quand même
+Summary: A first contact with SQLAlchemy
+Created: 2018/08/10 08:00
 Image: /images/sqlalchemy_logo.png
 Image: /images/sqlalchemy_logo.png
 Lang: en
 Lang: en
-Status: draft
+Status: published
 
 
 ___
 ___
 
 
@@ -62,8 +63,8 @@ table name, primary key, ...)
         name = Column(String)
         name = Column(String)
         fullname = Column(String)
         fullname = Column(String)
 
 
-All the information provided there are aggregated into the *Base* whose
-"metadata" field that now be used to assemble the whole puzzle (database
+All the information provided there is aggregated into the *Base* whose
+"metadata" field can now be used to assemble the whole puzzle (database
 connection and schema declaration).
 connection and schema declaration).
 
 
     :::python
     :::python
@@ -77,7 +78,7 @@ create instances of user defined classes :
     In [1]: user = User(name="way", fullname="theenglishway")
     In [1]: user = User(name="way", fullname="theenglishway")
     Out [1]: <User(name='way', fullname='theenglishway')>
     Out [1]: <User(name='way', fullname='theenglishway')>
 
 
-... but those instances cannot be directly sent into the database yet (Django's
+... but those instances could not be directly sent into the database yet (Django's
 ORM would have already allowed you to call `user.save()`). You will need another
 ORM would have already allowed you to call `user.save()`). You will need another
 kind of object for that, which is at the heart of SQLAlchemy, the *session* ;
 kind of object for that, which is at the heart of SQLAlchemy, the *session* ;
 the session basically makes the connection to the database, and any transaction
 the session basically makes the connection to the database, and any transaction
@@ -150,7 +151,7 @@ An example is worth a thousand words :
     # ... in which a user is added
     # ... in which a user is added
     In [2]: session.add(User(name="way", fullname="theenglishway"))
     In [2]: session.add(User(name="way", fullname="theenglishway"))
 
 
-    # A query returns that user
+    # A query within that session returns that user
     In [3]: session.query(User).all()
     In [3]: session.query(User).all()
     Out[3]: [<User(name='way', fullname='theenglishway')>]
     Out[3]: [<User(name='way', fullname='theenglishway')>]
 
 
@@ -175,8 +176,15 @@ environment of a web framework that handles request in a given thread : one
 should take care to use [**_scoped sessions_**][sqlalchemy-sessions]
 should take care to use [**_scoped sessions_**][sqlalchemy-sessions]
 in that case.
 in that case.
 
 
+As a general rule, SQLAlchemy is usually even more powerful and subtle than you
+might imagine, so browsing through the
+[incredibly complete documentation][sqlalchemy-doc] is a must-read before
+anything ... and, of course, future articles of mine that will touch on that
+subject !
+
 
 
 [sqlalchemy-django]: http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/
 [sqlalchemy-django]: http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/
 [sqlalchemy-tutorial]: https://docs.sqlalchemy.org/en/latest/orm/tutorial.html
 [sqlalchemy-tutorial]: https://docs.sqlalchemy.org/en/latest/orm/tutorial.html
 [sqlalchemy-logo]: /images/sqlalchemy_logo.png
 [sqlalchemy-logo]: /images/sqlalchemy_logo.png
 [sqlalchemy-sessions]: http://docs.sqlalchemy.org/en/latest/orm/contextual.html#using-thread-local-scope-with-web-applications
 [sqlalchemy-sessions]: http://docs.sqlalchemy.org/en/latest/orm/contextual.html#using-thread-local-scope-with-web-applications
+[sqlqlchemy-doc]: https://docs.sqlalchemy.org/en/

+ 15 - 8
content/posts/sqlalchemy-intro.md

@@ -1,11 +1,12 @@
 Slug: sqlalchemy-intro
 Slug: sqlalchemy-intro
 Title: SQLAlchemy, c'est pas sorcier !
 Title: SQLAlchemy, c'est pas sorcier !
-Category: Le développement web pour les nuls
-Tags: développement, SQLAlchemy, Python, web
-Summary:
+Category: Je tisse ma toile
+Tags: développement, SQLAlchemy, Python, web, un peu compliqué quand même
+Summary: Premier contact avec SQLAlchemy
+Created: 2018/08/10 08:00
 Image: /images/sqlalchemy_logo.png
 Image: /images/sqlalchemy_logo.png
 Lang: fr
 Lang: fr
-Status: draft
+Status: published
 
 
 ___
 ___
 
 
@@ -15,7 +16,7 @@ Après plusieurs mois à me reposer sur l'ORM de Django, voici venu le temps de
 frotter à quelquechose d'un peu plus conséquent : la Rolls de l'ORM Python,
 frotter à quelquechose d'un peu plus conséquent : la Rolls de l'ORM Python,
 SQLAlchemy.
 SQLAlchemy.
 
 
-# Initialisation
+## Initialisation
 
 
 Voilà quelquechose dont je m'étais fait une montagne en survolant la
 Voilà quelquechose dont je m'étais fait une montagne en survolant la
 documentation, et qui n'est pourtant pas si complexe que cela quand on
 documentation, et qui n'est pourtant pas si complexe que cela quand on
@@ -131,7 +132,7 @@ Voici à quoi ressemble le fichier complet :
     Base.metadata.create_all(engine)
     Base.metadata.create_all(engine)
     Session = sessionmaker(bind=engine)
     Session = sessionmaker(bind=engine)
 
 
-# Utilisation basique
+## Utilisation basique
 
 
 Maintenant que l'on a une belle base de données avec une table vide, il ne reste
 Maintenant que l'on a une belle base de données avec une table vide, il ne reste
 plus qu'à l'utiliser. Contrairement à Django qui faisait beaucoup pour nous dans
 plus qu'à l'utiliser. Contrairement à Django qui faisait beaucoup pour nous dans
@@ -159,7 +160,8 @@ Un exemple vaut mille mots :
     # ... dans laquelle on ajoute un utilisateur
     # ... dans laquelle on ajoute un utilisateur
     In [2]: session.add(User(name="way", fullname="theenglishway"))
     In [2]: session.add(User(name="way", fullname="theenglishway"))
 
 
-    # Une query fait bien apparaître ce nouvel utilisateur
+    # Une requëte faite dans cette session fait bien apparaître ce nouvel
+    # utilisateur
     In [3]: session.query(User).all()
     In [3]: session.query(User).all()
     Out[3]: [<User(name='way', fullname='theenglishway')>]
     Out[3]: [<User(name='way', fullname='theenglishway')>]
 
 
@@ -177,14 +179,19 @@ Un exemple vaut mille mots :
     In [7]: session2.query(User).all()
     In [7]: session2.query(User).all()
     Out[7]: [<User(name='way', fullname='theenglishway')>]
     Out[7]: [<User(name='way', fullname='theenglishway')>]
 
 
-# Le cas des frameworks web
+## Le cas des frameworks web
 
 
 Petite subtilité importante à noter à propos des sessions utilisées dans le
 Petite subtilité importante à noter à propos des sessions utilisées dans le
 cadre d'un framework web qui traite les requêtes en utilisant un thread donné :
 cadre d'un framework web qui traite les requêtes en utilisant un thread donné :
 il faut alors utiliser des [**_scoped sessions_**][sqlalchemy-sessions].
 il faut alors utiliser des [**_scoped sessions_**][sqlalchemy-sessions].
 
 
+De manière générale, SQLAlchemy est encore plus puissant et subtil qu'il est
+possible de le concevoir au premier abord, et il est donc essentiel d'aller
+jeter un oeil à sa [documentation extrêmement complète] ... et évidemment, aux
+futurs articles que j'écrirai sur le sujet !
 
 
 [sqlalchemy-django]: http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/
 [sqlalchemy-django]: http://lucumr.pocoo.org/2011/7/19/sqlachemy-and-you/
 [sqlalchemy-tutorial]: https://docs.sqlalchemy.org/en/latest/orm/tutorial.html
 [sqlalchemy-tutorial]: https://docs.sqlalchemy.org/en/latest/orm/tutorial.html
 [sqlalchemy-logo]: /images/sqlalchemy_logo.png
 [sqlalchemy-logo]: /images/sqlalchemy_logo.png
 [sqlalchemy-sessions]: http://docs.sqlalchemy.org/en/latest/orm/contextual.html#using-thread-local-scope-with-web-applications
 [sqlalchemy-sessions]: http://docs.sqlalchemy.org/en/latest/orm/contextual.html#using-thread-local-scope-with-web-applications
+[sqlqlchemy-doc]: https://docs.sqlalchemy.org/en/