A storage/query backend for Tokyo Cabinet.
Allows direct access to the database and is thus extremely fast. However, it locks the database and is therefore not suitable for environments where concurrent access is required. Please use Tokyo Tyrant for such environments.
database: | Tokyo Cabinet |
---|---|
status: | experimental |
dependencies: | tc (rsms) |
Warning
this module is not intended for production, it’s just a (working) example. Patches, improvements, rewrites are welcome.
Usage:
>>> import os
>>> import pymodels
>>> DB_SETTINGS = {
... 'backend': 'pymodels.backends.tokyo_cabinet',
... 'kind': 'TABLE',
... 'path': '_tc_test.tct',
... }
>>> assert not os.path.exists(DB_SETTINGS['path']), 'test database must not exist'
>>> db = pymodels.get_storage(DB_SETTINGS)
>>> class Person(pymodels.Model):
... name = pymodels.Property()
... __unicode__ = lambda self: self.name
>>> Person.objects(db) # the database is expected to be empty
[]
>>> db.connection.put('john', {'name': 'John'})
>>> mary = Person(name='Mary')
>>> mary_pk = mary.save(db)
>>> q = Person.objects(db)
>>> q
[<Person John>, <Person Mary>]
>>> q.where(name__matches='^J')
[<Person John>]
>>> q # the original query was not modified by the descendant
[<Person John>, <Person Mary>]
>>> os.unlink(DB_SETTINGS['path'])
Parameters: |
|
---|
Saves given model instance into the storage. Returns primary key.
Parameters: |
|
---|
Note that you must provide current primary key for a model instance which is already in the database in order to update it instead of copying it.
The Query class. Experimental.
Defines order in which results should be retrieved.
Parameters: |
|
---|
Examples:
q.order_by('name') # ascending
q.order_by('-name') # descending