]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
use begin() for settting up first PK
authorMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Mar 2022 21:47:34 +0000 (17:47 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Mon, 21 Mar 2022 21:47:34 +0000 (17:47 -0400)
Change-Id: I227bbb46fbcbae1f60d3f5bb4dd2b9f41ca3dd0c

examples/sharding/separate_databases.py
examples/sharding/separate_tables.py

index accbfd79b44d103fd254c24256b426e26811a007..9818656c3c55f250b1e3dea5988ff15a4d4d6786 100644 (file)
@@ -56,7 +56,7 @@ ids = Table("ids", Base.metadata, Column("nextid", Integer, nullable=False))
 
 def id_generator(ctx):
     # in reality, might want to use a separate transaction for this.
-    with db1.connect() as conn:
+    with db1.begin() as conn:
         nextid = conn.scalar(ids.select().with_for_update())
         conn.execute(ids.update().values({ids.c.nextid: ids.c.nextid + 1}))
     return nextid
index 4314e2233799ffeb3592bd76224423442ea6b576..0f6e2ffd830560ae9bf2e84ac0c022a2364f77fc 100644 (file)
@@ -70,7 +70,7 @@ ids = Table("ids", Base.metadata, Column("nextid", Integer, nullable=False))
 
 def id_generator(ctx):
     # in reality, might want to use a separate transaction for this.
-    with engine.connect() as conn:
+    with engine.begin() as conn:
         nextid = conn.scalar(ids.select().with_for_update())
         conn.execute(ids.update().values({ids.c.nextid: ids.c.nextid + 1}))
     return nextid