acid
acid copied to clipboard
join()/merge() helper functions/classes
Once Key creation (issue #23) and iteration (#37) are made cheap, implementing some less trivial query styles becomes interesting. Not decided on what this should look like. Maybe:
class User(acid.meta.Model):
name = acid.meta.String()
location = acid.meta.String()
age = acid.emta.Integer()
@acid.meta.index
def by_location(self):
return self.location
@acid.meta.index
def by_age(self):
return self.age
# Find everyone in London aged 29-33.
join = acid.Join()
join.intersect(User.by_age, lo=29, hi=33, include=True)
join.intersect(User.by_location, args="London")
join.order(User.by_age)
for user in join:
print 'Found', user
Perhaps an interface like:
# Return a Merge instance representing keys of all users interested
# in swimming or snorkling.
lifestyles = acid.merge(User.by_lifestyle.exact('swimming'),
User.by_lifestyle.exact('snorkling'))
# Return a Join instance representing keys of all users present in
# `lifestyles', and additionally female and aged 16-32.
population = acid.join(User.by_age.range(16, 32),
User.by_sex.exact('male'),
lifestyles)
print('There are %d males 16-32 who enjoy swimming or snorkling' %\
population.count())
How to represent non-indexed criteria?