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.


>>> 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")
>>> new_thingy = load(db, "the_id")
>>> print
>>> env.destroy("objectstorage_test")

API, db, id=None, rev=None, prefix=None)[source]

Stores obj into db.

  • 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 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-‘.

obj – the same object as the parameter on which 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.

  • 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.

the earlier stored object.

Table Of Contents

Previous topic

The pouchdb package

Next topic

The pouchdb.mapping module

This Page