Future-proof way to access a global DB object
See original GitHub issueHi,
I am trying to pass a db connection objection to all my routes (on demand) and my first guess would be an equivalent of current_app
object like we do in flask.
I have seen issues #226 and #374 discussing similar concerns but I am not sure if there is any definite way to do it. And by saying definite I mean to not break our universe in a future version (potentially v1.0.0)
I would say request['app']
is very intriguing to use but I would like to know your thoughts first
Cheers, Periklis
Issue Analytics
- State:
- Created 4 years ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
Kafka, JSON, DevOps: Future Proof Your IBM i With Secure ...
APIs allow outside applications to access data and functions in real time. Many IBM i users are replacing FTP file transfers, EDI and...
Read more >Does your document database provide these 3 critical ...
Oracle Autonomous JSON Database is part of Oracle Autonomous Database ... Ensure you future-proof your applications today! ... Enter JSON.
Read more >PHP objects and shared database connection - Stack Overflow
I'd say this makes for a better more future proof approach to database access in php oop scripts. Share.
Read more >Doing Power BI the Right Way: 1. Futureproofing Power BI ...
Power Query or Power BI Dataflows · Define the technical audience · Establish solution ownership · Continuation plan (if they were to leave?)...
Read more >Accessing Session-Global Data | Framework | Vaadin 8 Docs
Applications typically need to access some objects from practically all user interface code, such as a user object, a business data model, ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think what you’re looking for is
request.state
.You can include a middleware class that attaches a mongo connection instance (or whatever else) to the request, which will then be available anywhere you’re passing the request around.
If you need that to work lazily, then you’d need the object that you’re attaching to deal with only acquiring the connection at the first point it’s actually used.
Passing a
database
instance that’s declared once, globally, will do what you need here. Have a look over https://www.starlette.io/database/This example service that I’m building out also takes the same approach, so might be a good place to look.