pip install odbm
from datetime import datetime, date import odbm # class User(odbm.Model): username = odbm.UnicodeProperty(primary_key=True) birthday = odbm.DateProperty(key='b') is_active = odbm.Property(key='a', default=True) is_admin = odbm.Property(key='r', default=False) created = odbm.DateTimeProperty(key='c') __filename__ = 'var/user.odbm.tch' __db_type__ = 'tc' # User(username='fizban', birthday=date(1917, 1, 1), created=datetime.now()).save() # dict-style : # db['fizban'] = {'b': timestamp , 'c': timestamp } # (. key=... property) # u = User.get('fizban') print u.birthday # datetime.date(1917, 1, 1) # u.is_active = False u.save() # for i in xrange(10): User(username=('test-%i' % i), birthday=date(1950 + i, 1, 1)).save() # User.find() # c birthday > 1955, username for obj in User.find( filter = lambda u: u.birthday.year > 1955, order = lambda u: u.username): print obj # print User.count(lambda u: u.username.startswith('f')) # 1 # print User.count() # 11 User.find_one().delete() print User.count() # 10
seconds to write/read 10000 rows
pickle (write, read): (1.0030829906463623, 0.25429201126098633)
odbm (write, read): (0.99477910995483398, 0.14065694808959961)
pickle file size: 2768704
odbm file size: 1348752
Source: https://habr.com/ru/post/114300/
All Articles