{ "info": { "author": "James Arthur", "author_email": "username: thruflo, domain: gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Environment :: Web Environment", "Framework :: Pylons", "Intended Audience :: Developers", "License :: Public Domain", "Natural Language :: English", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 2.6", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.2", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: WSGI", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Good frameworks, like [Pyramid][] and [Angular][], help developers write\ntestable code. [SQLAlchemy][] is a great framework. However, the sheer\nconvenience of having model instances returned from a database query\nencourages developers to write large ORM classes which can be hard to test.\n\nOne way to avoid this is to keep model classes [thin][] and write separate code\nto instantiate and manipulate them. The downside of this approach is the loss in\nconvenience: the separated, easily testable code isn't provided by default as\nan attribute of the model instances returned from a database query.\n\n[pyramid_alchemy][] provides an `add_model_method` Pyramid\n[configuration directive]() that extends [SQLAlchemy ORM][] classes in the same\nway that `add_request_method` [extends the Pyramid Request][]. Using this\ndirective allows developers to write easily testable code that is conveniently\navailable as a model instance attribute. For example, if you [include][] this\nin your Pyramid application:\n\n```python\nfrom .model import Spam\n\ndef get_eggs(instance, source='hens', limit=9, offset=0):\n \"\"\"Example ORM instance method, implemented as a standalone function.\"\"\"\n \n query = instance.query.filter_by(source=source)\n return query.offset(offset).limit(limit)\n\ndef includeme(config):\n config.add_model_method(Spam, get_eggs, 'get_eggs')\n```\n\nYou can then use the `get_eggs` method from `Spam` instances:\n\n```python\nspam = Session.query(Spam).get(1)\neggs = spam.get_eggs()\n```\n\n### Interfaces\n\nJust as you can hang a Pyramid view off any context object implementing a\nspecific interface, you can extend any model instance implementing an interface.\nFor example, if your model looked something like this:\n\n```python\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom zope.interfaces import implementer\n\nfrom .interfaces import IFilling\n\nBase = declarative_base()\n\n@implementer(IFilling)\nclass Ham(Base):\n # ...\n\n@implementer(IFilling)\nclass Spam(Base):\n # ...\n```\n\nThen you could extend all fillings -- current and future -- with:\n\n```python\nconfig.add_model_method(IFilling, get_eggs, 'get_eggs')\n```\n\n### Limitations\n\nNote that it's highly unlikely to be a good idea to use `add_model_method` to\nadd dynamic or hybrid methods that affect the underlying sql table or mapping.\n\n[Pyramid]: http://docs.pylonsproject.org/projects/pyramid/en/latest\n[Angular]: http://angularjs.org\n[SQLAlchemy]: http://docs.sqlalchemy.org/en/latest\n[pyramid_alchemy]: https://github.com/thruflo/pyramid_alchemy\n[configuration directive]: http://docs.pylonsproject.org/projects/pyramid/en/latest/narr/extconfig.html\n[SQLAlchemy ORM]: http://docs.sqlalchemy.org/en/latest/orm\n[extends the Pyramid Request]: http://docs.pylonsproject.org/projects/pyramid/en/latest/api/config.html#pyramid.config.Configurator.add_request_method\n[include]: http://docs.pylonsproject.org/projects/pyramid/en/latest/api/config.html#pyramid.config.Configurator.include\n[thin]: http://blog.codeclimate.com/blog/2012/10/17/7-ways-to-decompose-fat-activerecord-models/", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "http://github.com/thruflo/pyramid_alchemy", "keywords": null, "license": "This is free and unencumbered software released into the public domain.", "maintainer": null, "maintainer_email": null, "name": "pyramid_alchemy", "package_url": "https://pypi.org/project/pyramid_alchemy/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/pyramid_alchemy/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/thruflo/pyramid_alchemy" }, "release_url": "https://pypi.org/project/pyramid_alchemy/0.0.1/", "requires_dist": null, "requires_python": null, "summary": "Pyramid framework integration to extend SQLAlchemy ORM classes with separate, easily testable, code.", "version": "0.0.1" }, "last_serial": 1036157, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "1c3416e4aa3f2fc9dc46a8d96dde234b", "sha256": "6806b9090af3dca6aa06e843b86ba684e419d2d752178215bb28bb0527d794ca" }, "downloads": -1, "filename": "pyramid_alchemy-0.0.1.tar.gz", "has_sig": false, "md5_digest": "1c3416e4aa3f2fc9dc46a8d96dde234b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3961, "upload_time": "2014-03-20T14:49:10", "url": "https://files.pythonhosted.org/packages/e0/8c/73d4653d611a6ec93e20e1ab35fff340fd24c63cf5ba79e12f4ee4b07cb7/pyramid_alchemy-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "1c3416e4aa3f2fc9dc46a8d96dde234b", "sha256": "6806b9090af3dca6aa06e843b86ba684e419d2d752178215bb28bb0527d794ca" }, "downloads": -1, "filename": "pyramid_alchemy-0.0.1.tar.gz", "has_sig": false, "md5_digest": "1c3416e4aa3f2fc9dc46a8d96dde234b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3961, "upload_time": "2014-03-20T14:49:10", "url": "https://files.pythonhosted.org/packages/e0/8c/73d4653d611a6ec93e20e1ab35fff340fd24c63cf5ba79e12f4ee4b07cb7/pyramid_alchemy-0.0.1.tar.gz" } ] }