You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was considering the possibility of using ormar in my projects and I have a question about the architectural design of the library. Namely to create models with predefined configuration in OrmarConfig.
This design forces me to have a module-level (import-time) database configuration. That is, the database configuration should already exist at the time I define the model classes. This works for toy examples, but can be a problem in real large applications when the application configuration is not loaded at import-time. I'm not in favor of having any import-time application logic at all.
I'd say this kind of design isn't exactly declarative. It is rather imperative. SQLAlchemy/SQLModel/TortoiseORM don't obligate me to have some import-time database configuration. In Pydantic/dataclasses I can use default_factory to define a callable to get default values at run-time. So, it's just a declarative definition of models and that's all. I can load the config in run-time at application startup, create an engine on-demand, etc. I can flexibly manage this depending on the environment, also it's easy to test.
So I'm a bit confused and still don't understand how I can use ormar in our projects where all the configuration loading logic is done in run-time rather than import-time.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I was considering the possibility of using ormar in my projects and I have a question about the architectural design of the library. Namely to create models with predefined configuration in
OrmarConfig
.Here is an example from the docs:
This design forces me to have a module-level (import-time) database configuration. That is, the database configuration should already exist at the time I define the model classes. This works for toy examples, but can be a problem in real large applications when the application configuration is not loaded at import-time. I'm not in favor of having any import-time application logic at all.
I'd say this kind of design isn't exactly declarative. It is rather imperative. SQLAlchemy/SQLModel/TortoiseORM don't obligate me to have some import-time database configuration. In Pydantic/dataclasses I can use
default_factory
to define a callable to get default values at run-time. So, it's just a declarative definition of models and that's all. I can load the config in run-time at application startup, create an engine on-demand, etc. I can flexibly manage this depending on the environment, also it's easy to test.So I'm a bit confused and still don't understand how I can use ormar in our projects where all the configuration loading logic is done in run-time rather than import-time.
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions