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


Python schema.Index类代码示例

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


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

示例1: downgrade

def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    service_statuses = Table('service_statuses', meta, autoload=True)
    idx = Index("service_statuses_instance_id", service_statuses.c.instance_id)
    idx.drop()
开发者ID:AlexeyDeyneko,项目名称:trove,代码行数:7,代码来源:025_add_service_statuses_indexes.py

示例2: create_index

    def create_index(self, columns, name=None):
        """
        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'])
        """
        self._check_dropped()
        if not name:
            sig = '||'.join(columns)

            # This is a work-around for a bug in <=0.6.1 which would create
            # indexes based on hash() rather than a proper hash.
            key = abs(hash(sig))
            name = 'ix_%s_%s' % (self.table.name, key)
            if name in self.indexes:
                return self.indexes[name]

            key = sha1(sig.encode('utf-8')).hexdigest()[:16]
            name = 'ix_%s_%s' % (self.table.name, key)

        if name in self.indexes:
            return self.indexes[name]
        try:
            self.database._acquire()
            columns = [self.table.c[c] for c in columns]
            idx = Index(name, *columns)
            idx.create(self.database.engine)
        except:
            idx = None
        finally:
            self.database._release()
        self.indexes[name] = idx
        return idx
开发者ID:reubano,项目名称:dataset,代码行数:34,代码来源:table.py

示例3: create_index

 def create_index(self, columns, name=None, index_type="btree"):
     """
     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'])
     """
     self._check_dropped()
     if not name:
         sig = "||".join(columns + [index_type])
         # This is a work-around for a bug in <=0.6.1 which would create
         # indexes based on hash() rather than a proper hash.
         key = abs(hash(sig))
         name = "ix_%s_%s" % (self.table.name, key)
         if name in self.indexes:
             return self.indexes[name]
         key = sha1(sig.encode("utf-8")).hexdigest()[:16]
         name = "ix_%s_%s" % (self.table.name, key)
     if name in self.indexes:
         return self.indexes[name]
     # self.db._acquire()
     columns = [self.table.c[col] for col in columns]
     idx = Index(name, *columns, postgresql_using=index_type)
     idx.create(self.engine)
     # finally:
     #    self.db._release()
     self.indexes[name] = idx
     return idx
开发者ID:smnorris,项目名称:pgdb,代码行数:28,代码来源:table.py

示例4: upgrade

def upgrade(migrate_engine):
    LOG.info(_LI("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:ISCAS-VDI,项目名称:designate-base,代码行数:8,代码来源:084_add_delayed_notify_column.py

示例5: generate_key_index

 def generate_key_index(self):
     for index in self.key.table.indexes:
         if len(index.columns) == 1:
             for col in index.columns:
                 if col == self.key:
                     return
     index = Index(self.index_name, self.key)
     index.create(self.config.engine)
开发者ID:backgroundcheck,项目名称:linkage,代码行数:8,代码来源:model.py

示例6: upgrade

def upgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    service_statuses = Table('service_statuses', meta, autoload=True)
    idx = Index("service_statuses_instance_id", service_statuses.c.instance_id)

    try:
        idx.create()
    except OperationalError as e:
        logger.info(e)
开发者ID:Tesora,项目名称:tesora-trove,代码行数:11,代码来源:025_add_service_statuses_indexes.py

示例7: upgrade

def upgrade(migrate_engine):
    meta.bind = migrate_engine
    Table('datastores', meta, autoload=True)
    Table('datastore_versions', meta, autoload=True)
    instances = Table('instances', meta, autoload=True)
    create_tables([clusters])
    instances.create_column(Column('cluster_id', String(36),
                                   ForeignKey("clusters.id")))
    instances.create_column(Column('shard_id', String(36)))
    instances.create_column(Column('type', String(64)))
    cluster_id_idx = Index("instances_cluster_id", instances.c.cluster_id)
    cluster_id_idx.create()
开发者ID:Hopebaytech,项目名称:trove,代码行数:12,代码来源:032_clusters.py

示例8: generate_key_index

    def generate_key_index(self):
        key = self.key
        table = key.table
        if isinstance(table, Alias):
            table = table.original
            key = table.c[key.name]

        for index in table.indexes:
            if len(index.columns) == 1:
                for col in index.columns:
                    if col == key:
                        return
        index = Index(self.index_name, key)
        index.create(self.config.engine)
开发者ID:pudo,项目名称:linkage,代码行数:14,代码来源:model.py

示例9: create_index

def create_index(engine, table, columns, name=None):
    with lock:
        if not name:
            sig = abs(hash('||'.join(columns)))
            name = 'ix_%s_%s' % (table.name, sig)
        if name in INDEXES:
            return INDEXES[name]
        try:
            columns = [table.c[c] for c in columns]
            idx = Index(name, *columns)
            idx.create(engine)
        except:
            idx = None
        INDEXES[name] = idx
        return idx
开发者ID:rossjones,项目名称:sqlaload,代码行数:15,代码来源:schema.py

示例10: create_index

def create_index(engine, table, columns, name=None):
    table = get_table(engine, table)
    with lock:
        if not name:
            sig = abs(hash("||".join(columns)))
            name = "ix_%s_%s" % (table.name, sig)
        if name in engine._indexes:
            return engine._indexes[name]
        try:
            columns = [table.c[c] for c in columns]
            idx = Index(name, *columns)
            idx.create(engine)
        except:
            idx = None
        engine._indexes[name] = idx
        return idx
开发者ID:jljs,项目名称:sqlaload,代码行数:16,代码来源:schema.py

示例11: upgrade

def upgrade(migrate_engine):
    meta.bind = migrate_engine
    Table('datastores', meta, autoload=True)
    Table('datastore_versions', meta, autoload=True)
    instances = Table('instances', meta, autoload=True)

    # since the downgrade is a no-op, an upgrade after a downgrade will
    # cause an exception because the tables already exist
    # we will catch that case and log an info message
    try:
        create_tables([clusters])

        instances.create_column(Column('cluster_id', String(36),
                                       ForeignKey("clusters.id")))
        instances.create_column(Column('shard_id', String(36)))
        instances.create_column(Column('type', String(64)))

        cluster_id_idx = Index("instances_cluster_id", instances.c.cluster_id)
        cluster_id_idx.create()
    except OperationalError as e:
        logger.info(e)
开发者ID:rumale,项目名称:trove,代码行数:21,代码来源:032_clusters.py

示例12: create_index

    def create_index(self, columns, name=None):
        """
        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'])
        """
        self._check_dropped()
        with self.database.lock:
            if not name:
                sig = abs(hash('||'.join(columns)))
                name = 'ix_%s_%s' % (self.table.name, sig)
            if name in self.indexes:
                return self.indexes[name]
            try:
                columns = [self.table.c[c] for c in columns]
                idx = Index(name, *columns)
                idx.create(self.database.engine)
            except:
                idx = None
            self.indexes[name] = idx
            return idx
开发者ID:aklaver,项目名称:dataset,代码行数:22,代码来源:table.py

示例13: visit_column

    def visit_column(self, column):
        """Create a column (table already exists).

        :param column: column object
        :type column: :class:`sqlalchemy.Column` instance
        """
        if column.default is not None:
            self.traverse_single(column.default)

        table = self.start_alter_table(column)
        self.append("ADD ")
        self.append(self.get_column_specification(column))

        for cons in column.constraints:
            self.traverse_single(cons)
        self.execute()

        # ALTER TABLE STATEMENTS

        # add indexes and unique constraints
        if column.index_name:
            ix = Index(column.index_name,
                       column,
                       unique=bool(column.index_name or column.index))
            ix.create()
        elif column.unique_name:
            constraint.UniqueConstraint(column,
                                        name=column.unique_name).create()

        # SA bounds FK constraints to table, add manually
        for fk in column.foreign_keys:
            self.add_foreignkey(fk.constraint)

        # add primary key constraint if needed
        if column.primary_key_name:
            cons = constraint.PrimaryKeyConstraint(column,
                                                   name=column.primary_key_name)
            cons.create()
开发者ID:hgroll,项目名称:yocto-autobuilder,代码行数:38,代码来源:ansisql.py

示例14: downgrade

def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    instances = Table('instances', meta, autoload=True)

    tenant_id_idx = Index("instances_tenant_id", instances.c.tenant_id)
    tenant_id_idx.drop()

    deleted_idx = Index("instances_deleted", instances.c.deleted)
    deleted_idx.drop()
开发者ID:cretta,项目名称:trove,代码行数:11,代码来源:023_add_instance_indexes.py

示例15: downgrade

def downgrade(migrate_engine):
    meta = MetaData()
    meta.bind = migrate_engine

    backups = Table('backups', meta, autoload=True)
    backups_instance_id_idx = Index("backups_instance_id",
                                    backups.c.instance_id)
    backups_deleted_idx = Index("backups_deleted", backups.c.deleted)

    meta.bind = migrate_engine
    backups_instance_id_idx.drop()
    backups_deleted_idx.drop()
开发者ID:AlexeyDeyneko,项目名称:trove,代码行数:12,代码来源:024_add_backup_indexes.py


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