{ "info": { "author": "UNKNOWN", "author_email": "UNKNOWN", "bugtrack_url": null, "classifiers": [], "description": "SQLAlchemyManager\n+++++++++++++++++\n\n.. contents ::\n\nSummary\n=======\n\n* Provides a sensible way of using SQLAlchemy in WSGI applications\n\nGet Started\n===========\n\n* Download from the `SQLAlchemyManager Cheeseshop page `_\n* Install with ``easy_install SQLAlchemyManager``.\n\nIntroduction\n=============\n\nSQLAlchemy has two problems:\n\n* It is very powerful and so can be used in many different ways but\n understanding the different options can be difficult.\n\n* To try to make SQLAlchemy simpler in Pylons, objects like scoped_session, g,\n MetaData etc are used, these further abstract the user from what is going on\n and make SQLAlchemy appear even more inpenetrable when you do try to get to\n grips with it\n\nThis middleware sets up the *standard* SQLAlchemy objects in a piece of WSGI\nmiddleware without doing anything particularly clever and without using any\nglobal objects.\n\nAs well as making things slightly simpler in frameworks such as Pylons, the\nsetup recommended in this module also provides an API for other applications\nsuch as AuthKit (which can use their own SQLAlchemy objects) to be setup at the\nsame time as the application's SQLAlchemy objects in the same model. This in\nturn begins to allow developers to componentise certain parts of their code\neven if they rely on a database.\n\n.. caution :: \n\n This package is currently *not* the recommended way of using SQLAlchemy in \n a WSGI environment and is merely the first step towards thinking about how\n best to do it.\n\nTutorial\n========\n\nHere's how SQLAlchemyManager is used in a Pylons application.\n\nIn your ``config/middleware.py`` file at the top::\n\n from yourproject.model import setup_model\n from sqlalchemymanager import SQLAlchemyManager\n\nThen, right after the line where you set up \n``PylonsApp``::\n \n app = SQLAlchemyManager(app, app_conf, [setup_model])\n\nYour ``model/__init__.py`` file then looks like this::\n\n from sqlalchemy import Column, Table, types\n from sqlalchemy.orm import mapper, relation\n\n def setup_model(model, metadata, **p):\n model.table1 = Table(\"table1\", metadata,\n Column(\"id\", types.Integer, primary_key=True),\n Column(\"name\", types.String, nullable=False),\n )\n class MyClass(object):\n pass\n model.MyClass = MyClass\n model.table1_mapper = mapper(model.MyClass, model.table1)\n\nThis means you can write code like this::\n\n from sqlalchemy.sql import select\n\n def app(environ, start_response):\n # The model is the same across requests so is safe to save as a global\n # somewhere in your application.\n model = environ['sqlalchemy.model']\n # You will get a new session object on each request so you shouldn't save it\n session = environ['sqlalchemy.session']\n\n # Use the SQLExpression API via the session object\n select_statement = select([model.table1])\n select_result = [row for row in session.execute(select_statement)]\n \n # Or use the ORM API\n mr_jones = model.MyClass()\n mr_jones.name = 'Mr Jones'\n session.save(mr_jones)\n session.commit()\n multiple_mr_jones = session.query(model.MyClass).filter(model.MyClass.name=='Mr Jones').all()\n \n # Return the data\n start_response('200 OK', [('Content-Type', 'text/plain')])\n return [\n '''\n Select Result: \n %s\n \n Mr Jones Results:\n %s \n '''%(\n select_result,\n ', '.join([person.name for person in multiple_mr_jones])\n )\n ]\n\nNotice that we are using both the ORM and SQL Expression features of SQLAlchemy\nand that options such as connection pooling will still work perfectly well.\nAlso, existing SQLAlchemy setups shouldn't need much modification to work with\nthis middleware. Simply wrapping their model definitions in a function and\nensuring that all the SQLAlchemy objects are assigned to ``model`` explicitly\nshould be enough.\n\nThat's the basics. If you want to create the tables there are a number of ways:\n\nYou can create the required tables during a request like this::\n\n # Create the tables\n environ['sqlalchemy.manager'].create_all()\n\nOr if you are using a script you can do this::\n\n from yourproject.model import setup_model\n from sqlalchemymanager import SQLAlchemyManager\n\nThen, right after the line where you set up \n``PylonsApp``::\n \n manager = SQLAlchemyManager(None, app_conf, [setup_model])\n manager.create_all()\n\nTo do any manipulation you'll need to create your own session::\n\n connection = manager.engine.connect()\n session = manager.session_maker(bind=connection)\n try:\n # Do stuff here\n pass\n finally:\n session.close()\n connection.close()\n\n\nChanges\n=======\n\n0.1.0\n\n* First version\n\n\nLicense\n=======\nMIT License\n\nCopyright (c) 2007 James Gardner\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE.\n\n\nDownload\n========", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "UNKNOWN", "keywords": "", "license": "UNKNOWN", "maintainer": null, "maintainer_email": null, "name": "SQLAlchemyManager", "package_url": "https://pypi.org/project/SQLAlchemyManager/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/SQLAlchemyManager/", "project_urls": { "Download": "UNKNOWN", "Homepage": "UNKNOWN" }, "release_url": "https://pypi.org/project/SQLAlchemyManager/0.1.0/", "requires_dist": null, "requires_python": null, "summary": "Provides a sensible way of using SQLAlchemy in WSGI applications", "version": "0.1.0" }, "last_serial": 785583, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "eb20b13c3ae59f2047dc31d4eb64b5ad", "sha256": "f9c399e9c01be8cb79471c19d4de144f8b733ea9d43714d96bdf6bb95a02fef8" }, "downloads": -1, "filename": "SQLAlchemyManager-0.1.0-py2.4.egg", "has_sig": false, "md5_digest": "eb20b13c3ae59f2047dc31d4eb64b5ad", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 8398, "upload_time": "2007-11-08T12:34:34", "url": "https://files.pythonhosted.org/packages/7e/ca/c3960283ae7f978a5ef07f481478bc8cf2f4272c03cc2ff125215b629258/SQLAlchemyManager-0.1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "068b29d8e4ef97839d96a4945df4fcf9", "sha256": "3d84f4c64fc70a4033f6b348d6842ce9a20de9f6b22b1504f64f8abfde9a2f5b" }, "downloads": -1, "filename": "SQLAlchemyManager-0.1.0.tar.gz", "has_sig": false, "md5_digest": "068b29d8e4ef97839d96a4945df4fcf9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9236, "upload_time": "2008-03-14T12:45:55", "url": "https://files.pythonhosted.org/packages/47/36/bbbc4a78c3f6057ea62139977fccaf1e0a2a12affead63e2221d75745ea1/SQLAlchemyManager-0.1.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "eb20b13c3ae59f2047dc31d4eb64b5ad", "sha256": "f9c399e9c01be8cb79471c19d4de144f8b733ea9d43714d96bdf6bb95a02fef8" }, "downloads": -1, "filename": "SQLAlchemyManager-0.1.0-py2.4.egg", "has_sig": false, "md5_digest": "eb20b13c3ae59f2047dc31d4eb64b5ad", "packagetype": "bdist_egg", "python_version": "2.4", "requires_python": null, "size": 8398, "upload_time": "2007-11-08T12:34:34", "url": "https://files.pythonhosted.org/packages/7e/ca/c3960283ae7f978a5ef07f481478bc8cf2f4272c03cc2ff125215b629258/SQLAlchemyManager-0.1.0-py2.4.egg" }, { "comment_text": "", "digests": { "md5": "068b29d8e4ef97839d96a4945df4fcf9", "sha256": "3d84f4c64fc70a4033f6b348d6842ce9a20de9f6b22b1504f64f8abfde9a2f5b" }, "downloads": -1, "filename": "SQLAlchemyManager-0.1.0.tar.gz", "has_sig": false, "md5_digest": "068b29d8e4ef97839d96a4945df4fcf9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9236, "upload_time": "2008-03-14T12:45:55", "url": "https://files.pythonhosted.org/packages/47/36/bbbc4a78c3f6057ea62139977fccaf1e0a2a12affead63e2221d75745ea1/SQLAlchemyManager-0.1.0.tar.gz" } ] }