本文整理汇总了Python中sqlalchemy.schema.CreateIndex方法的典型用法代码示例。如果您正苦于以下问题:Python schema.CreateIndex方法的具体用法?Python schema.CreateIndex怎么用?Python schema.CreateIndex使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sqlalchemy.schema
的用法示例。
在下文中一共展示了schema.CreateIndex方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_table
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def create_table(self, table):
table.dispatch.before_create(
table, self.connection, checkfirst=False, _ddl_runner=self
)
self._exec(schema.CreateTable(table))
table.dispatch.after_create(
table, self.connection, checkfirst=False, _ddl_runner=self
)
for index in table.indexes:
self._exec(schema.CreateIndex(index))
with_comment = (
sqla_compat._dialect_supports_comments(self.dialect)
and not self.dialect.inline_comments
)
comment = sqla_compat._comment_attribute(table)
if comment and with_comment:
self.create_table_comment(table)
for column in table.columns:
comment = sqla_compat._comment_attribute(column)
if comment and with_comment:
self.create_column_comment(column)
示例2: print_create_table
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def print_create_table(tables):
app.config.from_object('config.default')
database.init_app(app)
engine = database.session.get_bind()
for class_name in tables:
cls = get_class(class_name)
for c in cls.__table__.columns:
if not isinstance(c.type, Enum):
continue
t = c.type
sql = str(CreateEnumType(t).compile(engine))
click.echo(sql.strip() + ';')
for index in cls.__table__.indexes:
sql = str(CreateIndex(index).compile(engine))
click.echo(sql.strip() + ';')
sql = str(CreateTable(cls.__table__).compile(engine))
click.echo(sql.strip() + ';')
示例3: test_create_index_bitmap_compress
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_index_bitmap_compress(self):
m = MetaData()
tbl = Table("testtbl", m, Column("data", Integer))
idx1 = Index("idx1", tbl.c.data, oracle_compress=True)
idx2 = Index("idx2", tbl.c.data, oracle_compress=1)
idx3 = Index("idx3", tbl.c.data, oracle_bitmap=True)
self.assert_compile(
schema.CreateIndex(idx1),
"CREATE INDEX idx1 ON testtbl (data) COMPRESS",
)
self.assert_compile(
schema.CreateIndex(idx2),
"CREATE INDEX idx2 ON testtbl (data) COMPRESS 1",
)
self.assert_compile(
schema.CreateIndex(idx3),
"CREATE BITMAP INDEX idx3 ON testtbl (data)",
)
示例4: test_create_index_with_using
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_index_with_using(self):
m = MetaData()
tbl = Table("testtbl", m, Column("data", String))
idx1 = Index("test_idx1", tbl.c.data)
idx2 = Index("test_idx2", tbl.c.data, postgresql_using="btree")
idx3 = Index("test_idx3", tbl.c.data, postgresql_using="hash")
self.assert_compile(
schema.CreateIndex(idx1),
"CREATE INDEX test_idx1 ON testtbl " "(data)",
dialect=postgresql.dialect(),
)
self.assert_compile(
schema.CreateIndex(idx2),
"CREATE INDEX test_idx2 ON testtbl " "USING btree (data)",
dialect=postgresql.dialect(),
)
self.assert_compile(
schema.CreateIndex(idx3),
"CREATE INDEX test_idx3 ON testtbl " "USING hash (data)",
dialect=postgresql.dialect(),
)
示例5: test_create_index_with_multiple_options
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_index_with_multiple_options(self):
m = MetaData()
tbl = Table("testtbl", m, Column("data", String))
idx1 = Index(
"test_idx1",
tbl.c.data,
postgresql_using="btree",
postgresql_tablespace="atablespace",
postgresql_with={"fillfactor": 60},
postgresql_where=and_(tbl.c.data > 5, tbl.c.data < 10),
)
self.assert_compile(
schema.CreateIndex(idx1),
"CREATE INDEX test_idx1 ON testtbl "
"USING btree (data) "
"WITH (fillfactor = 60) "
"TABLESPACE atablespace "
"WHERE data > 5 AND data < 10",
dialect=postgresql.dialect(),
)
示例6: test_create_index_concurrently
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_index_concurrently(self):
m = MetaData()
tbl = Table("testtbl", m, Column("data", Integer))
idx1 = Index("test_idx1", tbl.c.data, postgresql_concurrently=True)
self.assert_compile(
schema.CreateIndex(idx1),
"CREATE INDEX CONCURRENTLY test_idx1 ON testtbl (data)",
)
dialect_8_1 = postgresql.dialect()
dialect_8_1._supports_create_index_concurrently = False
self.assert_compile(
schema.CreateIndex(idx1),
"CREATE INDEX test_idx1 ON testtbl (data)",
dialect=dialect_8_1,
)
示例7: test_create_index_with_parser
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_index_with_parser(self):
m = MetaData()
tbl = Table("testtbl", m, Column("data", String(255)))
idx = Index(
"test_idx1",
tbl.c.data,
mysql_length=10,
mysql_prefix="FULLTEXT",
mysql_with_parser="ngram",
)
self.assert_compile(
schema.CreateIndex(idx),
"CREATE FULLTEXT INDEX test_idx1 "
"ON testtbl (data(10)) WITH PARSER ngram",
)
示例8: test_create_composite_index_with_length_quoted
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_composite_index_with_length_quoted(self):
m = MetaData()
tbl = Table(
"testtbl",
m,
Column("some Quoted a", String(255), key="a"),
Column("some Quoted b", String(255), key="b"),
)
idx1 = Index(
"test_idx1",
tbl.c.a,
tbl.c.b,
mysql_length={"some Quoted a": 10, "some Quoted b": 20},
)
self.assert_compile(
schema.CreateIndex(idx1),
"CREATE INDEX test_idx1 ON testtbl "
"(`some Quoted a`(10), `some Quoted b`(20))",
)
示例9: test_create_composite_index_with_length
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_composite_index_with_length(self):
m = MetaData()
tbl = Table(
"testtbl", m, Column("a", String(255)), Column("b", String(255))
)
idx1 = Index(
"test_idx1", tbl.c.a, tbl.c.b, mysql_length={"a": 10, "b": 20}
)
idx2 = Index("test_idx2", tbl.c.a, tbl.c.b, mysql_length={"a": 15})
idx3 = Index("test_idx3", tbl.c.a, tbl.c.b, mysql_length=30)
self.assert_compile(
schema.CreateIndex(idx1),
"CREATE INDEX test_idx1 ON testtbl (a(10), b(20))",
)
self.assert_compile(
schema.CreateIndex(idx2),
"CREATE INDEX test_idx2 ON testtbl (a(15), b)",
)
self.assert_compile(
schema.CreateIndex(idx3),
"CREATE INDEX test_idx3 ON testtbl (a(30), b(30))",
)
示例10: test_colliding_col_label_from_index_flag_no_conv
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_colliding_col_label_from_index_flag_no_conv(self):
t1 = self._colliding_name_fixture({"ck": "foo"}, {"index": True})
idx = list(t1.indexes)[0]
# this behavior needs to fail, as of #4911 since we are testing it,
# ensure it raises a CompileError. In #4289 we may want to revisit
# this in some way, most likely specifically to Postgresql only.
assert_raises_message(
exc.CompileError,
"CREATE INDEX requires that the index have a name",
CreateIndex(idx).compile,
)
assert_raises_message(
exc.CompileError,
"DROP INDEX requires that the index have a name",
DropIndex(idx).compile,
)
示例11: create_table
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def create_table(self, table):
if util.sqla_07:
table.dispatch.before_create(table, self.connection,
checkfirst=False,
_ddl_runner=self)
self._exec(schema.CreateTable(table))
if util.sqla_07:
table.dispatch.after_create(table, self.connection,
checkfirst=False,
_ddl_runner=self)
for index in table.indexes:
self._exec(schema.CreateIndex(index))
示例12: create_index
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def create_index(self, index):
self._exec(schema.CreateIndex(index))
示例13: create_index
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def create_index(self, index):
# this likely defaults to None if not present, so get()
# should normally not return the default value. being
# defensive in any case
mssql_include = index.kwargs.get("mssql_include", None) or ()
for col in mssql_include:
if col not in index.table.c:
index.table.append_column(Column(col, sqltypes.NullType))
self._exec(CreateIndex(index))
示例14: test_create_partial_index
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_partial_index(self):
m = MetaData()
tbl = Table("testtbl", m, Column("data", Integer))
idx = Index(
"test_idx1",
tbl.c.data,
sqlite_where=and_(tbl.c.data > 5, tbl.c.data < 10),
)
# test quoting and all that
idx2 = Index(
"test_idx2",
tbl.c.data,
sqlite_where=and_(tbl.c.data > "a", tbl.c.data < "b's"),
)
self.assert_compile(
schema.CreateIndex(idx),
"CREATE INDEX test_idx1 ON testtbl (data) "
"WHERE data > 5 AND data < 10",
dialect=sqlite.dialect(),
)
self.assert_compile(
schema.CreateIndex(idx2),
"CREATE INDEX test_idx2 ON testtbl (data) "
"WHERE data > 'a' AND data < 'b''s'",
dialect=sqlite.dialect(),
)
示例15: test_create_index_alt_schema
# 需要导入模块: from sqlalchemy import schema [as 别名]
# 或者: from sqlalchemy.schema import CreateIndex [as 别名]
def test_create_index_alt_schema(self):
m = MetaData()
t1 = Table("foo", m, Column("x", Integer), schema="alt_schema")
self.assert_compile(
schema.CreateIndex(Index("bar", t1.c.x)),
"CREATE INDEX alt_schema.bar ON alt_schema.foo (x)",
)