-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.py
38 lines (29 loc) · 1006 Bytes
/
example.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import logging
import os
import sys
import dictabase as db
logging.basicConfig(
stream=sys.stdout,
format='%(asctime)s:%(levelname)s: %(message)s',
level=os.environ.get('DEBUG_LEVEL') or logging.INFO)
log = logging.getLogger(__name__) # pylint: disable=C0103
class ExampleModel(db.Model):
name = db.Property()
last = db.Property()
id_num = db.Property()
DATASET = [
ExampleModel(name="Nick", last="Hunter-Walker", id_num=43564),
ExampleModel(name="Nick", last="Denny", id_num=12435),
ExampleModel(name="Alan", last="Vezina", id_num=54321),
ExampleModel(name="Don", last="Sheu", id_num=34512),
]
def main():
with db.DictaBase(DATASET, indexes=('name', 'id_num')) as view:
query = view.query()
query = query.filter(ExampleModel.name > 'Joe')
query = query.filter(ExampleModel.id_num > 12436)
results = query.fetch()
for result in results:
log.info(result)
if __name__ == '__main__':
main()