Database agnostic query system
Project description
link.dbrequest is a database agnostic query system.
See documentation for more informations.
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
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 Distribution
link.dbrequest-0.9.tar.gz
(13.7 kB
view details)
Built Distribution
File details
Details for the file link.dbrequest-0.9.tar.gz
.
File metadata
- Download URL: link.dbrequest-0.9.tar.gz
- Upload date:
- Size: 13.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
36d2400cab8483e65ced4cd712af786a8623f47082220e2263a29bdbe3620c2f
|
|
MD5 |
941b20953e5e839173b35e21fa075a08
|
|
BLAKE2b-256 |
83a87de3ae516039214b2918b028ec5353946a70ed588d95d5c71e1b10f52257
|
File details
Details for the file link.dbrequest-0.9-py2.py3-none-any.whl
.
File metadata
- Download URL: link.dbrequest-0.9-py2.py3-none-any.whl
- Upload date:
- Size: 21.4 kB
- Tags: Python 2, Python 3
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 |
d07379f43d61d1caf532267057515dbbdc9c8f472c048f6d2e74f135ab66e2e6
|
|
MD5 |
b5c532024aecbdc64840124c8a607e71
|
|
BLAKE2b-256 |
f5494a4ee9d44f5e327260b1b45776ca7101c7b35c4225fff99d8843b0654bc1
|