Beispiel #1
0
def include_forward_references(table, head, consumed, include, exclude, indent,
                               opts):
    found = False
    for col in filter(
            lambda col:
        (not is_excluded(col.name, exclude) or is_included(col.name, include)),
            table.columns()):
        logger.debug('col.name %s not in exclude %s', col.name, exclude)
        fk = table.foreign_key(col.name)
        # logger.debug('consumed=%s', consumed)
        if not fk:
            if opts.include_columns:
                # Add column
                head.append(ColumnNode(col, indent))
        elif fk.a.table.name == table.name:
            # Collects the forward references
            logger.debug('adds forward reference: fk=%s, include=%s', fk,
                         include)
            head.append(ForeignKeyNode(fk, table, indent))
            if (is_included(fk.a.name, include)
                    or (opts.recursive and fk.b.table.name not in consumed)):
                # logger.debug('adds table=%s', fk.b.table)
                head.append(
                    TableNode(fk.b.table,
                              include=selection(fk.a.name, include),
                              exclude=selection(fk.a.name, exclude),
                              indent=indent + 1))
                found = True

    return found
Beispiel #2
0
def include_forward_references(
        table, head, consumed, include, exclude, indent, opts):
    found = False
    for col in filter(
            lambda col: (
                not is_excluded(col.name, exclude) or
                is_included(col.name, include)),
            table.columns()):
        logger.debug('col.name %s not in exclude %s', col.name, exclude)
        fk = table.foreign_key(col.name)
        # logger.debug('consumed=%s', consumed)
        if not fk:
            if opts.include_columns:
                # Add column
                head.append(ColumnNode(col, indent))
        elif fk.a.table.name == table.name:
            # Collects the forward references
            logger.debug(
                'adds forward reference: fk=%s, include=%s',
                fk, include)
            head.append(ForeignKeyNode(fk, table, indent))
            if (is_included(fk.a.name, include)
                    or (opts.recursive and fk.b.table.name not in consumed)):
                # logger.debug('adds table=%s', fk.b.table)
                head.append(TableNode(
                    fk.b.table,
                    include=selection(fk.a.name, include),
                    exclude=selection(fk.a.name, exclude),
                    indent=indent + 1))
                found = True

    return found
Beispiel #3
0
    def test_selection(self):
        """Tests the utils.selection function"""

        d = {
            'a': {
                'b': False,
                'c': None
            },
            'd': None,
            'e': {
                'f': {
                    'g': None
                }
            }
        }

        self.assertEqual(False, utils.selection('', False))
        self.assertEqual(False, utils.selection('', {}))

        self.assertEqual(d['a'], utils.selection('a', d))
        self.assertEqual(False, utils.selection('b', d))
        self.assertEqual(False, utils.selection('c', d))
        self.assertEqual(d['d'], utils.selection('d', d))
        self.assertEqual(d['e'], utils.selection('e', d))
        self.assertEqual(False, utils.selection('f', d))
        self.assertEqual(False, utils.selection('g', d))
Beispiel #4
0
def include_back_references(table, head, consumed, include, exclude, indent,
                            opts):
    found = False
    for _, fk in filter(
            lambda (key, fk):
        (fk.b.table.name == table.name and
         (not is_excluded(fk.a.table.name, exclude) or is_included(
             fk.a.table.name, include))),
            table.foreign_keys().iteritems()):
        logger.debug('adds back reference: fk=%s, include=%s', fk, include)
        head.append(ForeignKeyNode(fk, table, indent))
        if (is_included(fk.a.table.name, include)
                or (opts.recursive and fk.a.table.name not in consumed)):
            # Collects the back references
            # logger.debug('adds table=%s', fk.a.table)
            head.append(
                TableNode(fk.a.table,
                          include=selection(fk.a.table.name, include),
                          exclude=selection(fk.a.table.name, exclude),
                          indent=indent + 1))
            found = True
Beispiel #5
0
def include_back_references(
        table, head, consumed, include, exclude, indent, opts):
    found = False
    for _, fk in filter(
            lambda (key, fk): (
                fk.b.table.name == table.name
                and (
                    not is_excluded(fk.a.table.name, exclude)
                    or is_included(fk.a.table.name, include))),
            table.foreign_keys().iteritems()):
        logger.debug(
            'adds back reference: fk=%s, include=%s',
            fk, include)
        head.append(ForeignKeyNode(fk, table, indent))
        if (is_included(fk.a.table.name, include)
                or (opts.recursive and fk.a.table.name not in consumed)):
            # Collects the back references
            # logger.debug('adds table=%s', fk.a.table)
            head.append(TableNode(
                fk.a.table,
                include=selection(fk.a.table.name, include),
                exclude=selection(fk.a.table.name, exclude),
                indent=indent + 1))
            found = True