Giter VIP home page Giter VIP logo

django-mongoengine-rql's Introduction

Django Mongoengine RQL

pyversions PyPi Status PyPI status PyPI Downloads Quality Gate Status Coverage

Introduction

RQL (Resource query language) is designed for modern application development. It is built for the web, ready for NoSQL, and highly extensible with simple syntax. This is a query language for fast and convenient database interaction. RQL was designed for use in URLs to request object-style data structures.

This library is a Django-Mongoengine specific implementation of RQL filtering.

RQL Reference

Django RQL

Django Mongoengine

Install

Django Mongoengine RQL can be installed from pypi.org using pip:

$ pip install django-mongoengine-rql

Documentation

This library is fully based on Django RQL, so there are no specific docs for it. Full documentation for Django-RQL is available at https://django-rql.readthedocs.org.

Example

# filters.py
from dj_mongoengine_rql.filter_cls import MongoengineRQLFilterClass
from py_rql.constants import FilterLookups
from your_docs import Document

class DocFilters(MongoengineRQLFilterClass):
    MODEL = Document
    SELECT = True
    FILTERS = (
        'filter1',
        {
            'filter': 'filter2',
            'source': 'related_doc__doc_field',
        },
        {
            'namespace': 'ns1',
            'filters': ('ns1f',),
        },
        {
            'filter': 'filter3',
            'lookups': {FilterLookups.EQ, FilterLookups.IN},
        },
    )


# views.py
from dj_rql.drf.backend import RQLFilterBackend
from dj_rql.drf.paginations import RQLContentRangeLimitOffsetPagination
from rest_framework import mixins
from rest_framework.viewsets import GenericViewSet

class DRFViewSet(mixins.ListModelMixin, GenericViewSet):
    queryset = Document.objects.all()
    rql_filter_class = DocFilters
    pagination_class = RQLContentRangeLimitOffsetPagination
    filter_backends = (RQLFilterBackend,)

Notes

Due to implementation and Mongo engine features there may be some limitations in filtering, for example:

  • distinct setting is not supported for filters
  • annotations are not supported, as well

Development

  1. Python 3.8+
  2. Install dependencies pip install poetry && poetry install
  3. We use isort library to order and format our imports, and black - to format the code. We check it using flake8-isort and flake8-black libraries (automatically on flake8 run).
    For convenience you may run docker compose run format to format the code.

Testing

  1. Python 3.8+
  2. Install dependencies pip install poetry && poetry install

Check code style: poetry run flake8 Run tests: poetry run pytest Run integration tests: docker compose run app_test

Tests reports are generated in tests/reports.

  • out.xml - JUnit test results
  • coverage.xml - Coverage xml results

To generate HTML coverage reports use: --cov-report html:tests/reports/cov_html

License

Django Mongoengine RQL is released under the Apache License Version 2.0.

django-mongoengine-rql's People

Contributors

maxipavlovic avatar hairash avatar zzzevaka avatar marcserrat avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.