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
Introduce SqlAlchemy as ORM #3
Closed
Closed
Conversation
This file contains 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
fixed a lot of mistakes and converted the whole of XALTdb to the orm.
fixed a lot of mistakes and converted the whole of XALTdb to the orm.
Conflicts: src/XALTdb.py src/xalt_db_model.py
@georg-rath: wow, impressive (although I won't pretend to have reviewed all of this) unmergeable for now though, due to upstream changes, so you'll need to resync with upstream |
I think there were some commited but unpushed changes that @rtmclay just pushed a couple of minutes ago. Georg rebasing now :) |
fixed a lot of mistakes and converted the whole of XALTdb to the orm.
fixed a lot of mistakes and converted the whole of XALTdb to the orm.
Conflicts: src/XALTdb.py
Initialize schema is done implicitly and removal of the database should happen on the db server.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Hi Robert,
Hi Mark,
to make XALT able to speak with other databases than MySQL and to make life easier when working with databases, I have refactored XALT to use SqlAlchemy, which is an object-relational-mapper. It basically maps classes to database tables.
You'll find the classes in xalt_db_model.py. This model should be compatible with existing XALT databases. I wrote a small set of (very) rudimentary tests to make sure, that reading/writing to the database via the XALTdb class works.
The config file takes a connection string, instead of separate user, password, hostname and database settings. Format of the string is "[database dialect]://[username]:[password]@[host]/[database]", as documented here.
Creation of the database schema and checking for validity is done automatically by SqlAlchemy, when connecting to the database.
I think having an ORM to take care of the database handling is much more flexible, than doing all that stuff by hand. Although it creates and additional layer of abstraction I find it much easier to work with Python classes and let SqlAlchemy do the job of pushing that into the database. Using SqlAlchemy still allows you to use raw SQL to query the database.
Further work here is definitely adding more meaningful tests and introducing a tool that can handle database migrations (schema changes), like Alembic.
Let me know if you think this is worth merging.
Best regards,
Georg
/cc @itkovian @JensTimmerman @boegel