Ejemplo n.º 1
0
    def desc(self, qrn=None, verbose=False):
        """Prints the description of the relations of the model

        If a qualified relation name (<schema name>.<table name>) is
        passed, prints only the description of the corresponding relation.
        """
        if not qrn:
            entry = self.__metadata[self.__dbname]['byname']
            for key in entry:
                fqrn = ".".join(['"{}"'.format(elt) for elt in key[1:]])
                if verbose:
                    print(relation_factory(
                        'Table', (), {'fqrn': fqrn, 'model': self})())
                else:
                    print('{} {}'.format(entry[key]['tablekind'], fqrn))
        else:
            fqrn = '"{}".{}'.format(self.__dbname, _normalize_qrn(qrn=qrn))
            print(relation_factory(
                'Table', (), {'fqrn': fqrn, 'model': self})())
Ejemplo n.º 2
0
    def get_relation_class(self, qtn):
        """Retuns the class corresponding to the fqrn relation in the database.

        @qtn is the <schema>.<table> name of the relation
        @kwargs is a dictionary {field_name:value}
        """
        schema, table = qtn.rsplit('.', 1)
        fqrn = '.'.join([self.__dbname, '"{}"'.format(schema), table])
        fqrn, _ = _normalize_fqrn(fqrn)
        return relation_factory('Table', (), {'fqrn': fqrn, 'model': self})