ms_core.setup
conf_db(app, db_url, model_paths=None)
Registers TortoiseORM with the FastAPI application.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
FastAPI
|
An instance of the FastAPI class. |
required |
db_url
|
str
|
The database URL to connect to. |
required |
model_paths
|
list[str] | None
|
A list of paths to modules containing Tortoise models. If not provided, defaults to None. |
None
|
Returns:
Type | Description |
---|---|
None
|
None |
Source code in ms_core/setup.py
include_routers(app, routers_path)
Includes all routers in the specified directory into the FastAPI application.
The router file must contain a variable named router
, which should be an instance of fastapi.APIRouter
.
Files starting with an underscore ("_") or not ending with ".py" will be ignored.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
FastAPI
|
An instance of the FastAPI class. |
required |
routers_path
|
Path
|
The path to the directory containing router files. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If |
Returns:
Type | Description |
---|---|
None
|
None |
Source code in ms_core/setup.py
setup_app(app, db_url, routers_path, model_paths=None)
Configures the FastAPI application with TortoiseORM and includes all routers from the specified directory.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
app
|
FastAPI
|
An instance of the FastAPI class. |
required |
db_url
|
str
|
The database URL to connect to. |
required |
routers_path
|
Path
|
The path to the directory containing router files. |
required |
model_paths
|
list[str] | None
|
A list of relative paths (dot notation) to modules containing Tortoise models. If not provided, defaults to None. |
None
|
Returns:
Type | Description |
---|---|
dict
|
None |