The pouchdb.objectstorage module

The objectstorage module allows you to save ordinary Python objects directly into PouchDB. The (de)serializing is handled by the jsonpickle module.

Example

>>> from pouchdb.objectstorage import load, store
>>> from jsonpickle._samples import Thing
>>> 
>>> env = setup()
>>> db = env.PouchDB("objectstorage_test")
>>> thingy = Thing("abc")
>>> 
>>> store(thingy, db, "the_id")
Thing("abc")
>>> new_thingy = load(db, "the_id")
>>> print new_thingy.name
abc
>>> 
>>> env.destroy("objectstorage_test")

API

pouchdb.objectstorage.store(obj, db, id=None, rev=None, prefix=None)[source]

Stores obj into db.

Parameters:
  • obj – Any Python object that jsonpickle can handle. (i.e. most objects.)
  • db (pouchdb.SyncPouchDB) – A database as returned by pouchdb.setup().PouchDB(db_name). This can’t be a database as generated by the asynchronous API.
  • id (str) – Used as the _id field in PouchDB. If this is None and obj.id exists, that is used. The fallback is a UUID.
  • rev (str) – Used as the _rev field in PouchDB. If this is None and obj.rev exists, that is used. Otherwise a new document is assumed (with no _rev yet).
  • prefix (str) – a serialization as returned by jsonpickle can have a field starting with ‘_’ in a dictionary. That clashes with PouchDB, which can’t. To work around that, every key is prefixed with this argument if the situation occurs. When no prefix is specified it’ll be: ‘python-pouchdb-‘.
Returns:

obj – the same object as the parameter on which obj.id and obj.rev will have been set.

pouchdb.objectstorage.load(db, id, rev=None, prefix=None)[source]

Loads an earlier under id stored object from db.

Parameters:
  • id (str) – The _id to look for in the database.
  • rev (str) – The _rev to look for in the database. When not specified the latest revision is used.
  • prefix (str) – see store()‘s parameter with the same name. Should equal the one used to store the object, otherwise the result is undefined.
Returns:

the earlier stored object.

Table Of Contents

Previous topic

The pouchdb package

Next topic

The pouchdb.mapping module

This Page