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


Python schema.Index方法代码示例

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


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

示例1: test_noindexes_table

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

示例2: test_noconstraints_table

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

示例3: test_indexes_table

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

示例4: test_include_columns_indexes

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def test_include_columns_indexes(self):
        m = self.metadata

        t1 = Table("t1", m, Column("a", sa.Integer), Column("b", sa.Integer))
        sa.Index("foobar", t1.c.a, t1.c.b)
        sa.Index("bat", t1.c.a)
        m.create_all()
        m2 = MetaData(testing.db)
        t2 = Table("t1", m2, autoload=True)
        assert len(t2.indexes) == 2

        m2 = MetaData(testing.db)
        t2 = Table("t1", m2, autoload=True, include_columns=["a"])
        assert len(t2.indexes) == 1

        m2 = MetaData(testing.db)
        t2 = Table("t1", m2, autoload=True, include_columns=["a", "b"])
        assert len(t2.indexes) == 2 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:20,代码来源:test_reflection.py

示例5: test_index_reflection_cols_busted

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def test_index_reflection_cols_busted(self):
        t = Table(
            "x", self.metadata, Column("a", Integer), Column("b", Integer)
        )
        sa.Index("x_ix", t.c.a, t.c.b)
        self.metadata.create_all()

        def mock_get_columns(self, connection, table_name, **kw):
            return [{"name": "b", "type": Integer, "primary_key": False}]

        with testing.mock.patch.object(
            testing.db.dialect, "get_columns", mock_get_columns
        ):
            m = MetaData()
            with testing.expect_warnings(
                "index key 'a' was not located in columns"
            ):
                t = Table("x", m, autoload=True, autoload_with=testing.db)

        eq_(list(t.indexes)[0].columns, [t.c.b]) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:22,代码来源:test_reflection.py

示例6: test_non_attached_col_plus_string_expr

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def test_non_attached_col_plus_string_expr(self):
        # another one that declarative can lead towards
        metadata = MetaData()

        t1 = Table("a", metadata, Column("id", Integer))

        c2 = Column("x", Integer)

        # if we do it here, no problem
        # t1.append_column(c2)

        idx = Index("foo", c2, desc("foo"))

        t1.append_column(c2)

        self._assert_index_col_x(t1, idx, columns=True) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_metadata.py

示例7: test_auto_append_constraint

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def test_auto_append_constraint(self):
        m = MetaData()

        t = Table("tbl", m, Column("a", Integer), Column("b", Integer))

        t2 = Table("t2", m, Column("a", Integer), Column("b", Integer))

        for c in (
            UniqueConstraint(t.c.a),
            CheckConstraint(t.c.a > 5),
            ForeignKeyConstraint([t.c.a], [t2.c.a]),
            PrimaryKeyConstraint(t.c.a),
        ):
            assert c in t.constraints
            t.append_constraint(c)
            assert c in t.constraints

        c = Index("foo", t.c.a)
        assert c in t.indexes 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:21,代码来源:test_metadata.py

示例8: test_raise_clauseelement_not_a_column

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def test_raise_clauseelement_not_a_column(self):
        m = MetaData()
        t2 = Table("t2", m, Column("x", Integer))

        class SomeClass(object):
            def __clause_element__(self):
                return t2

        assert_raises_message(
            exc.ArgumentError,
            r"String column name or column expression for DDL constraint "
            r"expected, got .*SomeClass",
            Index,
            "foo",
            SomeClass(),
        ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:18,代码来源:test_metadata.py

示例9: test_combined

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def test_combined(self):
        with self._fixture():
            idx = Index(
                "a", "b", "c", participating_x=7, nonparticipating_y=True
            )

            eq_(
                idx.dialect_options,
                {
                    "participating": {"y": False, "x": 7, "z_one": None},
                    "nonparticipating": {"y": True, "*": None},
                },
            )
            eq_(
                idx.dialect_kwargs,
                {"participating_x": 7, "nonparticipating_y": True},
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:19,代码来源:test_metadata.py

示例10: test_multiple_participating

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def test_multiple_participating(self):
        with self._fixture():
            idx = Index(
                "a",
                "b",
                "c",
                participating_x=7,
                participating2_x=15,
                participating2_y="lazy",
            )
            eq_(
                idx.dialect_options,
                {
                    "participating": {"x": 7, "y": False, "z_one": None},
                    "participating2": {"x": 15, "y": "lazy", "pp": "default"},
                },
            )
            eq_(
                idx.dialect_kwargs,
                {
                    "participating_x": 7,
                    "participating2_x": 15,
                    "participating2_y": "lazy",
                },
            ) 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:27,代码来源:test_metadata.py

示例11: create_index

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def create_index(self, columns, name=None, **kw):
        """Create an index to speed up queries on a table.

        If no ``name`` is given a random name is created.
        ::

            table.create_index(['name', 'country'])
        """
        columns = [normalize_column_name(c) for c in ensure_tuple(columns)]
        with self.db.lock:
            if not self.exists:
                raise DatasetException("Table has not been created yet.")

            for column in columns:
                if not self.has_column(column):
                    return

            if not self.has_index(columns):
                self._threading_warn()
                name = name or index_name(self.name, columns)
                columns = [self.table.c[c] for c in columns]
                idx = Index(name, *columns, **kw)
                idx.create(self.db.executable) 
开发者ID:bkerler,项目名称:android_universal,代码行数:25,代码来源:table.py

示例12: _get_index_final_name

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def _get_index_final_name(dialect, idx):
    # trying to keep the truncation rules totally localized on the
    # SQLA side while also stepping around the quoting issue.   Ideally
    # the _prepared_index_name() method on the SQLA side would have
    # a quoting option or the truncation routine would be broken out.
    #
    # test for SQLA quoted_name construct, introduced in
    # 0.9 or thereabouts.
    # this doesn't work in 0.8 and the "quote" option on Index doesn't
    # seem to work in 0.8 either.
    if hasattr(idx.name, "quote"):
        # might be quoted_name, might be truncated_name, keep it the
        # same
        quoted_name_cls = type(idx.name)
        new_name = quoted_name_cls(str(idx.name), quote=False)
        idx = schema.Index(name=new_name)
    return dialect.ddl_compiler(dialect, None)._prepared_index_name(idx) 
开发者ID:bkerler,项目名称:android_universal,代码行数:19,代码来源:sqla_compat.py

示例13: index

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def index(self, name, tablename, columns, schema=None, **kw):
        t = sa_schema.Table(
            tablename or 'no_table', self.metadata(),
            schema=schema
        )
        idx = sa_schema.Index(
            name,
            *[util.sqla_compat._textual_index_column(t, n) for n in columns],
            **kw)
        return idx 
开发者ID:jpush,项目名称:jbox,代码行数:12,代码来源:schemaobj.py

示例14: _make_index

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def _make_index(params, conn_table):
    # TODO: add .info such as 'duplicates_constraint'
    return sa_schema.Index(
        params['name'],
        *[conn_table.c[cname] for cname in params['column_names']],
        unique=params['unique']
    ) 
开发者ID:jpush,项目名称:jbox,代码行数:9,代码来源:compare.py

示例15: upgrade

# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import Index [as 别名]
def upgrade(migrate_engine):
    LOG.info("Adding boolean column delayed_notify to table 'zones'")
    meta.bind = migrate_engine
    zones_table = Table('zones', meta, autoload=True)
    col = Column('delayed_notify', Boolean(), default=False)
    col.create(zones_table)
    index = Index('delayed_notify', zones_table.c.delayed_notify)
    index.create(migrate_engine) 
开发者ID:openstack,项目名称:designate,代码行数:10,代码来源:084_add_delayed_notify_column.py


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