當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。