On 12/1/06, iain duncan <[EMAIL PROTECTED]> wrote:
>
> Does sqlalchemy not do enums? Are enums bad?
>
They aren't *bad* per se, but they're not (afaik) ANSI SQL and are
(again, afaik) a MySQL feature. I would just emulate an enum but
modifying the object in SA (or SO for that matter) and raise a
ValueError if you try to set the attribute to anything other than what
you have in your 'enum' list.
example_table = Table("examples", metadata,
Column('id', Integer, primary_key=True),
Column('data', String(50))
)
class Example(object):
def _set_data(self, data):
enum_vals['valid', 'data', 'for', 'enum']
if data not in enum_vals:
raise ValueError("'%s' is not a valid data value" % data)
self._data = data
def _get_data(self):
return self._data
data = property(_get_data, _set_data)
assign_mapper(session.context, Example, example_table,
properties={
'_data': example_table.c.data
}
)
Lee
--
Lee McFadden
blog: http://www.splee.co.uk
work: http://fireflisystems.com
skype: fireflisystems
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---