The Depot

ACR provides a key-value storage that makes possible to store and retrieve data in collections without the need to create and manage database tables. The Depot also provides a way to lookup data, keep in mind that while storing and retrieving data is quite fast, lookup is a costly operation that requires fetching and checking all the available data for the filters you are applying.

The Depot will be available inside Genshi and User Defined Views as acr.depot.

Store/Retrieve/Delete

Basic Depot functions include:

  • acr.depot.create(collection_name, data) -> collection_name is the name of the collection and data a
    dictionary of strings to store, returns a Result object with data and object_id of the newly created object.
  • acr.depot.get(collection_name, object_id)-> given a collection and an object_id will return the Result
    object for the currently stored entry or None.
  • acr.depot.update(collection_name, object_id, data) -> Updates an existing entry with the given object_id
    setting its fields to every property specified in the data dictionary. Properties not specified in the new data dictionary will be kept to the previous value. The update call returns a Result object representing the state of the entry before update or None.
  • acr.depot.delete(collection_name, object_id) -> Deletes an entry from the specified collection, if the action
    is successful a Result object with the entry recently deleted is returned.

EXAMPLE:

created = acr.depot.create('depot_test', {'path':acr.request.path, 'num':random.randint(1, 10)})
updated = acr.depot.update('depot_test', created.object_id, {'num':created.data['num']+1})
after_update = acr.depot.get('depot_test', updated.object_id)
acr.depot.delete('depot_test', after_update.object_id)

Lookup Data

The Depot provides the lookup method to search data not by object_id. A call to lookup will return a ResultSet which provides the first(), all() and count() methods. ResultSet objects are also iterable.

Lookup function is defined as lookup(collection_name, filters) where filters is a dictionary of data which the entries will be looked for.

EXAMPLE:

for i in range(100):
    acr.depot.create('depot_test', {'num':random.randint(1, 10), 'time':time.time()})

first_entry_with_four = acr.depot.lookup('depot_test', {'num':'4'}).first()
print first_entry_with_four.data['time']

for entry in acr.depot.lookup('depot_test', {'num':'8'}):
    print entry.object_id, entry.data['time']