Bootstrap Sequence¶
Warning
This section is for contributing developers of the uvicore source code. Or for folks who just wish to learn how uvicore works under the hood!
Flow¶
- Uvicore is booted and raises the AppEvents.Booted event
- database/package/provider.py
- Handles the event with
AppEvents.Booted.listen(bootstrap.Database)
- Handles the event with
- database/package/bootstrap.py
__call__method- Builds
Dict()of all packages withdatabaseconnections - Builds
Listof all packages models - Builds
Listof all packages tables - Then calls
uvicore.db.init(app_default or last_default, connections)- Found in
uvicore/database/db.py
- Found in
- Builds
- database/db.py
init()method- Fills out each connection detail + SA URL
- Creates SQLAlchemy sync or async engines
- Stored in
self._enginesaccessible atuvicore.db.engines - Using
create_async_engine(conn_url, connect_args=connection.options) - Or
sa.create_engine(conn_url, connect_args=connection.options, pool_pre_ping=True) - No
engine.connect()takes place until an actual query is made, then it is closed.
- Stored in
- Creates SQLAlchemy metadata
- Stored in
self._metadatasaccessible atuvicore.db.metadatas - All tables defined in a users package are linked tot his connection specific metadata by database/table.py which is inherited from each users table definition.
- Stored in
- Back in
uvicore/database/package/bootstrap.pyafterdb init()- Dynamically Import all
modelmodules defined by all packages - Dynamically Import all
tablemodules defined by all packages- When these tables are imported, they bind themselves to proper SQLAlchemy MetaData (
db.metadatas) because of their database/table.py inheritance!
- When these tables are imported, they bind themselves to proper SQLAlchemy MetaData (
- Dynamically Import all