本文整理汇总了Python中sqlalchemy.Index方法的典型用法代码示例。如果您正苦于以下问题:Python sqlalchemy.Index方法的具体用法?Python sqlalchemy.Index怎么用?Python sqlalchemy.Index使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy
的用法示例。
在下文中一共展示了sqlalchemy.Index方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_add_index
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_render_add_index(self):
"""
autogenerate.render._add_index
"""
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("active", Boolean()),
Column("code", String(255)),
)
idx = Index("test_active_code_idx", t.c.active, t.c.code)
op_obj = ops.CreateIndexOp.from_index(idx)
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.create_index('test_active_code_idx', 'test', "
"['active', 'code'], unique=False)",
)
示例2: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def upgrade():
op.create_table(
'container_actions',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('action', sa.String(length=255), nullable=True),
sa.Column('container_uuid', sa.String(length=36), nullable=False),
sa.Column('request_id', sa.String(length=255), nullable=True),
sa.Column('user_id', sa.String(length=255), nullable=True),
sa.Column('project_id', sa.String(length=255), nullable=True),
sa.Column('start_time', sa.DateTime(), nullable=True),
sa.Column('finish_time', sa.DateTime(), nullable=True),
sa.Column('message', sa.String(length=255), nullable=True),
sa.Index('container_uuid_idx', 'container_uuid'),
sa.Index('request_id_idx', 'request_id'),
sa.ForeignKeyConstraint(['container_uuid'], ['container.uuid'], ),
sa.PrimaryKeyConstraint('id')
)
示例3: upgrade
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def upgrade():
op.create_table(
'allocation',
sa.Column('created_at', sa.DateTime(), nullable=True),
sa.Column('updated_at', sa.DateTime(), nullable=True),
sa.Column('id', sa.Integer(), nullable=False),
sa.Column('resource_provider_id', sa.Integer(), nullable=False),
sa.Column('consumer_id', sa.String(36), nullable=False),
sa.Column('resource_class_id', sa.Integer(), nullable=False),
sa.Column('used', sa.Integer(), nullable=False),
sa.Column('is_nested', sa.Integer(), nullable=False),
sa.Column('blob', zun.db.sqlalchemy.models.JSONEncodedList(),
nullable=True),
sa.Index('allocation_resource_provider_class_used_idx',
'resource_provider_id', 'resource_class_id', 'used'),
sa.Index('allocation_consumer_id_idx', 'consumer_id'),
sa.Index('allocation_resource_class_id_idx', 'resource_class_id'),
sa.PrimaryKeyConstraint('id'),
)
示例4: test_noindexes_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy 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')
)
"""
)
示例5: test_noconstraints_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy 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)
)
"""
)
示例6: test_indexes_table
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy 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)
)
"""
)
示例7: test_render_add_index_pg_where
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_render_add_index_pg_where(self):
autogen_context = self.autogen_context
m = MetaData()
t = Table("t", m, Column("x", String), Column("y", String))
idx = Index(
"foo_idx", t.c.x, t.c.y, postgresql_where=(t.c.y == "something")
)
op_obj = ops.CreateIndexOp.from_index(idx)
eq_ignore_whitespace(
autogenerate.render_op_text(autogen_context, op_obj),
"""op.create_index('foo_idx', 't', \
['x', 'y'], unique=False, """
"""postgresql_where=sa.text(!U"y = 'something'"))""",
)
示例8: test_render_add_index_batch
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_render_add_index_batch(self):
"""
autogenerate.render._add_index
"""
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("active", Boolean()),
Column("code", String(255)),
)
idx = Index("test_active_code_idx", t.c.active, t.c.code)
op_obj = ops.CreateIndexOp.from_index(idx)
with self.autogen_context._within_batch():
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"batch_op.create_index('test_active_code_idx', "
"['active', 'code'], unique=False)",
)
示例9: test_render_add_index_schema
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_render_add_index_schema(self):
"""
autogenerate.render._add_index using schema
"""
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("active", Boolean()),
Column("code", String(255)),
schema="CamelSchema",
)
idx = Index("test_active_code_idx", t.c.active, t.c.code)
op_obj = ops.CreateIndexOp.from_index(idx)
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.create_index('test_active_code_idx', 'test', "
"['active', 'code'], unique=False, schema='CamelSchema')",
)
示例10: test_render_add_index_func
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_render_add_index_func(self):
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("code", String(255)),
)
idx = Index("test_lower_code_idx", func.lower(t.c.code))
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'lower(code)')], unique=False)",
)
示例11: test_render_add_index_cast
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [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)",
)
示例12: test_drop_index
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_drop_index(self):
"""
autogenerate.render._drop_index
"""
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("active", Boolean()),
Column("code", String(255)),
)
idx = Index("test_active_code_idx", t.c.active, t.c.code)
op_obj = ops.DropIndexOp.from_index(idx)
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"op.drop_index('test_active_code_idx', table_name='test')",
)
示例13: test_drop_index_batch
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_drop_index_batch(self):
"""
autogenerate.render._drop_index
"""
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("active", Boolean()),
Column("code", String(255)),
)
idx = Index("test_active_code_idx", t.c.active, t.c.code)
op_obj = ops.DropIndexOp.from_index(idx)
with self.autogen_context._within_batch():
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"batch_op.drop_index('test_active_code_idx')",
)
示例14: test_drop_index_schema_batch
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_drop_index_schema_batch(self):
"""
autogenerate.render._drop_index using schema
"""
m = MetaData()
t = Table(
"test",
m,
Column("id", Integer, primary_key=True),
Column("active", Boolean()),
Column("code", String(255)),
schema="CamelSchema",
)
idx = Index("test_active_code_idx", t.c.active, t.c.code)
op_obj = ops.DropIndexOp.from_index(idx)
with self.autogen_context._within_batch():
eq_ignore_whitespace(
autogenerate.render_op_text(self.autogen_context, op_obj),
"batch_op.drop_index('test_active_code_idx')",
)
示例15: test_unique_flag_nothing_changed
# 需要导入模块: import sqlalchemy [as 别名]
# 或者: from sqlalchemy import Index [as 别名]
def test_unique_flag_nothing_changed(self):
m1 = MetaData()
m2 = MetaData()
Table(
"unq_idx",
m1,
Column("id", Integer, primary_key=True),
Column("x", String(20)),
Index("x", "x", unique=True),
)
Table(
"unq_idx",
m2,
Column("id", Integer, primary_key=True),
Column("x", String(20)),
Index("x", "x", unique=True),
)
diffs = self._fixture(m1, m2)
eq_(diffs, [])