acid
acid copied to clipboard
Cross-collection index
Once #39 is complete, it would become possible to have an index covering multiple collections. This has interesting interactions with implementing joins. It's also another use case where explicitly including the prefix as part of Key's data would be useful. Imagine something like:
class Person(MyModel):
name = acid.meta.String()
location = acid.meta.GeoPoint()
class Event(MyModel):
name = acid.meta.String()
location = acid.meta.GeoPoint()
class CarCrash(MyModel):
sports_car = acid.meta.Bool()
crash_location = acid.meta.GeoPoint()
class MultiIndex(acid.meta.MultiIndex):
@acid.meta.index_func(Person):
@acid.meta.index_func(Event):
def index_location(self, obj):
return obj.location
@acid.meta.index_func(CarCrash):
def index_crash_location(self, crash):
return rash.crash_location
# Return everything that happened in London.
london = acid.Point(0.249111, 0.614548)
for obj in MultiIndex.iter(prefix=london.within(miles=1)):
if isinstance(obj, Person):
print 'Person located nearby:', obj
elif isinstance(obj, Event):
print 'Event happened nearby:', obj
else:
print 'Car crash happened:', obj