Welcome to Modular-ODM’s documentation!¶
Contents:
Basic Usage¶
<todo>
Query Syntax¶
Operators¶
Equality¶
Keyword | Operator | Description |
---|---|---|
eq | equal to | |
ne | not equal to |
Comparison¶
Keyword | Operator | Description |
---|---|---|
gt | greater than | |
gte | greater than or equal to | |
lt | less than | |
lte | less than or equal to |
Membership¶
Keyword | Operator | Description |
---|---|---|
in | in | |
nin | not in |
String Comparison¶
Keyword | Operator | Description |
---|---|---|
startswith | starts with | |
endswith | ends with | |
contains | contains | |
icontains | contains (case insensitive) |
StoredObject¶
-
class
modularodm.storedobject.
StoredObject
(**kwargs)[source]¶ Base class to be used for models.
-
get_changed_fields
(cached_data, storage_data)[source]¶ Get fields that differ between the cache_sandbox and the current object. Validation and after_save methods should only be run on diffed fields.
Parameters: - cached_data – Storage-formatted data from cache_sandbox
- storage_data – Storage-formatted data from object
Returns: List of diffed fields
-
classmethod
migrate
(old, new, verbose=True, dry_run=False, rm_refs=True)[source]¶ Migrate record to new schema.
Parameters: - old – Record from original schema
- new – Record from new schema
- verbose – Print detailed info
- dry_run – Dry run; make no changes if true
- rm_refs – Remove references on deleted fields
-
save
(*args, **kwargs)[source]¶ Save a record.
Parameters: force (bool) – Save even if no fields have changed; used to update back-references Returns: List of changed fields
-
update_fields
(**kwargs)[source]¶ Update multiple fields, specified by keyword arguments.
Example:
person.update(given_name='Fred', family_name='Mercury')
... is equivalent to ...
person.given_name = 'Fred' person.family_name = 'Mercury'
Parameters: **kwargs – field names and the values to set
-
classmethod
find
(*args, **kwargs)[source]¶ Parameters: - query –
- kwargs –
Returns: an iterable of
StoredObject
instances
-
classmethod
delegate
(method, conflict=None, *args, **kwargs)[source]¶ Execute or queue a database action. Variable positional and keyword arguments are passed to the provided method.
Parameters: - method (function) – Method to execute or queue
- conflict (bool) – Potential conflict between cache_sandbox and backend, e.g., in the event of bulk updates or removes that bypass the cache_sandbox
-
classmethod
start_queue
()[source]¶ Start the queue. Between calling
start_queue
andcommit_queue
, all writes will be deferred to the queue.
-
classmethod
cancel_queue
()[source]¶ Cancel any pending actions. This method clears the queue and also clears caches if any actions are pending.
-
classmethod
commit_queue
()[source]¶ Commit all queued actions. If any actions fail, clear caches. Note: the queue will be cleared whether an error is raised or not.
-
classmethod
subscribe
(signal_name, weak=True)[source]¶ Parameters: Returns: Decorator created by
Signal::connect_via
Raises: ValueError if signal is not found
Example usage:
>>> @Schema.subscribe('before_save') ... def listener(cls, instance): ... instance.value += 1
-
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>¶
-
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.
-
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, raisesMultipleResultsFound
.Params: One or more Query
orQuerySet
objects may be passedReturns: 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
-