Skip to content

Instantly share code, notes, and snippets.

@gawel
Last active December 30, 2015 10:02
Show Gist options
  • Save gawel/82eff173b594a261f219 to your computer and use it in GitHub Desktop.
Save gawel/82eff173b594a261f219 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
from tinydb import TinyDB
from tinydb import Query
db = TinyDB('db.json')
def fake():
from faker import Faker
f = Faker()
d = []
for i in range(50000):
d.append(dict(name=f.name(), email=f.email(),
company=f.company(),
tags=[dict(tag=f.state()), dict(tag='red')]))
db.insert_multiple(d)
fake()
User = Query()
Tag = Query()
print(db.search(User.name.matches(r'^[Aa].*e$') & User.tags.any(
(Tag.tag == 'red') | (Tag.tag == 'NM'))))
print(User.name.matches(r'^[Aa].*e$') & User.tags.any(
(Tag.tag == 'red') | (Tag.tag == 'NM')))
print(len(db))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment