Example #1
0
 def format_column_node(self, node):
     return textwrap.dedent("""
             {indent_}# {column}
             {indent_}{column.name}: # !!{type_} {nullable}""").format(
         indent_=(node.indent+1)*4*' ',
         type_=to_yaml_type(node.column.type),
         nullable={True: 'optional', False: 'mandatory'}.get(
             node.column.nullable),
         **node.__dict__)
Example #2
0
    def test_to_yaml_type(self):
        """Tests the utils.to_yaml_type function"""

        from sqlalchemy.sql.sqltypes import Boolean, Integer, Float, String, \
            Date, Time, DateTime, _Binary

        self.assertEqual('str', utils.to_yaml_type(None))

        self.assertEqual('bool', utils.to_yaml_type(Boolean()))
        self.assertEqual('int', utils.to_yaml_type(Integer()))
        self.assertEqual('float', utils.to_yaml_type(Float()))
        self.assertEqual('str', utils.to_yaml_type(String()))
        self.assertEqual('str', utils.to_yaml_type(Date()))
        self.assertEqual('str', utils.to_yaml_type(Time()))
        self.assertEqual('str', utils.to_yaml_type(DateTime()))
        self.assertEqual('binary', utils.to_yaml_type(_Binary()))
Example #3
0
    def format_foreign_key_node(self, node):
        if node.fk.a.tablename == node.parent.name:
            # A forward reference
            return textwrap.dedent(u"""
                    {indent_}# → {fk.a.name} → {fk.b}
                    {indent_}{fk.a.name}: # !!{type_} {nullable}""").format(
                indent_=(node.indent+1)*4*' ',
                type_=to_yaml_type(node.fk.a.type),
                nullable={True: 'optional', False: 'mandatory'}.get(
                    node.fk.a.nullable),
                **node.__dict__)

        # A back reference
        return textwrap.dedent(u"""
                {indent_}# ↑ {fk.a} → {fk.b}
                {indent_}{fk.a.tablename}:""").format(
            indent_=(node.indent+1)*4*' ',
            **node.__dict__)