rattail.mappers - Mappers and helpers
This module is where all core class mappings are defined. Those aren’t of too much use to callers, but the module also provides some helper functions, etc., which will be useful to some extensions.
The following classes derive from sqlalchemy.orm.MapperExtension, and may be added to any mapper by passing an instance of the extension to mapper(), e.g.:
from sqlalchemy import *
from sqlalchemy.orm import mapper
from rattail import get_uuid
from rattail.mappers import AutoIncrementer
metadata = MetaData()
my_things = Table(
'my_things', metadata,
Column('uuid', String(32), primary_key=True, default=get_uuid),
Column('id', Integer),
)
class MyThing(object):
pass
mapper(
MyThing, my_things,
extension=AutoIncrementer(),
)
Adds auto-increment behavior to a mapper’s id property.
Note
Currently the affected property must be named id.