Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

SqlAlchemy extension for noseapp lib

Project Description
pip install noseapp_alchemy

Install extension from app

config module

from noseapp.ext.alchemy.mysql_ex import make_config

MY_DB = make_config()

MY_DB.configure(
    host='127.0.0.1',
    port=3306,
    user='root',
    password='',
    db='target',
    protocol='mysql',
    # pool_size=POOL_SIZE,
    # pool_class=POOL_CLASS,
    # strategy=ENGINE_STRATEGY,
    # max_overflow=MAX_OVERFLOW,
    # bind_key=DB_BIND_KEY,
)

ALCHEMY_EX_MYSQL = (
    MY_DB,
)

ALCHEMY_EX_SESSION = {}

etc...

app module

from noseapp import NoseApp
from noseapp.ext.alchemy import MySQLEx


class MyApp(NoseApp):

    def initialize(self):
        MySQLEx.install(self)

suite

from noseapp import Suite
from noseapp import TestCase


suite = Suite(__name__, require=['mysql'])


class MyTestCase(TestCase):

    def setUp(self):
        self.db = self.mysql.get_client()
        # get by bind key
        self.db = self.mysql.get_client('bind key')

    def test(self):
        with self.db.read() as execute:
            result = execute('SELECT 1').fetchone()
        self.assertTrue(result)

Usage ORM

from sqlalchemy import Column
from sqlalchemy import String
from sqlalchemy import Integer

from noseapp.ext.alchemy.orm import BaseModel


class MyModel(BaseModel):
    class Meta:
        # bind = 'bind key from db settings'
        table = 'table name'

id = Column(Integer, autoincrement=True, nullable=False, primary_key=True)
name = Column(String(255), nullable=False, default='Name')

Create new object

obj = MyModel.create(name='Hello World!')

Update object

obj = MyModel.objects.get(1)
obj.update(name='Hello!')

Get objects by

objects = MyModel.objects.getlist_by(name='Hello')
obj = MyModel.objects.get_by(name='Hello')

Etc…See orm module…

Release History

Release History

This version
History Node

1.0.0

Download Files

Download Files

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

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
noseapp_alchemy-1.0.0.tar.gz (4.3 kB) Copy SHA256 Checksum SHA256 Source Apr 16, 2015

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting