Backends

class modularodm.storage.base.Storage[source]

Abstract base class for storage objects. Subclasses (e.g. PickleStorage, MongoStorage, etc.) must define insert, update, get, remove, flush, and find_all methods.

translator = <modularodm.translators.DefaultTranslator object>
logger = <modularodm.storage.base.Logger object>
insert(this, *args, **kwargs)[source]

Insert a new record.

Parameters:
  • primary_name (str) – Name of primary key
  • key – The value of the primary key
  • value (dict) – The dictionary of attribute:value pairs
update(this, *args, **kwargs)[source]

Update multiple records with new data.

Parameters:
  • query – A query object.
  • data (dict) – Dictionary of key:value pairs.
get(this, *args, **kwargs)[source]

Get a single record.

Parameters:
  • primary_name (str) – The name of the primary key.
  • key – The value of the primary key.
remove(this, *args, **kwargs)[source]

Remove records.

flush(this, *args, **kwargs)[source]

Flush the database.

find_one(this, *args, **kwargs)[source]

Gets a single object from the collection.

If no matching documents are found, raises NoResultsFound. If >1 matching documents are found, raises MultipleResultsFound.

Params:One or more Query or QuerySet objects may be passed
Returns:The selected document
find(this, *args, **kwargs)[source]

Return a generator of query results. Takes optional by_pk keyword argument; if true, return keys rather than values.

Parameters:query
Returns:a generator of StoredObject instances

Ephemeral

class modularodm.storage.ephemeralstorage.EphemeralStorage(*args, **kwargs)[source]

Mongo

class modularodm.storage.mongostorage.MongoStorage(db, collection)[source]

Wrap a MongoDB collection. Note: store is a property instead of an attribute to handle passing db as a proxy.

Parameters:
  • db (Database) –
  • collection (str) –

Pickle

class modularodm.storage.picklestorage.PickleStorage(collection_name, prefix='db_', ext='pkl')[source]

Storage backend using pickle.

Build pickle file name and load data if exists.

Parameters:
  • collection_name – Collection name
  • prefix – File prefix.
  • ext – File extension.