2023-04-22 07:40:21 -07:00
|
|
|
import psycopg2
|
|
|
|
|
import asyncio
|
|
|
|
|
import asyncpg
|
|
|
|
|
|
2023-04-22 08:02:20 -07:00
|
|
|
PGCAT_HOST = "127.0.0.1"
|
|
|
|
|
PGCAT_PORT = "6432"
|
|
|
|
|
|
2023-04-22 07:40:21 -07:00
|
|
|
|
|
|
|
|
def regular_main():
|
|
|
|
|
# Connect to the PostgreSQL database
|
|
|
|
|
conn = psycopg2.connect(
|
2023-04-22 08:02:20 -07:00
|
|
|
host=PGCAT_HOST,
|
2023-04-22 07:40:21 -07:00
|
|
|
database="sharded_db",
|
|
|
|
|
user="sharding_user",
|
|
|
|
|
password="sharding_user",
|
2023-04-22 08:02:20 -07:00
|
|
|
port=PGCAT_PORT,
|
2023-04-22 07:40:21 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 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(
|
2023-04-22 08:02:20 -07:00
|
|
|
host=PGCAT_HOST,
|
2023-04-22 07:40:21 -07:00
|
|
|
database="sharded_db",
|
|
|
|
|
user="sharding_user",
|
|
|
|
|
password="sharding_user",
|
2023-04-22 08:02:20 -07:00
|
|
|
port=PGCAT_PORT,
|
2023-04-22 07:40:21 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
# 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())
|