Next / Previous / Contents / NM Tech homepage

8.5. MyCBC.__mapTable: Locate and bind a table

mycbc.py
# - - -   M y C B C . _ _ m a p T a b l e

    def __mapTable(self, tableName, className):
        '''Map one table class

          [ (tableName is a table name found in self.meta) and
            (className is a Class) ->
              orm  :=  orm with className mapped to that table ]
        '''
        #-- 1 --
        # [ if self.meta.tables has a key (tableName) ->
        #     table  :=  the related value
        #     self.(tableName)  :=  the related value
        #   else ->
        #     raise IOError ]
        try:
            table = self.meta.tables[tableName]
            setattr(self, tableName, table)
        except KeyError, detail:
            raise IOError("MySQL database does not contain a table "
                "named %s: %s." % (tableName, detail) )

        #-- 2 --
        # [ orm  :=  orm with class (classname) mapped to table ]
        orm.mapper(className, table)