Tori Framework supports both relational databases via SQLAlchemy and MongoDB databases via PyMongo. Please note that any modules related to relational databases are experimental and not supported by the project.
Warning
This is experimental. Those with heart condition must not use these APIs.
Author: | Juti Noppornpitak <jnopporn@shiroyuki.com> |
---|---|
Status: | Stable |
The module provides a simple wrapper to work with MongoDB and Tori ORM.
Collection (Entity Repository) for Mongo DB
Parameters: |
|
---|
Author: | Juti Noppornpitak <jnopporn@shiroyuki.com> |
---|---|
Stability: | Stable |
Simply GUID Generator
Generate the GUID
Returns: | Global unique identifier within the scope of the generator |
---|---|
Return type: | str |
Hash-type GUID Generator
Author: | Juti Noppornpitak <jnopporn@shiroyuki.com> |
---|---|
Stability: | Stable |
This module contains the abstract of documents in MongoDB.
Dynamic-attribute Base Document
Parameters: | attributes (dict) – key-value dictionary |
---|
Here is the example on how to use this class.
@document
class Note(BaseDocument): pass
In this case, it is similar to the example for document() except that the class Node no longer guarantees that it will have attributes title, content and author but it maps all available data to the object.
In case that a document class needs to have certain attributes and unknown dynamic attributes the Note class should look like this.
@document
class Note(BaseDocument):
def __init__(self, title, author, content, **attributes):
BaseDocument.__init__(self, **attributes)
self.title = title
self.author = author
self.content = content
Document decorator
Parameters: | collection_name (str) – the name of the collection |
---|---|
Returns: | the decorated object |
Return type: | str |
Create a document-type class
Parameters: | cls (object) – the document class |
---|
The object decorated with this decorator will be provided with the following read-only attribute
Attribute | Description |
---|---|
id | Document Identifier |
and methods
Method | Description |
---|---|
get_collection_name | Get the default name of the collection |
get_class_name | Get the default name of the class |
get_changeset | Get the computed changeset |
is_dirty | Check if a certain attribute is dirty (changed or added) |
reset_bits | Reset the computed changeset |
to_dict | Convert the data into dictionary (experimental) |
Note
Internally, the attribute _id of the decorated object holds the object identifier (ID). Although it is writeable and accessible publicly, it is strongly discouraged from accessing the property directly AFTER the instantiation.
Here is an example.
@document
class Note(object):
def __init__(self, title, author, content, _id=None):
self.title = title
self.author = author
self.content = content
self._id = _id
From the example, you will notice that this is all it take to make it work with tori.db.collection.Collection.
You will also see that this example tell the constructor to set _id. This is just to work with the collection API.
Author: | Juti Noppornpitak |
---|
Relational Database Entity
This module just provides tori.db.entity.Entity as a result of the factory method sqlalchemy.ext.declarative.declarative_base().
Exception thrown when the property is already mapped.
Exception thrown when the ID is tempted to change.
Exception thrown when a reserved attribute is tempted to change.
Exception thrown when the collection is not available.
Author: | Juti Noppornpitak |
---|
Foundation of the council
Note
this must be used at most once.
Warning
this class is not tested.
Define the fixtures.
Parameters: |
|
---|
fixture = Fixture()
fixture.set(
'council.security.model.Provider',
{
'ldap': { 'name': 'ldap' }
}
)
fixture.set(
'council.user.model.User', {
'admin': { 'name': 'Juti Noppornpitak' }
}
)
fixture.set(
'council.security.model.Credential',
{
'shiroyuki': {
'login': 'admin',
'user': 'proxy/council.user.model.User/admin',
'provider': 'proxy/council.security.model.Provider/ldap'
}
}
)
Entity Repository for Relational Database
Author: | Juti Noppornpitak |
---|
The default relational database service for Tori framework compatible with SQLAlchemy.
Relational Database Service
This is based on based on SQLAlchemy 0.7.
This service provides basic functionality to interact a relational database. It also heavily uses lazy loading for the sake of faster startup and resource efficiency.
Parameters: |
|
---|
Get the SQLAlchemy engine.
Return type: | sqlalchemy.engine.base.Engine |
---|
Note
With the service, it is not recommended to directly use this method.
Get an entity of type entity_type.
Parameters: |
|
---|
Get all entities of type entity_type.
Parameters: | entity_type – the class reference of the entities being searched |
---|
Insert new entities into the database.
Parameters: | entities – a list of new entities. |
---|
Retrieve the query object for the given type of entities.
Parameters: | entity_type (list) – the type of entity |
---|---|
Return type: | sqlalchemy.orm.query.Query |
Returns: | The query object for the given type of entities. |
Create the table if necessary.
Return type: | True if the reflection is made. |
---|
Get a SQLAlchemy session for the current connection.
Return type: | sqlalchemy.orm.session.Session |
---|---|
Returns: | a session for the connection. |
Get the connecting URL.
Returns: | the URL |
---|---|
Return type: | string|unicode |
Abstract Database Service
This service is served as an abstract of any