Search MySQL JSON fields in Django
Project description
# jsonLookup Searching in MySQL JSON field in Django
# Challenge
MySQL has introduced JSON fields in MySQL Server 5.7, Currently it works well with [jsonfield](https://github.com/bradjasper/django-jsonfield) for Data Saving and retrieval. The problem that Searching can only be done through LIKE operator which isn’t convinent for all function.
# Objective
Creating a new custom lookup operator “has” for Django that will support JSON Search in MySQL.
# Installation
### Install the Package `sh $ pip install jsonLookup `
### Register to JSONFields
`python from jsonLookup import hasLookup,jcontainsLookup JSONField.register_lookup(hasLookup) JSONField.register_lookup(jcontainsLookup) `
### Write your JSON queries
`python # Create test objects User.objects.create(name="Ahmed",properties={"city":"Giza","Address":{"district":"Ahram","Code":11263}}) User.objects.create(name="Mohamed",properties={"city":"Cairo","Address":{"district":"Helipolis","Code":11351}}) # Run first query q = User.objects.filter(properties__has="$.city=Giza") print q[0].name "Ahmed" # Run Second query q= User.objects.filter(properties__has="$.Address.Code=11351") print q[0].name "Mohamed" `
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Hashes for jsonLookup-0.5.2-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 04129089aac5339917a1d9f094fdc8bbe7df3a95cc75dfcdb8cdcdfe4726430b |
|
MD5 | 33b169642a6e6dcaae36df7b79458d10 |
|
BLAKE2b-256 | 4128c23e212258167e14312bd299c2a68d2eba2f0ff8a710f547f7251047527a |