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


Python SqliteDatabase.create_index方法代码示例

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


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

示例1: build_features_tree

# 需要导入模块: from peewee import SqliteDatabase [as 别名]
# 或者: from peewee.SqliteDatabase import create_index [as 别名]
    def build_features_tree(self):
        from peewee import SqliteDatabase, Model, IntegerField, CharField, BooleanField

        # built or connect database
        sqlite_path = {
                "memory" : ":memory:",
                "disk"   : self.sqlite3db_path(),
        }[self.link_to_detdup.storage_type]
        sqlite_database = SqliteDatabase(sqlite_path, check_same_thread=False)

        class BaseFeaturesTree(Model):
            uniq_chars__len     = IntegerField(default=0)
            sqrt_chars__len     = IntegerField(default=0)
            sorted_freq_chars   = CharField()
# TODO support item_id as int or str type
            item_id             = CharField()

            class Meta:
                database = sqlite_database
        self.features_tree = BaseFeaturesTree

        tablename = "_".join(self.custom_features).capitalize() or "DefaultFeaturesTree"

        # If customize more features
        if self.custom_features:
            self.features_tree = type(tablename, (BaseFeaturesTree,), dict())
            for feature_k1 in self.custom_features:
                # http://stackoverflow.com/questions/22358489/dynamically-define-fields-in-a-peewee-model
                feature_v1 = self.custom_features[feature_k1]
                # Compact with (int) instance
                if type(feature_v1) is int: feature_v1 = int
                field1 = {int: IntegerField, str: CharField}[feature_v1]()
                field1.add_to_class(self.features_tree, feature_k1)

        self.features_tree._meta.db_table = tablename

        # create table and indexes
        if not self.features_tree.table_exists():
            self.features_tree.create_table()
            sqlite_database.create_index(self.features_tree, "item_id".split(" "))

# TODO 让大str在前面,加快索引搜索速度
            index_columns = self.default_features.keys() + self.custom_features.keys()
            sqlite_database.create_index(self.features_tree, index_columns)

        print "[build_features_tree]", self.features_tree, "self.default_features :", self.default_features, "self.custom_features :", self.custom_features
        print
开发者ID:17zuoye,项目名称:detdup,代码行数:49,代码来源:default.py

示例2: __init__

# 需要导入模块: from peewee import SqliteDatabase [as 别名]
# 或者: from peewee.SqliteDatabase import create_index [as 别名]
    def __init__(self, data_model):
        self.data_model = data_model
        self.data_model.fake_item_ids_store = self

        assert self.data_model.cache_dir, "FakeItemIds need cache_dir from data_model!"
        sqlite_path = os.path.join(self.data_model.cache_dir, "fake_item_ids_store.db")

        sqlite_database = SqliteDatabase(sqlite_path, check_same_thread=False)

        class FakeItemIdsStore(Model):
            is_deleted = BooleanField(default=False)  # mark processed or duplicated items
            item_id = CharField()
            item_content_json = TextField()
            created_at = TimeField(default=datetime.datetime.now)

            class Meta:
                database = sqlite_database
        self.storage = FakeItemIdsStore

        if not self.storage.table_exists():
            self.storage.create_table()
            sqlite_database.create_index(self.storage, "is_deleted item_id".split(" "))
开发者ID:17zuoye,项目名称:detdup,代码行数:24,代码来源:fake_item_ids.py


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