Skip to main content

SQLAlchemy support for cherrypy.

Project description

sqlalchemy support for cherrypy.

Installation

pip install marbaloo_sqlalchemy

Usage

# app.py
import marbaloo_sqlalchemy
import cherrypy
import os
from your_models import messages_model
marbaloo_sqlalchemy.Plugin(cherrypy.engine).subscribe()
cherrypy.tools.db = marbaloo_sqlalchemy.Tool()


class Root(object):

    @cherrypy.expose
    def index(self):
        db_session1 = cherrypy.request.db['db1']
        db_session2 = cherrypy.request.db['db2']

        query = messages_model.insert().values(message='TESTMessage')
        db_session1.get_bind().execute(query)
        db_session1.commit()

        query = messages_model.insert().values(message='TESTMessage')
        db_session2.get_bind().execute(query)
        db_session2.commit()

config = {
    'global': {
        'marbaloo_sqlalchemy_db': {
            'db1': {
                'engine': {
                    'name_or_url': 'sqlite:///test1.db',
                    'echo': True,
                },
                'session': {
                    'expire_on_commit': True,
                    'autoflush': True,
                    'autocommit': False
                }
            },
            'db2': {
                'engine': {
                    'name_or_url': 'sqlite:///test2.db',
                    'echo': True,
                },
                'session': {
                    'expire_on_commit': True,
                    'autoflush': True,
                    'autocommit': False
                }
            },
        }
    },
    '/': {
        'tools.db.on': True
    }
}
cherrypy.quickstart(Root(), '/', config)

Project details


Release history Release notifications

Download files

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

Filename, size & hash SHA256 hash help File type Python version Upload date
marbaloo_sqlalchemy-0.1.0.tar.gz (3.0 kB) Copy SHA256 hash SHA256 Source None Feb 16, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page