Excellent! I think you're right about SQLAlchemy needing a declarative
way of defining objects.
Couple of suggestions:
'onetomany' and 'onetoone' would be more readable as 'one_to_many' and
'one_to_one'. Or because, they're classes, 'OneToMany' and 'OneToOne'
in accordance with PEP8 standards.
__table__ could default to a lowercase version of the classname if it's
not specified in the mapping class. That would be a useful convention
which could be overridden in those few cases where the table name
couldn't be derived like that.
BTW, there's some interesting examples of meta programming for this kind
of thing here:
http://blog.ianbicking.org/more-on-python-metaprogramming.html
Something you didn't mention - is it necessary to call
'process_relationships()' and 'create_tables()' once you have all your
classes defined?
This is a bit off topic, but I thought some of you might find it useful.
I have been playing around with SQLAlchemy lately, and I really like
it, but I feel like it needs a more declarative way to define object/
table maps. I have started on such a project, and I am calling it
ActiveMapper.
I have my current efforts so far available in a SVN repository, If
you are interested in helping out, please take a look at get back to me:
http://cleverdevil.org/svn/activemapper/
Currently, it allows you to do most of the basic mapping in the
following basic form:
class Address(ActiveMapper):
class mapping:
__table__ = 'address'
id = column(Integer, primary_key=True)
type = column(String)
address_1 = column(String)
city = column(String)
state = column(String)
postal_code = column(String)
person_id = column(Integer, foreign_key=ForeignKey
('person.id'))
class Preferences(ActiveMapper):
class mapping:
__table__ = 'preferences'
id = column(Integer, primary_key=True)
favorite_color = column(String)
personality_type = column(String)
class Person(ActiveMapper):
class mapping:
__table__ = 'person'
id = column(Integer, primary_key=True)
full_name = column(String)
first_name = column(String)
middle_name = column(String)
last_name = column(String)
birth_date = column(DateTime)
ssn = column(String)
gender = column(String)
home_phone = column(String)
cell_phone = column(String)
work_phone = column(String)
prefs_id = column(Integer,
foreign_key=ForeignKey('preferences.id'))
addresses = onetomany('Address',
colname='person_id', backref='person')
preferences = onetoone('Preferences', colname='pref_id',
backref='person')
Anyway, I hope that I find some people interested in helping move
this forward, and sorry for starting an off-topic thread.
--
Jonathan LaCour
http://cleverdevil.org