Skip to main content

Database Cluster Session Manager

Project description

dbcluster: Database Cluster Session Manager

Kris Hardy kris@abqsoft.com

NOTE: This code is in early beta and is under active development. Please use carefully until the code stabalizes into version 1.0 (target: May 2019)

This database engine manager manages master/slave database connections and session management. This is useful for applications which need to manage sqlalchemy database engines and sessionmakers for master/slave database clusters.

Example usage:

import sqlalchemy
from dbcluster import MasterSlaveManager
manager = MasterSlaveManager()

# Set up the master(s)
manager.append_master(
    sqlalchemy.create_engine('postgresql://127.0.0.1:5432'),
    orm=MasterSlaveManager.ORM_SQLALCHEMY
)

# Set up slaves
manager.append_slave(
    sqlalchemy.create_engine('postgresql://127.0.0.1:5433'),
    orm=MasterSlaveManager.ORM_SQLALCHEMY
)

manager.append_slave(
    sqlalchemy.create_engine('postgresql://127.0.0.1:5435'),
    orm=MasterSlaveManager.ORM_SQLALCHEMY
)

# Use the database sessions
with manager.master_session_ctx() as db_session:
    # Do something with the session ...
    db_session.commit()

with manager.slave_session_ctx() as db_session:
    # Returns a random slave session
    # Do something with the session ...
    db_session.commit()

with manager.slave_session_ctx(0) as db_session:
    # Returns a session to the first slave
    # Do something with the session ...
    db_session.commit()

Project details


Release history Release notifications | RSS feed

This version

0.1

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dbcluster-0.1.tar.gz (3.3 kB view hashes)

Uploaded Source

Built Distribution

dbcluster-0.1-py2-none-any.whl (5.7 kB view hashes)

Uploaded Python 2

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page