當前位置: 首頁>>代碼示例>>Python>>正文


Python schema.CreateIndex方法代碼示例

本文整理匯總了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) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:25,代碼來源:impl.py

示例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() + ';') 
開發者ID:EdwardBetts,項目名稱:osm-wikidata,代碼行數:24,代碼來源:cli.py

示例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)",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:21,代碼來源:test_compiler.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:25,代碼來源:test_compiler.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:24,代碼來源:test_compiler.py

示例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,
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:19,代碼來源:test_compiler.py

示例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",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:18,代碼來源:test_compiler.py

示例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))",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:22,代碼來源:test_compiler.py

示例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))",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:26,代碼來源:test_compiler.py

示例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,
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:21,代碼來源:test_metadata.py

示例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)) 
開發者ID:jpush,項目名稱:jbox,代碼行數:14,代碼來源:impl.py

示例12: create_index

# 需要導入模塊: from sqlalchemy import schema [as 別名]
# 或者: from sqlalchemy.schema import CreateIndex [as 別名]
def create_index(self, index):
        self._exec(schema.CreateIndex(index)) 
開發者ID:jpush,項目名稱:jbox,代碼行數:4,代碼來源:impl.py

示例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)) 
開發者ID:sqlalchemy,項目名稱:alembic,代碼行數:11,代碼來源:mssql.py

示例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(),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:30,代碼來源:test_sqlite.py

示例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)",
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:9,代碼來源:test_compiler.py


注:本文中的sqlalchemy.schema.CreateIndex方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。