Connectors¶
The connector libraries contain connectivity classes used by our framework and support functions to ease some common operations.
Cassandra¶
Our mapper to use cassandra is described in 9. NoSQL modeling
SQLAlchemy¶
Some basic functionality is included for the object relational mapper we use.
connectors.rdbms_model.base, connectors.rdbms_model.core¶
When designing models, as explained in 8. Relational modeling we usually make sure our models extend from
both connectors.rdbms_model.base.Base and connectors.rdbms_model.core.BaseModelMixin.
The Base class is a normal declarative base, documented in the SQLAlchemy docs
http://docs.sqlalchemy.org/en/latest/orm/extensions/declarative/api.html .
Our BaseModelMixin includes some basic extensions such as load_object_defaults() to set the
default to our model before flushing to the database and convert_to_dict() to return the model
as a dictionary.
connectors.rdbms_model.objects¶
In same cases we do want to use (materialized) views, which can be created using the create_view()
and create_materialized_view() functions defined in connectors.rdbms_model.objects.
Our implementation is heavily inspired by the following example http://www.jeffwidman.com/blog/847/using-sqlalchemy-to-create-and-manage-postgresql-materialized-views/
where both functions accept a name, select() and a schema .
The resulting model class should look similar to the following:
1from sqlalchemy import literal, select
2from valuea_framework.connectors.rdbms_model.base import Base
3from valuea_framework.connectors.rdbms_model.objects import create_view
4
5my_view = create_view('my_view', select([literal(1).label('id')]), 'public')
6
7
8class MyView(Base):
9 __table__ = my_view
10
11 __mapper_args__ = {
12 'primary_key': [my_view.c.id]
13 }
14
Which imports the requirements, creates the view and maps it to a model for usage in other components. (these should react similar to regular models)
connectors.rdbms_model.tools¶
The tools library contains some practical functions to help refresh your materialized views (if refresh order doesn’t matter),
using refresh_all_materialized_views and some help to optimize your database schema with vacuum_analyse.
RabbitMQ¶
Our main messaging system, extensively documented in our examples, to listen for incoming commands (and act as a consumer)
the best starting point is 1. “Hello world!” Service. This chapter also explains how to send a message to the queue using
the SimpleRpcClient.