This commit is contained in:
Lev Kokotov
2023-04-22 07:40:21 -07:00
parent 62b2d994c1
commit ab7ac16974
6 changed files with 139 additions and 16 deletions

View File

@@ -0,0 +1,57 @@
import psycopg2
import asyncio
import asyncpg
def regular_main():
# Connect to the PostgreSQL database
conn = psycopg2.connect(
host="localhost",
database="sharded_db",
user="sharding_user",
password="sharding_user",
port=6432,
)
# Open a cursor to perform database operations
cur = conn.cursor()
# Execute a SQL query
cur.execute("SELECT 1")
# Fetch the results
rows = cur.fetchall()
# Print the results
for row in rows:
print(row[0])
# Close the cursor and the database connection
cur.close()
conn.close()
async def main():
# Connect to the PostgreSQL database
conn = await asyncpg.connect(
host="localhost",
database="sharded_db",
user="sharding_user",
password="sharding_user",
port=6432,
)
# Execute a SQL query
for _ in range(25):
rows = await conn.fetch("SELECT 1")
# Print the results
for row in rows:
print(row[0])
# Close the database connection
await conn.close()
regular_main()
asyncio.run(main())

View File

@@ -1,2 +1,11 @@
asyncio==3.4.3
asyncpg==0.27.0
black==23.3.0
click==8.1.3
mypy-extensions==1.0.0
packaging==23.1
pathspec==0.11.1
platformdirs==3.2.0
psutil==5.9.1
psycopg2==2.9.3
psutil==5.9.1
tomli==2.0.1