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


Python mysql.VARCHAR属性代码示例

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


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

示例1: upgrade

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def upgrade():
    with op.batch_alter_table('capsule', schema=None) as batch_op:
        batch_op.create_unique_constraint('uniq_capsule0uuid', ['uuid'])
        batch_op.drop_column('message')

    with op.batch_alter_table('container_actions', schema=None) as batch_op:
        batch_op.create_foreign_key(
            None, 'container', ['container_uuid'], ['uuid'])

    with op.batch_alter_table('pci_device', schema=None) as batch_op:
        batch_op.create_foreign_key(
            None, 'compute_node', ['compute_node_uuid'], ['uuid'])

    with op.batch_alter_table('volume_mapping', schema=None) as batch_op:
        batch_op.alter_column('container_uuid',
                              existing_type=mysql.VARCHAR(length=36),
                              nullable=True)
        batch_op.create_foreign_key(
            None, 'container', ['container_uuid'], ['uuid']) 
开发者ID:openstack,项目名称:zun,代码行数:21,代码来源:71f8b4cf1dbf_upgrade.py

示例2: downgrade

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def downgrade():
    op.add_column(
        'accounts',
        sa.Column('re_fee', mysql.VARCHAR(length=254), nullable=True)
    )
    op.drop_column('accounts', 're_other_fee')
    op.drop_column('accounts', 're_late_fee')
    bind = op.get_bind()
    session = Session(bind=bind)
    for acct in session.query(Account).all():
        acct.re_interest_charge = '^(interest charge|purchase finance charge)'
        acct.re_interest_paid = '^interest paid'
        acct.re_payment = '^(online payment|' \
                          'internet payment|online pymt|payment)'
        acct.re_fee = '^(late fee|past due fee)'
    session.commit() 
开发者ID:jantman,项目名称:biweeklybudget,代码行数:18,代码来源:073142f641b3_account_remove_re_field_defaults.py

示例3: test_enum_detection

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [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_mysql_column_types

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def test_mysql_column_types(metadata):
    Table("simple_items", metadata, Column("id", mysql.INTEGER), Column("name", mysql.VARCHAR(255)))

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

metadata = MetaData()


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

示例5: test_indexes_table

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [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

示例6: test_foreign_key_options

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def test_foreign_key_options(metadata):
    Table(
        "simple_items",
        metadata,
        Column(
            "name", VARCHAR, ForeignKey("simple_items.name", ondelete="CASCADE", onupdate="CASCADE", deferrable=True, initially="DEFERRED")
        ),
    )

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

metadata = MetaData()


t_simple_items = Table(
    'simple_items', metadata,
    Column('name', String, ForeignKey('simple_items.name', ondelete='CASCADE', \
onupdate='CASCADE', deferrable=True, initially='DEFERRED'))
)
"""
    ) 
开发者ID:thomaxxl,项目名称:safrs,代码行数:27,代码来源:test_codegen.py

示例7: test_metadata_column

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

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

Base = declarative_base()
metadata = Base.metadata


class Simple(Base):
    __tablename__ = 'simple'

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

示例8: test_render_add_index_cast

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def test_render_add_index_cast(self):
        m = MetaData()
        t = Table(
            "test",
            m,
            Column("id", Integer, primary_key=True),
            Column("code", String(255)),
        )
        idx = Index("test_lower_code_idx", cast(t.c.code, String))
        op_obj = ops.CreateIndexOp.from_index(idx)

        eq_ignore_whitespace(
            autogenerate.render_op_text(self.autogen_context, op_obj),
            "op.create_index('test_lower_code_idx', 'test', "
            "[sa.text(!U'CAST(code AS VARCHAR)')], unique=False)",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:18,代码来源:test_autogen_render.py

示例9: test_render_variant

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def test_render_variant(self):
        from sqlalchemy import VARCHAR, CHAR

        self.autogen_context.opts["user_module_prefix"] = None

        type_ = (
            String(5)
            .with_variant(VARCHAR(10), "mysql")
            .with_variant(CHAR(15), "oracle")
        )

        # the new Black formatting will help a lot with this
        eq_ignore_whitespace(
            autogenerate.render._repr_type(type_, self.autogen_context),
            "sa.String(length=5)."
            "with_variant(sa.VARCHAR(length=10), 'mysql')."
            "with_variant(sa.CHAR(length=15), 'oracle')",
        ) 
开发者ID:sqlalchemy,项目名称:alembic,代码行数:20,代码来源:test_autogen_render.py

示例10: downgrade

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def downgrade(op, tables, tester):
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_constraint(op.f("fk_messages_media_type_id_mediatype"), "messages", type_="foreignkey")
    op.drop_index("messages_uuid", table_name="messages")
    op.drop_index("messages_severity", table_name="messages")
    op.drop_index("messages_media_type_id", table_name="messages")
    op.alter_column("messages", "uuid", existing_type=mysql.VARCHAR(length=36), nullable=True)
    op.drop_column("messages", "severity")
    op.drop_column("messages", "media_type_id")
    # ### end Alembic commands ###

    op.execute(
        tables.mediatype.delete().where(
            tables.mediatype.c.name == op.inline_literal("text/markdown")
        )
    ) 
开发者ID:quay,项目名称:quay,代码行数:18,代码来源:3e8cc74a1e7b_add_severity_and_media_type_to_global_.py

示例11: test_column_datatype_to_string

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def test_column_datatype_to_string(self):
        test_cases = (
            (DATE(), "DATE"),
            (VARCHAR(length=255), "VARCHAR(255)"),
            (
                VARCHAR(length=255, charset="latin1", collation="utf8mb4_general_ci"),
                "VARCHAR(255)",
            ),
            (NVARCHAR(length=128), "NATIONAL VARCHAR(128)"),
            (TEXT(), "TEXT"),
        )

        for original, expected in test_cases:
            actual = MySQLEngineSpec.column_datatype_to_string(
                original, mysql.dialect()
            )
            self.assertEqual(actual, expected) 
开发者ID:apache,项目名称:incubator-superset,代码行数:19,代码来源:mysql_tests.py

示例12: upgrade

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def upgrade():
    op.create_table(
        'gmailauthcredentials',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=False),
        sa.Column('deleted_at', sa.DateTime(), nullable=True),
        sa.Column('gmailaccount_id', sa.Integer(), nullable=False),
        sa.Column('refresh_token_id', sa.Integer(), nullable=False),
        sa.Column('scopes', mysql.VARCHAR(length=512), nullable=False),
        sa.Column('g_id_token', mysql.VARCHAR(length=1024), nullable=False),
        sa.Column('client_id', mysql.VARCHAR(length=256), nullable=False),
        sa.Column('client_secret', mysql.VARCHAR(length=256), nullable=False),
        sa.Column('is_valid', sa.Boolean(),
                  nullable=False, server_default=sa.sql.expression.true()),
        sa.ForeignKeyConstraint(
            ['gmailaccount_id'], [u'gmailaccount.id'], ondelete='CASCADE'
        ),
        sa.ForeignKeyConstraint(
            ['refresh_token_id'], [u'secret.id'], ondelete='CASCADE'
        ),
        sa.PrimaryKeyConstraint('id'),
        sa.UniqueConstraint('refresh_token_id'),
    ) 
开发者ID:nylas,项目名称:sync-engine,代码行数:26,代码来源:184_create_gmail_auth_credentials_table.py

示例13: upgrade

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def upgrade():
    op.create_table(
        'phonenumber',
        sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
        sa.Column('created_at', sa.DateTime(), nullable=False),
        sa.Column('updated_at', sa.DateTime(), nullable=False),
        sa.Column('deleted_at', sa.DateTime(), nullable=True),
        sa.Column('contact_id', sa.Integer(), nullable=False),
        sa.Column('type', mysql.VARCHAR(length=64), nullable=True),
        sa.Column('number', mysql.VARCHAR(length=64), nullable=False),
        sa.ForeignKeyConstraint(
            ['contact_id'], [u'contact.id'], ondelete='CASCADE'
        ),
        sa.PrimaryKeyConstraint('id'),
    )
    op.create_index('ix_phonenumber_created_at',
                    'phonenumber', ['created_at'], unique=False)
    op.create_index('ix_phonenumber_updated_at',
                    'phonenumber', ['updated_at'], unique=False)
    op.create_index('ix_phonenumber_contact_id',
                    'phonenumber', ['contact_id'], unique=False)
    op.create_index('ix_phonenumber_deleted_at',
                    'phonenumber', ['deleted_at'], unique=False) 
开发者ID:nylas,项目名称:sync-engine,代码行数:25,代码来源:206_add_phone_numbers_table.py

示例14: with_variant

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def with_variant(self, type_, dialect_name):
        """Produce a new type object that will utilize the given
        type when applied to the dialect of the given name.

        e.g.::

            from sqlalchemy.types import String
            from sqlalchemy.dialects import mysql

            s = String()

            s = s.with_variant(mysql.VARCHAR(collation='foo'), 'mysql')

        The construction of :meth:`.TypeEngine.with_variant` is always
        from the "fallback" type to that which is dialect specific.
        The returned type is an instance of :class:`.Variant`, which
        itself provides a :meth:`.Variant.with_variant`
        that can be called repeatedly.

        :param type_: a :class:`.TypeEngine` that will be selected
         as a variant from the originating type, when a dialect
         of the given name is in use.
        :param dialect_name: base name of the dialect which uses
         this type. (i.e. ``'postgresql'``, ``'mysql'``, etc.)

        .. versionadded:: 0.7.2

        """
        return Variant(self, {dialect_name: to_instance(type_)}) 
开发者ID:jpush,项目名称:jbox,代码行数:31,代码来源:type_api.py

示例15: downgrade

# 需要导入模块: from sqlalchemy.dialects import mysql [as 别名]
# 或者: from sqlalchemy.dialects.mysql import VARCHAR [as 别名]
def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.add_column('roles', sa.Column('name', mysql.VARCHAR(length=64), nullable=True))

    # op.drop_constraint(None, 'roles', type_='unique')
    # upgrade的时候更新了name,在上面的upgrade方法中添加了唯一约束
    # 降级的时候需要手动在donwgrade函数中去掉这个约束,将None变为'nick_name'
    op.drop_constraint('nick_name', 'roles', type_='unique')

    op.create_index('name', 'roles', ['name'], unique=True)
    op.drop_column('roles', 'nick_name')
    # ### end Alembic commands ### 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:14,代码来源:d1f1a273d45a_重新命名name.py


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