This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -128,16 +127,17 @@ For more in-depth information
on [dealing with disconnects](https://docs.sqlalchemy.org/core/pooling.html#dealing-with-disconnects){target="_blank"},
refer to SQLAlchemy's documentation on handling connection issues.
## **EllarSQLModule With App Config**
As stated above, **EllarSQLModule** can be configured from application through `EllarSQLModule.register_setup`.
This will register a [ModuleSetup](https://python-ellar.github.io/ellar/basics/dynamic-modules/#modulesetup){target="_blank"} factory that checks for `ELLAR_SQL` in application config.
The value of `ELLAR_SQL` read from the application config will be passed `EllarSQLModule` setup action
which validates and initializes the module.
## **EllarSQLModule RegisterSetup**
As mentioned earlier, **EllarSQLModule** can be configured from the application through `EllarSQLModule.register_setup`.
This process registers a [ModuleSetup](https://python-ellar.github.io/ellar/basics/dynamic-modules/#modulesetup){target="_blank"} factory
that depends on the Application Config object.
The factory retrieves the `ELLAR_SQL` attribute from the config and validates the data before passing it to `EllarSQLModule` for setup.
It's important to note
that `ELLAR_SQL` will be a dictionary object with the above [configuration parameters](#ellarsqlmodule-configuration-parameters) as keys.
It's essential to note
that `ELLAR_SQL` will be a dictionary object with the [configuration parameters](#ellarsqlmodule-configuration-parameters)
mentioned above as keys.
A Quick example:
Here's a quick example:
```python title="db_learning/root_module.py"
from ellar.common import Module, exception_handler, IExecutionContext, JSONResponse, Response, IApplicationStartup
from ellar.app import App
Expand Down
Expand Up
@@ -180,8 +180,10 @@ class DevelopmentConfig(BaseConfig):
'models': []
}
```
We have added config for **EllarSQLModule** through `ELLAR_SQL`. And from there, the rest of the actions
will be the same as to normal registration with `EllarSQLModule.setup()`.
The registered ModuleSetup factory reads the `ELLAR_SQL` value and configures the `EllarSQLModule` appropriately.
But with this approach,
we can seamlessly change **EllarSQLModule** configuration in any environment like CI, Development, Staging or Production.
This approach is particularly useful when dealing with multiple environments.
It allows for seamless modification of the **ELLAR_SQL** values in various environments such as
Continuous Integration (CI), Development, Staging, or Production.
You can easily change the settings for each environment
and export the configurations as a string to be imported into `ELLAR_CONFIG_MODULE`.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
return JSONResponse(dict(detail="Resource not found."), status_code=404)
```
In the above illustration,
we registered `UserController` and `EllarSQLModule` with some configurations on database and migration options.
See more on `EllarSQLModule` configurations.
Also, on the `on_startup` function, we retrieved `EllarSQLService` registered into the system through `EllarSQLModule`,
and call the `create_all()` function to create the SQLAlchemy tables.
In the provided code snippet:
- We registered `UserController` and `EllarSQLModule` with specific configurations for the database and migration options. For more details on [`EllarSQLModule` configurations](./configuration.md#ellarsqlmodule-config).
- In the `on_startup` method, we obtained the `EllarSQLService` from the Ellar Dependency Injection container using `EllarSQLModule`. Subsequently, we invoked the `create_all()` method to generate the necessary SQLAlchemy tables.
At this point, we are ready to test the application.
With these configurations, the application is now ready for testing.
```shell
ellar runserver --reload
```
Also,
remember to uncomment the `OpenAPIModule` configurations
in `server.py` to be able to visualize and interact with the `/users` the endpoint.
Additionally, please remember to uncomment the configurations for the `OpenAPIModule` in the `server.py`
file to enable visualization and interaction with the `/users` endpoint.
With that said, visit [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs){target="_blank"}
Once done,
you can access the OpenAPI documentation at [http://127.0.0.1:8000/docs](http://127.0.0.1:8000/docs){target="_blank"}.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Factory boy Support #11
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
Uh oh!
There was an error while loading. Please reload this page.
Factory boy Support #11
Filter by extension
Only manifest files
Deleted files Viewed files
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
There are no files selected for viewing
Uh oh!
There was an error while loading. Please reload this page.