当前位置: 首页>>代码示例>>Python>>正文


Python schema.Table方法代码示例

本文整理汇总了Python中sqlalchemy.schema.Table方法的典型用法代码示例。如果您正苦于以下问题:Python schema.Table方法的具体用法?Python schema.Table怎么用?Python schema.Table使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在sqlalchemy.schema的用法示例。


在下文中一共展示了schema.Table方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upgrade

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def upgrade(migrate_engine):
    meta.bind = migrate_engine

    pool_ns_records_table = Table('pool_ns_records', meta, autoload=True)

    # Only apply it if it's not there (It's been backported to L)
    insp = Inspector.from_engine(migrate_engine)
    unique_constraints = insp.get_unique_constraints('pool_ns_records')
    unique_constraint_names = [i['name'] for i in unique_constraints]

    if CONSTRAINT_NAME not in unique_constraint_names:
        # We define the constraint here if not it shows in the list above.
        constraint = UniqueConstraint('pool_id', 'hostname',
                                      name=CONSTRAINT_NAME,
                                      table=pool_ns_records_table)
        try:
            constraint.create()
        except exc.IntegrityError as e:
            LOG.error(explanation, e)
            # Use sys.exit so we don't blow up with a huge trace
            sys.exit(1) 
开发者ID:openstack,项目名称:designate,代码行数:23,代码来源:082_unique_ns_record.py

示例2: upgrade

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def upgrade(migrate_engine):
    meta.bind = migrate_engine

    status_enum = Enum(name='service_statuses_enum', metadata=meta,
                       *SERVICE_STATES)
    status_enum.create(checkfirst=True)

    service_status_table = Table('service_statuses', meta,
        Column('id', UUID(), default=utils.generate_uuid, primary_key=True),
        Column('created_at', DateTime),
        Column('updated_at', DateTime),

        Column('service_name', String(40), nullable=False),
        Column('hostname', String(255), nullable=False),
        Column('heartbeated_at', DateTime, nullable=True),
        Column('status', status_enum, nullable=False),
        Column('stats', Text, nullable=False),
        Column('capabilities', Text, nullable=False),
    )
    service_status_table.create(checkfirst=True) 
开发者ID:openstack,项目名称:designate,代码行数:22,代码来源:097_add_services.py

示例3: test_enum_detection

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_enum_detection(metadata):
    Table("simple_items", metadata, Column("enum", VARCHAR(255)), CheckConstraint(r"simple_items.enum IN ('A', '\'B', 'C')"))

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, Enum, MetaData, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('enum', Enum('A', "\\\\'B", 'C'))
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:20,代码来源:test_codegen.py

示例4: test_column_adaptation

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_column_adaptation(metadata):
    Table("simple_items", metadata, Column("id", postgresql.BIGINT), Column("length", postgresql.DOUBLE_PRECISION))

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import BigInteger, Column, Float, MetaData, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('id', BigInteger),
    Column('length', Float)
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:21,代码来源:test_codegen.py

示例5: test_noindexes_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_noindexes_table(metadata):
    simple_items = Table("simple_items", metadata, Column("number", INTEGER), CheckConstraint("number > 2"))
    simple_items.indexes.add(Index("idx_number", simple_items.c.number))

    assert (
        generate_code(metadata, noindexes=True)
        == """\
# coding: utf-8
from sqlalchemy import CheckConstraint, Column, Integer, MetaData, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('number', Integer),
    CheckConstraint('number > 2')
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:22,代码来源:test_codegen.py

示例6: test_noconstraints_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_noconstraints_table(metadata):
    simple_items = Table("simple_items", metadata, Column("number", INTEGER), CheckConstraint("number > 2"))
    simple_items.indexes.add(Index("idx_number", simple_items.c.number))

    assert (
        generate_code(metadata, noconstraints=True)
        == """\
# coding: utf-8
from sqlalchemy import Column, Integer, MetaData, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('number', Integer, index=True)
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:21,代码来源:test_codegen.py

示例7: test_indexes_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_indexes_table(metadata):
    simple_items = Table("simple_items", metadata, Column("id", INTEGER), Column("number", INTEGER), Column("text", VARCHAR))
    simple_items.indexes.add(Index("idx_number", simple_items.c.number))
    simple_items.indexes.add(Index("idx_text_number", simple_items.c.text, simple_items.c.number, unique=True))
    simple_items.indexes.add(Index("idx_text", simple_items.c.text, unique=True))

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, Index, Integer, MetaData, String, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('id', Integer),
    Column('number', Integer, index=True),
    Column('text', String, unique=True),
    Index('idx_text_number', 'text', 'number', unique=True)
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:26,代码来源:test_codegen.py

示例8: test_no_classes

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_no_classes(metadata):
    Table("simple_items", metadata, Column("id", INTEGER, primary_key=True))

    assert (
        generate_code(metadata, noclasses=True)
        == """\
# coding: utf-8
from sqlalchemy import Column, Integer, MetaData, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('id', Integer, primary_key=True)
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:20,代码来源:test_codegen.py

示例9: test_table_kwargs

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_table_kwargs(metadata):
    Table("simple_items", metadata, Column("id", INTEGER, primary_key=True), schema="testschema")

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

Base = declarative_base()
metadata = Base.metadata


class SimpleItem(Base):
    __tablename__ = 'simple_items'
    __table_args__ = {'schema': 'testschema'}

    id = Column(Integer, primary_key=True)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:23,代码来源:test_codegen.py

示例10: test_schema_table

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_schema_table(metadata):
    Table("simple_items", metadata, Column("name", VARCHAR), schema="testschema")

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, MetaData, String, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('name', String),
    schema='testschema'
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:21,代码来源:test_codegen.py

示例11: test_schema_boolean

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_schema_boolean(metadata):
    Table(
        "simple_items", metadata, Column("bool1", INTEGER), CheckConstraint("testschema.simple_items.bool1 IN (0, 1)"), schema="testschema"
    )

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Boolean, Column, MetaData, Table

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('bool1', Boolean),
    schema='testschema'
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:23,代码来源:test_codegen.py

示例12: test_pk_default

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_pk_default(metadata):
    Table("simple_items", metadata, Column("id", INTEGER, primary_key=True, server_default=text("uuid_generate_v4()")))

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, Integer, text
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, server_default=text("uuid_generate_v4()"))
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:22,代码来源:test_codegen.py

示例13: test_server_default_double_quotes

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_server_default_double_quotes(metadata):
    Table("simple", metadata, Column("id", INTEGER, primary_key=True, server_default=text('nextval("foo")')))

    assert (
        generate_code(metadata)
        == """\
# coding: utf-8
from sqlalchemy import Column, Integer, text
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()
metadata = Base.metadata


class Simple(Base):
    __tablename__ = 'simple'

    id = Column(Integer, primary_key=True, server_default=text("nextval(\\"foo\\")"))
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:22,代码来源:test_codegen.py

示例14: test_underscore

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_underscore(metadata):
    Table("customer_api_preference", metadata, Column("id", INTEGER, primary_key=True))

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

Base = declarative_base()
metadata = Base.metadata


class CustomerApiPreference(Base):
    __tablename__ = 'customer_api_preference'

    id = Column(Integer, primary_key=True)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:22,代码来源:test_codegen.py

示例15: test_pascal_underscore

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Table [as 别名]
def test_pascal_underscore(metadata):
    Table("customer_API_Preference", metadata, Column("id", INTEGER, primary_key=True))

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

Base = declarative_base()
metadata = Base.metadata


class CustomerAPIPreference(Base):
    __tablename__ = 'customer_API_Preference'

    id = Column(Integer, primary_key=True)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:22,代码来源:test_codegen.py


注:本文中的sqlalchemy.schema.Table方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。