]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
fix usage of kwargs to execute in docs
authorFederico Caselli <cfederico87@gmail.com>
Mon, 11 Mar 2024 20:58:46 +0000 (21:58 +0100)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 11 Mar 2024 20:59:00 +0000 (21:59 +0100)
Change-Id: I033cba49ba6c12113643b88e48c5917f2b70a307
(cherry picked from commit af4df5e2a2405cfef3aa26bbb8f48e24d954a370)

doc/build/core/custom_types.rst
doc/build/errors.rst
lib/sqlalchemy/dialects/postgresql/json.py
lib/sqlalchemy/sql/_elements_constructors.py
lib/sqlalchemy/sql/elements.py

index b9d8953b4e8c45a40f298f3683f785baadbeed5d..f9c0205249982df7b7f9447f143226d5d5fb6711 100644 (file)
@@ -527,7 +527,10 @@ transparently::
     with engine.begin() as conn:
         metadata_obj.create_all(conn)
 
-        conn.execute(message.insert(), username="some user", message="this is my message")
+        conn.execute(
+            message.insert(),
+            {"username": "some user", "message": "this is my message"},
+        )
 
         print(
             conn.scalar(select(message.c.message).where(message.c.username == "some user"))
index d6645123154c800c3057eb09cf9ff4d595e09a13..4c12e0fb17967fae7547964e189c8315def3aef8 100644 (file)
@@ -572,7 +572,7 @@ is executed::
 Above, no value has been provided for the parameter "my_param".  The correct
 approach is to provide a value::
 
-    result = conn.execute(stmt, my_param=12)
+    result = conn.execute(stmt, {"my_param": 12})
 
 When the message takes the form "a value is required for bind parameter <x>
 in parameter group <y>", the message is referring to the "executemany" style
index dff12e7f4988b2066ddb7e7b5bd8ee7f5bf8474d..3790fa359b1dc891fde516dc153d6bb265c6ff16 100644 (file)
@@ -155,7 +155,7 @@ class JSON(sqltypes.JSON):
          be used to persist a NULL value::
 
              from sqlalchemy import null
-             conn.execute(table.insert(), data=null())
+             conn.execute(table.insert(), {"data": null()})
 
          .. seealso::
 
index 27bac59e12627a14212d527eb038b258735b785f..77cc2a8021d3bf45a3260d408d122def69929fd8 100644 (file)
@@ -493,8 +493,9 @@ def bindparam(
 
         from sqlalchemy import bindparam
 
-        stmt = select(users_table).\
-                    where(users_table.c.name == bindparam('username'))
+        stmt = select(users_table).where(
+            users_table.c.name == bindparam("username")
+        )
 
     The above statement, when rendered, will produce SQL similar to::
 
@@ -504,22 +505,25 @@ def bindparam(
     would typically be applied at execution time to a method
     like :meth:`_engine.Connection.execute`::
 
-        result = connection.execute(stmt, username='wendy')
+        result = connection.execute(stmt, {"username": "wendy"})
 
     Explicit use of :func:`.bindparam` is also common when producing
     UPDATE or DELETE statements that are to be invoked multiple times,
     where the WHERE criterion of the statement is to change on each
     invocation, such as::
 
-        stmt = (users_table.update().
-                where(user_table.c.name == bindparam('username')).
-                values(fullname=bindparam('fullname'))
-                )
+        stmt = (
+            users_table.update()
+            .where(user_table.c.name == bindparam("username"))
+            .values(fullname=bindparam("fullname"))
+        )
 
         connection.execute(
-            stmt, [{"username": "wendy", "fullname": "Wendy Smith"},
-                   {"username": "jack", "fullname": "Jack Jones"},
-                   ]
+            stmt,
+            [
+                {"username": "wendy", "fullname": "Wendy Smith"},
+                {"username": "jack", "fullname": "Jack Jones"},
+            ],
         )
 
     SQLAlchemy's Core expression system makes wide use of
@@ -568,7 +572,7 @@ def bindparam(
     bound placeholders based on the arguments passed, as in::
 
         stmt = users_table.insert()
-        result = connection.execute(stmt, name='Wendy')
+        result = connection.execute(stmt, {"name": "Wendy"})
 
     The above will produce SQL output as::
 
@@ -1589,7 +1593,7 @@ def text(text: str) -> TextClause:
     E.g.::
 
         t = text("SELECT * FROM users WHERE id=:user_id")
-        result = connection.execute(t, user_id=12)
+        result = connection.execute(t, {"user_id": 12})
 
     For SQL statements where a colon is required verbatim, as within
     an inline string, use a backslash to escape::
@@ -1619,7 +1623,7 @@ def text(text: str) -> TextClause:
     such as for the WHERE clause of a SELECT statement::
 
         s = select(users.c.id, users.c.name).where(text("id=:user_id"))
-        result = connection.execute(s, user_id=12)
+        result = connection.execute(s, {"user_id": 12})
 
     :func:`_expression.text` is also used for the construction
     of a full, standalone statement using plain text.
index e5a9fb0624cce647c7dc15d5df00f26a8f0e6001..fe9f09e6b7a072cae1aa767c984702e720b2a90c 100644 (file)
@@ -1911,8 +1911,9 @@ class BindParameter(roles.InElementRole, KeyedColumnElement[_T]):
 
         from sqlalchemy import bindparam
 
-        stmt = select(users_table).\
-                    where(users_table.c.name == bindparam('username'))
+        stmt = select(users_table).where(
+            users_table.c.name == bindparam("username")
+        )
 
     Detailed discussion of how :class:`.BindParameter` is used is
     at :func:`.bindparam`.