Comments (6)
Actually it's not obvious if that'd be best or not.
Forcing explicit connection is a good way to ensure correct setup. If we just lazily establish the connection pool, then eg. it's easier to accidentally omit startup/shutdown events when integrating databases
with a web framework.
from databases.
Anyways let's close this issue off. We're good as we are.
Thanks for the extra feedback on it! 😄
from databases.
Just my two cents ...
Forcing explicit connection is a good way to ensure correct setup.
I agree. There was no single async service I made (either using Twisted or "now" with asyncio) that didn't required explicit connection handling in a use cycle ... Of course, you can always use the NullPoll
with Postgres behind pgBounce, but not everyone deploys that strategy into production.
There are good patterns to be used out there to handle this, not to mention the @transaction
and context managers already implemented to do that in the package. 👍
it's easier to accidentally omit startup/shutdown events when integrating
databases
with a web framework.
What do you mean? Leave a connection open after the request lifecycle is finished or leave the database open when shutting down the server (assuming it's an asyncio server) ?
from databases.
I mean if we force explicit connects, then it's also more likely that users will remember to use explicit disconnects too.
(If your test cases make sure to startup/shutdown the web application then this ties in nicely with making sure that force_rollback
runs at the end of every test case.)
Eg. in Starlette we'd expect users to integrate like so:
@app.on_event('startup')
async def startup():
await database.connect()
@app.on_event('shutdown')
async def shutdown():
await database.disconnect()
from databases.
The example you gave is exactly what I had in mind (relative to asyncio servers). And no need to thank me, we really need some effort on this (databases, ORMs, etc). I would not say that we (developers) feel "abandoned" in the asyncio database special area, but the ecossystem is really not that rich when it comes to that. I hope this changes in the future 😉
from databases.
Is there any existing option to enable lazy loading rather than me implementing it from scratch? 🤔
from databases.
Related Issues (20)
- Unable to retrieve foreignkey relation object from select statement HOT 2
- Password containing `/` cannot be used (MySQL)
- Support for UNIX domain socket for MySQL
- No module named 'asyncmy.connection' on python 3.11.3
- Warn for open transactions when a connection is garbage collected
- Unable to connect to database in docker
- MySQL Connection Pool Doesn't Seem to Work HOT 3
- Drop support for python 3.7 HOT 1
- New test `test_should_remove_ref_on_disconnect` in 0.8.0 fails on Fedora Linux HOT 10
- `IndexError` on force_rollback of Transaction in tests. HOT 13
- ImportError Postgresql HOT 1
- Transaction and gather HOT 2
- session manager/ session maker
- Allow passing string values for ssl query string in PostgreSQL URL HOT 1
- Version not match (0.8.0) depends on sqlalchemy (>=1.4.42,<1.5) HOT 2
- mypy's "has no attribute" error
- create table does not create unique keys and indexes
- new 0.8 version for sqlite connection with '?mode=ro' not working, Error can't open database
- Caching disabled in sqlalchemy queries HOT 1
- Potential Inefficiency in Connection Management Leading to "Too Many Connections" Error HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from databases.