Skip to content
New issue

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

Decouple DB model from logic #309

Open
3 tasks
Glutexo opened this issue Jun 25, 2019 · 2 comments
Open
3 tasks

Decouple DB model from logic #309

Glutexo opened this issue Jun 25, 2019 · 2 comments
Assignees

Comments

@Glutexo
Copy link
Collaborator

Glutexo commented Jun 25, 2019

Persisting hosts into a database is a form of serialization. The Host model’s responsibility is to represent the database record. It shouldn’t on the other hand

  1. contain any logic – instantiation, operations, export
  2. represent a host in the application

This can be done in separate steps:

The logic of how the fields and values are updated are in no way related to the database storage. Decoupling allows the application to operate with a simple object representing a Host instead of a database model with a lot of added behavior. The database model would be used only for the storage/retrieval. This increases predictability of the application.

@Glutexo Glutexo assigned Glutexo and unassigned Glutexo Jun 25, 2019
@Glutexo
Copy link
Collaborator Author

Glutexo commented Jun 25, 2019

Currently working on decoupling the export methods.

@Glutexo
Copy link
Collaborator Author

Glutexo commented Jul 24, 2019

Adding that currently storing data to the database is also a kind of serialization. Splitting the database model (a SQLAlchemy object) from a business logic representation would allow to internally store the data in a smarter way. E.g. to use a namedtuple for canonical facts and a defaultdict for facts.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant