storage_handler module

This module handles the database, maintains indexes and provides search function over this indexes.

exception storage.storage_handler.InvalidType

Raised in case that object you are trying to store doesn’t have required interface.

exception storage.storage_handler.UnindexableObject

Raised in case, that object doesn’t have at least one attribute set.

class storage.storage_handler.StorageHandler(project_key, conf_path='/home/docs/checkouts/readthedocs.org/user_builds/edeposit-amqp-storage/checkouts/latest/src/edeposit/amqp/storage/zconf/zeo_client.conf')

Object database with indexing by the object attributes.

Each stored object is required to have following properties:

  • indexes (list of strings)
  • project_key (string)

For example:

class Person(Persistent):
    def __init__(self, name, surname):
        self.name = name
        self.surname = surname

    @property
    def indexes(self):
        return [
            "name",
            "surname",
        ]

    @property
    def project_key(self):
        return PROJECT_KEY

Note

I suggest to use properties, because that way the values are not stored in database, but constructed at request by the property methods.

Constructor.

Parameters:
  • project_key (str) – Project key which is used for the root of DB.
  • conf_path (str) – Path to the client zeo configuration file. Default settings.ZEO_CLIENT_PATH.
store_object(obj)

Save obj into database and into proper indexes.

Attr:
obj (obj): Indexable object.
Raises:
  • InvalidType – When the obj doesn’t have right properties.
  • Unindexableobjlication – When there is no indexes defined.
search_objects(query)

Return list of objects which match all properties that are set (not None) using AND operator to all of them.

Example

result = storage_handler.search_objects(
DBPublication(isbn=”azgabash”)

)

Parameters:query (obj) – Object implementing proper interface with some of the properties set.
Returns:List of matching objects or [] if no match was found.
Return type:list
Raises:InvalidType – When the query doesn’t implement required properties.