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

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()

Donating

Support via Liberapay

Project details


Download files

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

Files for link.dbrequest, version 0.19
Filename, size File type Python version Upload date Hashes
Filename, size link.dbrequest-0.19-py2.py3-none-any.whl (29.1 kB) File type Wheel Python version 3.4 Upload date Hashes View hashes
Filename, size link.dbrequest-0.19.tar.gz (17.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page