We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
import os import asyncpg import logging # Singleton _db = None async def get(): # Get singleton global _db # Return database singleton if already connected if _db: return _db # Log to console logging.info("Connecting to database") _db = await asyncpg.connect( database = os.getenv("DB_NAME","defaultdb"), user = os.getenv("DB_USER", "root"), password = os.getenv("DB_PASS", "root"), host = os.getenv("DB_HOST", "localhost"), port = os.getenv("DB_PORT", "26257") ) # Return database singleton return _db async def main(): from datetime import datetime db = await get() start = datetime.now() await db.fetch("SELECT * FROM EVENTS") stop = datetime.now() print(stop-start) start = datetime.now() await db.fetch("SELECT * FROM EVENTS") stop = datetime.now() print(stop-start) # Entry point if __name__ == "__main__": import asyncio asyncio.run(main())
There is a huge 7 seconds delay running the first query. Subsequent queries are very fast.
(.venv) > python src/database2.py 0:00:06.947757 0:00:00.000738
The text was updated successfully, but these errors were encountered:
Possibly a duplicate of #1158
Sorry, something went wrong.
Yeah, dupe of #1158. Closing.
No branches or pull requests
uvloop?: don't know?
There is a huge 7 seconds delay running the first query. Subsequent queries are very fast.
The text was updated successfully, but these errors were encountered: