Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sqlalchemy file organization

Does anyone has any insight on organizing sqlalchemy based projects? I have many tables and classes with foreign keys, and relations. What is everyone doing in terms of separating classes, tables, and mappers ? I am relatively new to the framework, so any help would be appreciated.

Example:

classA.py # table definition and class A definition
classB.py # table definition and class B definition

### model.py
import classA,classB
map(classA.classA,clasSA.table)
map(classB.classB,clasSB.table)

Including mappers inside classA, and classB works, but poses cross import issues when building relations.. Maybe I am missing something :)

like image 451
Sebastian Vantreri Avatar asked Oct 15 '22 08:10

Sebastian Vantreri


1 Answers

Take a look at Pylons project including SA setup.

meta.py includes engine and metadata objects

models package includes declerative classes (no mapper needed). Inside that package, structure your classes by relavance into modules.

Maybe a good example would be reddit source code:)

like image 182
iElectric Avatar answered Oct 19 '22 02:10

iElectric