Source

tclite /

Filename Size Date modified Message
tclite
70 B
1.7 KB
1.8 KB
64 B
3.4 KB

tclite

Tokyo cabinet and tokyo tyrant object wrapper.

Installation

$ pip install tclite

Usage

>>> import tclite as tl
>>> from datetime import datetime, date
>>> class User(tl.Model):
...     username    = tl.UnicodeProperty(key='u')  # realy stored by short 'u' key
...     birthday    = tl.DateProperty()
...     rating      = tl.IntegerProperty(default=0)
...     reply_rate  = tl.FloatProperty(default=0)
...     about_me    = tl.CompressedUnicodeProperty(internal_encoding='cp1251')
...     friends     = tl.DumpProperty(default={})
...     messages    = tl.CompressedDumpProperty(default=[])
...     is_active   = tl.BooleanProperty(default=True)
...     created     = tl.DateTimeProperty(index=True) # indexed field
...     choice      = tl.ChoiceProperty([('1', 'first'), ('2', 'second')])
...
...     __file__ = 'var/readme_test.tclite'
...     #__host__ = 'localhost:1978'
>>> User.db.clear()
>>> for i in xrange(100):
...     User(
...         username='user-%s' % i,
...         birthday=date(1900 + i, 1, 1),
...         created=datetime.now()
...     ).save()
>>> users = User.filter('birthday >=', date(1950, 1, 1))
>>> users.count()
50
>>> for user in users.filter('username endswith', '0').order('-created'):
...     user.username
u'user-90'
u'user-80'
u'user-70'
u'user-60'
u'user-50'
>>> users.get().username
u'user-50'
>>> users.delete()
>>> users.count()
0
>>> User.filter().count()
50
>>> User(username='Foo', key='user-foo').save()  # set custom key name
>>> User.get('user-foo').username  # get by keyname
u'Foo'
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.