{ "info": { "author": "Dushyant Rijhwani", "author_email": "dushyant.rijhwani@deliveryhero.com", "bugtrack_url": null, "classifiers": [], "description": "lymph-sqlalchemy\n================\n\nThis is a library is a basic wrapper around sqlalchemy that provides an easy\nway to write an interface, integrate logging and helps in testing.\n\nStore\n-----\n\nThe ``lymph.sqlalchemy.store.Store`` class is a basic wrapper around sqlalchemy,\nit configures the engine and gives an interface to sessions.\n\n\n.. code-block:: python\n\n from lymph.sqlalchemy.store import Store\n store = Store('postgresql://postgres/lymph-test-sqlalchemy')\n # Access the engine\n engine = store.engine\n engine.execute('SELECT 1')\n\n # The sessions are context managers\n with store.get_session() as session:\n session.add(user)\n\n\nYou can pass all of the engine args to the ``Store``, they would be passed on\nwhen creating the engine.\n\n\nDefining Models\n--------------\n\nThe recommended way of defining your models is by first creating an sqlalchemy declarative base class and then\ndefine your models like any normal sqlalchemy models:\n\n.. code-block:: python\n\n from sqlalchemy import Column, Integer, String\n from sqlalchemy.ext.declarative import declarative_base\n\n Base = declarative_base()\n\n class User(Base):\n __tablename__ = 'users'\n\n id = Column(Integer, primary_key=True)\n name = Column(String)\n\n\n**IMPORTANT**: Please put the ``Base`` class in the same python module as the models, else you may\nhave some import problems.\n\nInterface\n---------\n\nThe ``lymph.sqlalchemy.interface.StoreInterface`` class uses the the lymph config to\nconfigure a store instance.\n\nAn example config for a ``StoreInterface`` looks like this, it has a dependency\non store.\n\n.. code-block:: python\n\n import lymph\n from lymph.sqlalchemy.interface import StoreInterface\n\n class UserInterface(StoreInterface):\n\n @lymph.rpc()\n def create_user(self, data):\n user = User(**data)\n with self.store.get_session() as session:\n session.add(user)\n\n\n.. code-block:: yaml\n\n dependencies:\n store:\n class: lymph.sqlalchemy.store:Store\n uri: postgresql://postgres/users\n pool_size: 5\n max_overflow: 10\n pool_timeout: 30\n base: dhh.users.models:Base\n\n interfaces:\n restaurants:\n class: UserInterface\n store: dep:store\n\nTesting\n-------\n\nThe library provides a ``lymph.sqlalchemy.testing.StorageInterfaceTest`` to help\nyou write your unittests. You would extend this class by providing it your own\ndatabase config and your service interface.\n\nThe class would create the database on ``setupClass`` and it would create the\ntables and the models that you provided as fixtures in ``setUp`` method of the\ntest case.\n\nIn the ``teardown`` this class would drop all the tables.\n\n.. code-block:: python\n\n from lymph.sqlalchemy.testing import StorageInterfaceTest\n\n\n class UserInterfaceTest(StorageInterfaceTest):\n\n def get_fixtures(self):\n self.user = User(name='Test')\n self.user_2 = User(name='Test 2')\n return [self.user, self.user_2]\n\n def test_get_user(self):\n user = self.client.get(pk=self.user.id)\n user_2 = self.client.get(pk=self.user_2.id)\n self.assertEqual(user.id, self.user.id)\n self.assertEqual(user_2.id, self.user_2.id)\n\n\nCommand Line Interfaces\n-----------------------\n\nThis library provides a couple of cli to make the workflow easiers.\n\n\n``init-db`` command would create all the tables for all models that are defined\nusing the library's `Base`\n\n.. code-block:: bash\n\n $lymph init-db -c .yml\n\n\n.. code-block:: yaml\n\n dependencies:\n store:\n class: lymph.sqlalchemy.store:Store\n base: dhh.users.models:Base\n\n\n``sql-shell`` command would give you a shell with a `store` instance already\nconfigured.\n\n.. code-block:: bash\n\n $LYMPH_NODE_CONFIG=`pwd`/.lymph.yml lymph sql-shell -c .yml", "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/deliveryhero/lymph-sqlalchemy/", "keywords": null, "license": "Apache License (2.0)", "maintainer": null, "maintainer_email": null, "name": "lymph-sqlalchemy", "package_url": "https://pypi.org/project/lymph-sqlalchemy/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/lymph-sqlalchemy/", "project_urls": { "Download": "UNKNOWN", "Homepage": "http://github.com/deliveryhero/lymph-sqlalchemy/" }, "release_url": "https://pypi.org/project/lymph-sqlalchemy/0.7.0/", "requires_dist": null, "requires_python": null, "summary": "UNKNOWN", "version": "0.7.0" }, "last_serial": 1985448, "releases": { "0.6.0": [ { "comment_text": "", "digests": { "md5": "8df92b8b3c33e727848f230d579d571d", "sha256": "cdbc687c9aa7a36251e5095770b85f2bfd94f818fad8bc5f39f25cb9c1f99279" }, "downloads": -1, "filename": "lymph-sqlalchemy-0.6.0.tar.gz", "has_sig": false, "md5_digest": "8df92b8b3c33e727848f230d579d571d", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10007, "upload_time": "2016-02-25T09:44:02", "url": "https://files.pythonhosted.org/packages/03/e2/2df17596194dc3c305548cb46fc4516b95b553ad5e54e981f4c498ef1cdd/lymph-sqlalchemy-0.6.0.tar.gz" } ], "0.7.0": [ { "comment_text": "", "digests": { "md5": "8e8ca5083101b95f358f470124060783", "sha256": "14176ad73e01608d816f8f8213e57238df01f4016d0da426f5566ed182b737ef" }, "downloads": -1, "filename": "lymph-sqlalchemy-0.7.0.tar.gz", "has_sig": false, "md5_digest": "8e8ca5083101b95f358f470124060783", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10434, "upload_time": "2016-03-02T10:42:24", "url": "https://files.pythonhosted.org/packages/ac/0a/e49bb0001acdcb4aa5659268e7129ce5b150ee2b23a8dc7ec0e880623f99/lymph-sqlalchemy-0.7.0.tar.gz" } ], "0.7.0-dev": [ { "comment_text": "", "digests": { "md5": "5e40631a03ec40f17ddccab4f9beebf0", "sha256": "a0201de989a3193cec43fbf66b61ab81b1b7341de1bd49bfac9826b33a29c5b4" }, "downloads": -1, "filename": "lymph-sqlalchemy-0.7.0-dev.tar.gz", "has_sig": false, "md5_digest": "5e40631a03ec40f17ddccab4f9beebf0", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10021, "upload_time": "2016-02-25T09:43:38", "url": "https://files.pythonhosted.org/packages/9f/9f/722ed52bad77204c0168922830117b341b6dc816eb8f2dc34cc91f0df418/lymph-sqlalchemy-0.7.0-dev.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "8e8ca5083101b95f358f470124060783", "sha256": "14176ad73e01608d816f8f8213e57238df01f4016d0da426f5566ed182b737ef" }, "downloads": -1, "filename": "lymph-sqlalchemy-0.7.0.tar.gz", "has_sig": false, "md5_digest": "8e8ca5083101b95f358f470124060783", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10434, "upload_time": "2016-03-02T10:42:24", "url": "https://files.pythonhosted.org/packages/ac/0a/e49bb0001acdcb4aa5659268e7129ce5b150ee2b23a8dc7ec0e880623f99/lymph-sqlalchemy-0.7.0.tar.gz" } ] }