Skip to main content

Database agnostic query system

Project description

link.dbrequest is a database agnostic query system.

See documentation for more informations.

License Development Status Latest release Supported Python versions Supported Python implementations Download format Build status Code test coverage Downloads Code Health Code issues

Installation

pip install link.dbrequest

Features

  • database agnostic

  • lazy query resolving

  • cached queries

  • queries are unique

Examples

Getting a backend:

from link.middleware.core import Middleware

# Will open a QueryManager using a MongoDB backend
manager = Middleware.get_middleware_by_uri('query+mongo://localhost:27107/mydatabase/mycollection')
# Will open a QueryManager using a SQL backend
manager = Middleware.get_middleware_by_uri('query+sql://localhost:5432/mydatabase/mytable')

Operations on the backend:

from link.dbrequest.expression import E, F
from link.dbrequest.assignment import A
from link.dbrequest.comparison import C


query = manager.all()  # get an iterable over all elements

manager.create(A('foo', 'bar'))  # put document {'foo': 'bar'} into database

doc = manager.get(C('foo') != 'bar')  # get single element, or None

Operations on queries:

docs = list(query)  # iterate over query to execute the request
docs = list(query)  # use cache when iterating again

# create a new query from the first one
q2 = query.filter(C('foo') == 'bar')
assert query is not q2

# exclude documents without a field named "bar"
q3 = q2.exclude(~C('bar'))

# filter documents "weight > 5" and "prop1 < prop2 * 5"
q4 = q3.filter((C('weight') > 5) & (C('prop1') < (E('prop2') * 5)))

# set "prop3 = prop1 + prop2" on q2 result
docs = q2.update(A('prop3', E('prop1') + E('prop2')))

# delete documents
q3.delete()

Operations on documents:

# save/delete a single document
doc.save()
doc.delete()

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

link.dbrequest-0.13.tar.gz (13.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

link.dbrequest-0.13-py2.py3-none-any.whl (21.4 kB view details)

Uploaded Python 2Python 3

File details

Details for the file link.dbrequest-0.13.tar.gz.

File metadata

  • Download URL: link.dbrequest-0.13.tar.gz
  • Upload date:
  • Size: 13.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for link.dbrequest-0.13.tar.gz
Algorithm Hash digest
SHA256 13e13fcb4eda1c5af8cebedbfa9f5f316ddfd6f540b96f00c90841449fdff9ba
MD5 c3fadeefc8d263ebf5f37a5534c5d1e0
BLAKE2b-256 15cbfb28efdacc0094a4ed86f6c8f80736987d962d52d6e18dda944d2026a17a

See more details on using hashes here.

File details

Details for the file link.dbrequest-0.13-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for link.dbrequest-0.13-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 311c6332487c1a3b3d5b5cf128bc43fafad829cfceebf95ec8ca9f9a9745f0a8
MD5 8aa97eaa0de50bea037ddfd94886db0f
BLAKE2b-256 055b9679ed2c96aa02b8df25908ba482c15215d43ab39f63737fc9a24e4b5417

See more details on using hashes here.

Supported by

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