rattail.mappers Module

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.

SQLAlchemy Mapper 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(),
    )
class rattail.mappers.AutoIncrementer

Adds auto-increment behavior to a mapper’s id property.

Note

Currently the affected property must be named id.

Table Of Contents

Previous topic

rattail.filters Module

Next topic

rattail.model Module

This Page