Blitz is a document-oriented database for Python that is backend-agnostic. It comes with a flat-file database for JSON documents and provides MongoDB-like querying capabilities.
from blitzdb import Document
from blitzdb.backends.file import Backend
class Movie(Document):
pass
backend = Backend('_test')
Movie({'name': 'The Godfather', 'year': 1972}).save(backend)
Movie({'name': 'Goodfellas', 'year': 1990}).save(backend)
Movie({'name': 'Star Wars', 'year': 1977}).save(backend)
backend.commit()
movies = backend.filter(Movie, {'year': lambda year: year >= 1970 and year <= 1979})
gives
Traceback (most recent call last):
File "test.py", line 19, in <module>
'year': lambda year: year >= 1970 and year <= 1979,
File "/home/kmahan/projects/blitzdb/blitzdb/backends/file/backend.py", line 586, in filter
query_set = compiled_query(query_function)
File "/home/kmahan/projects/blitzdb/blitzdb/backends/file/queries.py", line 38, in _get
return query_function(key, expression)
File "/home/kmahan/projects/blitzdb/blitzdb/backends/file/backend.py", line 569, in query_function
indexes[key].get_keys_for(expression)
File "/home/kmahan/projects/blitzdb/blitzdb/backends/file/queryset.py", line 42, in __init__
self.keys = list(keys)
TypeError: 'bool' object is not iterable
The problem seems to be that Index.get_keys_for has value=lambda year: year>=1970..., and calls value(self) on it, but changing the get_keys_for function seemed to break assumptions for a bunch of other query styles.
gives
The problem seems to be that
Index.get_keys_for
has value=lambda year: year>=1970..., and calls value(self) on it, but changing theget_keys_for
function seemed to break assumptions for a bunch of other query styles.