passerine.db.entity

Note

This page is automatically generated. If you don’t see anything, this means this sub-module is not meant to be used. If you really want to know what it is, please check out the source code at passerine/db/entity.py.

Author:Juti Noppornpitak <jnopporn@shiroyuki.com>
class passerine.db.entity.BasicAssociation(origin, destination)

Basic Association

Parameters:
  • origin (object) – The origin of the association
  • destination (object) – The destination (endpoint) of the association

Note

This class is used automatically by the association mapper.

class passerine.db.entity.Entity(**attributes)

Dynamic-attribute Basic Entity

Parameters:attributes (dict) – key-value dictionary

Here is an example on how to use this class.

@entity
class Note(Entity): pass
class passerine.db.entity.Index(field_map, unique=False)
Parameters:
  • field_map (dict) – the map of field to index type
  • unique (bool) – the unique flag

Unless a field is not in the map of fixed orders, the index will instruct the repository to ensure all combinations of indexes are defined whenever is necessary.

passerine.db.entity.entity(*args, **kwargs)

Entity decorator

Parameters:collection_name (str) – the name of the collection
Returns:the decorated object
Return type:object
passerine.db.entity.prepare_entity_class(cls, collection_name=None, indexes=[])

Create a entity class

Parameters:
  • cls (object) – the document class
  • collection_name (str) – the name of the corresponding collection where the default is the lowercase version of the name of the given class (cls)

The object decorated with this decorator will be automatically provided with a few additional attributes.

Attribute Access Description Read Write
id Instance Document Identifier Yes Yes, ONLY id is undefined.
__t3_orm_meta__ Static Tori 3’s Metadata Yes ONLY the property of the metadata
__session__ Instance DB Session Yes Yes, but NOT recommended.

The following attributes might stay around but are deprecated as soon as the stable Tori 3.0 is released.

Attribute Access Description Read Write
__collection_name__ Static Collection Name Yes Yes, but NOT recommended.
__relational_map__ Static Relational Map Yes Yes, but NOT recommended.
__indexes__ Static Indexing List Yes Yes, but NOT recommended.

__session__ is used to resolve the managing rights in case of using multiple sessions simutaneously.

For example,

@entity
class Note(object):
    def __init__(self, content, title=''):
        self.content = content
        self.title   = title

where the collection name is automatically defined as “note”.

Changed in version 3.0: The way Tori stores metadata objects in __collection_name__, __relational_map__ and __indexes__ are now ignored by the ORM in favour of __t3_orm_meta__ which is an entity metadata object.

This change is made to allow easier future development.

Tip

You can define it as “notes” by replacing @entity with @entity('notes').