test_codegen.py 文件源码

python
阅读 16 收藏 0 点赞 0 评论 0

项目:sqlacodegen 作者: agronholm 项目源码 文件源码
def test_foreign_key_schema(self):
        Table(
            'simple_items', self.metadata,
            Column('id', INTEGER, primary_key=True),
            Column('other_item_id', INTEGER),
            ForeignKeyConstraint(['other_item_id'], ['otherschema.other_items.id'])
        )
        Table(
            'other_items', self.metadata,
            Column('id', INTEGER, primary_key=True),
            schema='otherschema'
        )

        assert self.generate_code() == """\
# coding: utf-8
from sqlalchemy import Column, ForeignKey, Integer
from sqlalchemy.orm import relationship
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class SimpleItem(Base):
    __tablename__ = 'simple_items'

    id = Column(Integer, primary_key=True)
    other_item_id = Column(ForeignKey('otherschema.other_items.id'))

    other_item = relationship('OtherItem')


class OtherItem(Base):
    __tablename__ = 'other_items'
    __table_args__ = {'schema': 'otherschema'}

    id = Column(Integer, primary_key=True)
"""
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号