Ejemplo n.º 1
0
def include_forward_references(
        table, head, consumed, include, exclude, indent, opts):
    found = False
    for col in filter(
            lambda col: col.name not in exclude, table.columns()):
        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 (fk.a.name in prefixes(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=remove_prefix(fk.a.name, include),
                    exclude=remove_prefix(fk.a.name, exclude),
                    indent=indent + 1))
                found = True

    return found
Ejemplo n.º 2
0
    def test_remove_prefix(self):
        """Tests the utils.remove_prefix function"""

        self.assertEqual(
            ['b'],
            utils.remove_prefix('a', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            ['c', 'b'],
            utils.remove_prefix('b', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            ['c', 'd'],
            utils.remove_prefix('c', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            [],
            utils.remove_prefix('d', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
        self.assertEqual(
            [],
            utils.remove_prefix('', ['a.b', 'b.c', 'b', 'b.b', 'c.c', 'c.d']))
Ejemplo n.º 3
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 fk.a.table.name not in exclude),
            table.foreign_keys().iteritems()):
        logger.debug(
            'adds back reference: fk=%s, include=%s',
            fk, include)
        head.append(ForeignKeyNode(fk, table, indent))
        if (fk.a.table.name in prefixes(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=remove_prefix(fk.a.table.name, include),
                exclude=remove_prefix(fk.a.table.name, exclude),
                indent=indent + 1))
            found = True
Ejemplo n.º 4
0
def create_items(connection, items, include, exclude, substitutes):
    results_pre = []
    results_post = []
    includes = {}

    check_excludes(items, exclude)

    item = None
    for item in items:
        for i in include:
            process_item(item, i, includes)

    if item is not None:
        for fk in includes.keys():
            if fk.a.table.name == item.table.name:
                # forward references, must be in pre
                results_pre += create_items(
                    connection,
                    connection.rows(fk.b.table, QueryFilter(fk.b.name, "in", includes[fk]), limit=-1, simplify=False),
                    remove_prefix(fk.a.name, include),
                    remove_prefix(fk.a.name, exclude),
                    remove_prefix(fk.a.name, substitutes),
                )
            else:
                # backward reference, must be in post
                results_post += create_items(
                    connection,
                    connection.rows(fk.a.table, QueryFilter(fk.a.name, "in", includes[fk]), limit=-1, simplify=False),
                    remove_prefix(fk.a.table.name, include),
                    remove_prefix(fk.a.table.name, exclude),
                    remove_prefix(fk.a.table.name, substitutes),
                )

    return (
        results_pre
        + map(lambda i: RowItem(to_dto(i), prefixes(include), prefixes(exclude), prefixes(substitutes)), items)
        + results_post
    )
Ejemplo n.º 5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# Copyright © 2014 René Samselnig
#
# This file is part of Database Navigator.
#
# Database Navigator is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Database Navigator is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Database Navigator.  If not, see <http://www.gnu.org/licenses/>.
#

from dbnav.utils import prefixes, remove_prefix

d = {'name': 'b', 'fk.name': 'fk', 'fk.id': '123'}

print d
print prefixes(d)
print remove_prefix('a', d)