예제 #1
0
for r in db('age') >= 20:
    print(r)
print('#######')
print('shortguy')
for r in db('name').ilike('jeremy'):
    print(r)
print('#######')
#db support list comprehension
really_really_really_short = next(r for r in db('size') < 1.0)

#update supports record(s) value(s) and updates the indicie
db.update(really_really_really_short, size=0.1)
fp()  #even shorter
db.update(db, age='23')
fp()

#delete supports single and multiple records
db.delete(r for r in db('size') >= 0.2)
fp()
del db[next(r for r in db('size') < 0.2)['__id__']]
fp()

#useful utility functions
db.add_field('mood',
             default='catcucumber')  # adds field, with optional default value
db.drop_field('mood')  # drops field
db.path  # path of db, can be changed
db.name  # name of db, stripped of path
db.fields  # fields of db, excludes __id__ & __version__
len(db)  # number of records in db