thinkle / gourmet

Gourmet Recipe Manager
GNU General Public License v2.0
338 stars 138 forks source link

Use SQLAlchemy ORM #712

Open ockham opened 11 years ago

ockham commented 11 years ago

Gourmet has seen a rather long history of database backends, from Metakit over SQLite to SQLAlchemy. As a consequence, we're still using a layer of abstraction (in gourmet/db.py) around SQLAlchemy's "core" SQL functions, that should get rid of in favor of SQLAlchemy's native ORM, which would allow for more intuitive database abstraction, particularly for developers new to Gourmet that already know SQLAlchemy. See also issue #685 (which I've started to work on -- contact @ockham if you're interested), and #686 and #682 for bonus points.

This is one of the ideas we're suggesting as a project for GSoC 2013. For general information about Gourmet's participation in GSoC 2013, see the wiki page.

ockham commented 11 years ago

We might investigate using SQLkit to connect SQLAlchemy models to (py)GTK.

ockham commented 10 years ago

Implementing basic ORM classes like Recipe, Ingredient etc. isn't that hard -- I've already started a local branch for this. What's harder is migrating all those direct SQL functions that we're currently using to query (and modify) recipes, their ingredients, categories etc. to those ORM classes.

ockham commented 10 years ago

I've just pushed a work-in-progress (ie unfinished, dirty) branch, sql-alchemy-orm. This is probably the biggest refactoring project so far, and I could use some help with finishing it.

So as stated in the original post, the main goal is to replace our custom DB handling functions is gourmet/db.py with SQLAlchemy's ORM. That means we use objects made from classes like Recipe or Ingredient (all found in gourmet/models; BTW, the recipe card and index related stuff is now within the gourmet/views folder) which we obtain from and save to the database through the use of a Session object, which we pass along to the different UI components that need to access the DB. Porting to the ORM thus means (mostly):