Fahey-McLay / xalt

28 stars 15 forks source link

Introduce SqlAlchemy as ORM #3

Closed georg-rath closed 6 years ago

georg-rath commented 9 years ago

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

boegel commented 9 years ago

@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 master?

pforai commented 9 years ago

I think there were some commited but unpushed changes that @rtmclay just pushed a couple of minutes ago. Georg rebasing now :)