同时创建json索引

django-indices的Python项目详细描述


同时创建json索引

这个django应用程序提供的功能类似于 indexes, 只是它提供了一个创建索引的选项 concurrently

目前,只支持postgres json索引。

安装

使用pip安装最新版本:

pip install django_indices

django_indices添加到django设置文件中的INSTALLED_APPS

INSTALLED_APPS=(...,"django_indices",)

运行迁移:

python manage.py migrate django_indices

将您想要的索引添加到所需模型的Meta类中。那就跑吧 添加/删除索引的migrate_indices管理命令:

python manage.py migrate_indices

示例

fromdjango.dbimportmodelsfromdjango.db.modelsimportQfromdjango.contrib.postgres.fieldsimportJSONFieldfromdjango_indicesimportJSONIndexclassInventory(models.Model):data=JSONField()classMeta:indices=[# Creates an index on data->'product_type'# Indexes are created concurrently by default, which doesn't lock# the table.JSONIndex(field=["data","product_type"],name="idx_inventory_product_type",),# Creates a unique index on data->'product'->>'id'## concurrently=False ensures that the index creation will execute# in a transaction. So the index is either created successfully,# or fails cleanly. This will lock the table though.JSONIndex(field=["data","product","id"],name="idx_inventory_product_id",unique=True,concurrently=False,),# Creates a partial compound index on# (data->'product'->>'brand', data->'product'->>'size')# WHERE data->>'product_type' = 'shoe' OR data->>'product_type' = 'crocs'JSONIndex(field=(["data","product","brand"],["data","product","size"]),name="idx_inventory_footwear_brand_size",where=(Q(data__product_type="shoe")|Q(data__product_type="crocs"),),]

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
CentOS上的java Spring Boot简易应用程序需要很长时间才能启动   java如何检查字符串值是否等于null?   收集器中的java映射值。分组方式()   java需要支持Azure AD B2C webapp集成   java如何加入线程以停止它?   java如何使用意图传递类的对象?   java如何在战争环境中发现CDI生产者?   多模块项目中java奇怪的编译器行为   java如何在web应用程序中管理密码?   java从http服务器、filehandler中删除冗余代码   java使用反射来获取泛型类的字段   java Spring MVC/Hibernate/MySQL 400错误请求错误   给定正整数a的java幂为3   在Java中将元素拆分为不同数量的列表?   java展开折叠窗格