Tokyo Tyrant extension

A storage/query backend for Tokyo Tyrant.

status:stable
database:Tokyo Cabinet, Tokyo Tyrant
dependencies:Pyrant
suitable for:general purpose
class doqu.ext.tokyo_tyrant.storage.StorageAdapter(**kw)
clear()

Clears the whole storage from data, resets autoincrement counters.

connect()

Connects to the database. Raises RuntimeError if the connection is not closed yet. Use StorageAdapter.reconnect() to explicitly close the connection and open it again.

delete(key)

Permanently deletes the record with given primary key from the database.

get(doc_class, primary_key)

Returns document instance for given document class and primary key. Raises KeyError if there is no item with given key in the database.

get_many(doc_class, primary_keys)

Returns a list of documents with primary keys from given list. Basically this is just a simple wrapper around get() but some backends can reimplement the method in a much more efficient way.

get_or_create(doc_class, **kwargs)

Queries the database for records associated with given document class and conforming to given extra condtions. If such records exist, picks the first one (the order may be random depending on the database). If there are no such records, creates one.

Returns the document instance and a boolean value “created”.

reconnect()

Gracefully closes current connection (if it’s not broken) and connects again to the database (e.g. reopens the file).

save(data, primary_key=None)

Saves given model instance into the storage. Returns primary key.

Parameters:
  • data – dict containing all properties to be saved
  • primary_key – the key for given object; if undefined, will be generated

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.

class doqu.ext.tokyo_tyrant.query.QueryAdapter(storage, model)
count()

Returns the number of records that match current query. Does not fetch the records.

delete()

Deletes all records that match current query.

values(name)

Returns a list of unique values for given column name.

where(**conditions)

Returns Query instance filtered by given conditions.

where_not(**conditions)

Returns Query instance. Inverted version of where().

Previous topic

Tokyo Cabinet extension

Next topic

MongoDB extension

This Page