Skip to main content

Query proxy that allows the usage of AtlasSearch with mongoengine specific syntax

Project description

AtlasQ

AtlasQ allows the usage of AtlasSearch keeping the MongoEngine syntax.

Structure

The package tries to follow the MongoEngine structure; the major differences reside in the transform.py and queryset.py files.

Transform

Like in MongoEngine, a step in the pipeline is the creation of a query from a Q object: we have to find a correspondence between the MongoEngine common syntax and what AtlasSearch allows. For doing this, we had to find some compromises.

Not every keyword is supported at the moment: if you have an actual use case that you would like to support, please be free to open an issue or a PR at any moment.

QuerySet

There are probably a thousand of better implementation, if you actually knew MongoEngine and above all PyMongo. Unfortunately, our knowledge is limited, so here we go. If you find a solution that works better, again, feel free to open an issue or a PR.

The main idea, is that the filter should work like an aggregation. For doing so, and with keeping the compatibility on how MongoEngine works (i.e. the filter should return a queryset of Document) we had to do some work.
Calling .aggregate instead has to work as MongoEngine expect, meaning a list of dictionaries.

Features

Validation

We also decided to have, optionally, a validation of the index. Two things are checked:

  • The index actually exists (If you query a non-existing index, Atlas as default behaviour will not raise any error).
  • The fields that you are querying are actually indexed(If you query a field that is not indexed, Atlas as default behaviour will not raise any error, and will return an empty list). To make these check, you need to call the function ensure_index on the queryset:

Usage

Now the most important part: how do you use this package?

from mongoengine import Document, fields

from atlasq import AtlasManager, AtlasQ, AtlasQuerySet

index_name = str("my_index")

class MyDocument(Document):
    name = fields.StringField(required=True)
    surname = fields.StringField(required=True)
    atlas = AtlasManager(index_name)

obj = MyDocument.objects.create(name="value", surname="value2")

qs = MyDocument.atlas.filter(name="value")
assert isinstance(qs, AtlasQuerySet)
obj_from_atlas = qs.first()
assert obj == obj_from_atlas

obj2_from_atlas = MyDocument.atlas.get(AtlasQ(name="value") & AtlasQ(surname="value2"))
assert obj == obj2_from_atlas


obj3_from_atlas = MyDocument.atlas.get(AtlasQ(wrong_field="value"))
assert obj3_from_atlas is None

result = MyDocument.atlas.ensure_index("user", "pwd", "group", "cluster")
assert result is True
obj3_from_atlas = MyDocument.atlas.get(AtlasQ(wrong_field="value")) # raises AtlasIndexFieldError

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

atlasq-0.2.5.tar.gz (18.4 kB view details)

Uploaded Source

Built Distribution

atlasq-0.2.5-py3-none-any.whl (21.9 kB view details)

Uploaded Python 3

File details

Details for the file atlasq-0.2.5.tar.gz.

File metadata

  • Download URL: atlasq-0.2.5.tar.gz
  • Upload date:
  • Size: 18.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for atlasq-0.2.5.tar.gz
Algorithm Hash digest
SHA256 1bd58f2b9d6a39e8c1719fb1e2736745c81f81b4c1b8a728e80d9b42a638d27f
MD5 4740adc169a35cd4cdb9f9d61f8f9b10
BLAKE2b-256 f849bc58dfb8036d1748052b0014da40803a5643cd5eef2ba927d2b2ec174ab8

See more details on using hashes here.

File details

Details for the file atlasq-0.2.5-py3-none-any.whl.

File metadata

  • Download URL: atlasq-0.2.5-py3-none-any.whl
  • Upload date:
  • Size: 21.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.9.13

File hashes

Hashes for atlasq-0.2.5-py3-none-any.whl
Algorithm Hash digest
SHA256 c5dc7eefd6fe80886c235d1be744358c4fe3b410b4ffe27a15ba9c0ba721014d
MD5 1287d6eeb9ac3b9ce2bfd26fa689c1b2
BLAKE2b-256 15776610289a2bc629d22df377a1b235a2432104d1d3a9ef005b42d6439751e5

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page