{ "info": { "author": "H.D. \"Chip\" McCullough IV", "author_email": "hdmccullough.work@gmail.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Topic :: Database", "Topic :: Database :: Database Engines/Servers", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "# alchemist-stack\n**Package Author**: H.D. 'Chip' McCullough IV\n\n**Last Updated**: April 23rd, 2018\n\n**Description**:\\\nA Flexible Model-Repository-Database stack for use with SQL Alchemy\n\n## Overview\nAlchemist Stack is intended to be a thread-safe, multi-session/multi-connection \n\n## Usage\n\nExample ORM Table:\n```python\n# table_example.py\n\nfrom alchemist_stack.repository.models import Base\nfrom sqlalchemy import Column, Integer, DateTime\n\nclass ExampleTable(Base):\n __tablename__ = 'example'\n\n primary_key = Column('id', Integer, primary_key=True)\n timestamp = Column(DateTime(timezone=True), nullable=False)\n\n def __repr__(self):\n return ''.format(timestamp=self.timestamp)\n```\n\nExample Model:\n```python\n# model_example.py\n\nfrom tables.table_example import ExampleTable\n\nfrom datetime import datetime, timezone\nfrom typing import TypeVar\n\nE = TypeVar('E', bound=\"Example\")\n\nclass Example(object):\n \"\"\"\n Example Model class.\n \"\"\"\n\n def __init__(self, timestamp: datetime = datetime.now(timezone.utc).astimezone(), primary_key: int = None,\n *args, **kwargs):\n self.__pk = primary_key\n self.__timestamp = timestamp\n self.__args = args\n self.__kwargs = kwargs\n\n def __call__(self, *args, **kwargs) -> ExampleTable:\n \"\"\"\n Called when an instance of Example is called, e.g.:\n `x = Example(...)`\n `x(...)`\n This is equivalent to calling `to_orm()` on the object instance.\n\n :returns: The ORM of the Example.\n :rtype: ExampleTable\n \"\"\"\n return self.to_orm()\n\n def __repr__(self) -> str:\n \"\"\"\n A detailed String representation of Example.\n\n :returns: String representation of Example object.\n \"\"\"\n return ''.format(pk=self.__pk,\n timestamp=self.__timestamp,\n hex_id=hex(id(self)))\n\n @property\n def id(self) -> int:\n return self.__pk\n\n @property\n def timestamp(self) -> datetime:\n return self.__timestamp\n\n def to_orm(self) -> ExampleTable:\n return ExampleTable(primary_key=self.__pk, timestamp=self.__timestamp)\n\n @classmethod\n def from_orm(cls, obj: ExampleTable) -> E:\n return cls(timestamp=obj.timestamp, primary_key=obj.primary_key)\n```\n\nExample Repository:\n```python\n# repository_example.py\n\nfrom alchemist_stack.context import Context\nfrom alchemist_stack.repository import RepositoryBase\nfrom models.model_example import Example\nfrom tables.table_example import ExampleTable\n\nclass ExampleRepository(RepositoryBase):\n \"\"\"\n\n \"\"\"\n\n def __init__(self, context: Context, *args, **kwargs):\n \"\"\"\n Test Repository Constructor\n :param database: The Database object containing the engine used to connect to the database.\n :param args: Additional Arguments\n :param kwargs: Additional Keyword Arguments\n \"\"\"\n super().__init__(context=context, *args, **kwargs)\n\n def __repr__(self):\n \"\"\"\n\n :return:\n \"\"\"\n return 'RepositoryBase(context={context}) at {hex_id}>'\\\n .format(context=str(self.context),\n hex_id=hex(id(self.context)))\n\n def create_example(self, obj: Example):\n self._create_object(obj=obj.to_orm())\n\n def get_example_by_id(self, example_id: int) -> Example:\n self._create_session()\n __query = self._read_object(cls=ExampleTable)\n __t = __query.with_session(self.session).get(example_id)\n self._close_session()\n if isinstance(__t, ExampleTable):\n return Example.from_orm(__t)\n\n def update_example_by_id(self, example_id: int, values: dict, synchronize_session: str = 'evaluate') -> int:\n self._create_session()\n __query = self._update_object(cls=ExampleTable, values=values)\n rowcount = __query.with_session(self.session)\\\n .filter(ExampleTable.primary_key == example_id)\\\n .update(values=values,\n synchronize_session=synchronize_session)\n self._commit_session()\n return rowcount\n```\n\n", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/mcculloh213/alchemist-stack", "keywords": "sqlalchemy databases", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "alchemist-stack", "package_url": "https://pypi.org/project/alchemist-stack/", "platform": "", "project_url": "https://pypi.org/project/alchemist-stack/", "project_urls": { "Documentation": "https://github.com/mcculloh213/alchemist-stack", "Homepage": "https://github.com/mcculloh213/alchemist-stack", "Issue Tracker": "https://github.com/mcculloh213/alchemist-stack/issues", "Source": "https://github.com/mcculloh213/alchemist-stack" }, "release_url": "https://pypi.org/project/alchemist-stack/0.1.0.dev1/", "requires_dist": [ "sqlalchemy" ], "requires_python": ">=3", "summary": "A Thread-Safe, Multi-Session/Multi-Connection Model-Repository-Context base for SQL Alchemy", "version": "0.1.0.dev1" }, "last_serial": 3804218, "releases": { "0.1.0.dev1": [ { "comment_text": "", "digests": { "md5": "50eea3d0a8b236319c6a3785e6ed60b8", "sha256": "74e4f6158d5f3d13e8cae499d5dc0989371103b039c8b102c204bf307e820951" }, "downloads": -1, "filename": "alchemist_stack-0.1.0.dev1-py3-none-any.whl", "has_sig": false, "md5_digest": "50eea3d0a8b236319c6a3785e6ed60b8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 13354, "upload_time": "2018-04-24T19:34:08", "url": "https://files.pythonhosted.org/packages/97/09/369627fa8d586ef2caa60cec4ecc548d9d3942f87c6dad8ac8ed289c2a49/alchemist_stack-0.1.0.dev1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d13ba3bf6718c8889a6ef5f8431db9a3", "sha256": "339c56e09d10fdcdf319e05c643ace288afbb3832be1977f7ae3041e1a14919e" }, "downloads": -1, "filename": "alchemist_stack-0.1.0.dev1.tar.gz", "has_sig": false, "md5_digest": "d13ba3bf6718c8889a6ef5f8431db9a3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 11213, "upload_time": "2018-04-24T19:34:09", "url": "https://files.pythonhosted.org/packages/24/87/51f54b231fddc935452d872b179b51fd303ef6708cbf61710e31a72f3835/alchemist_stack-0.1.0.dev1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "50eea3d0a8b236319c6a3785e6ed60b8", "sha256": "74e4f6158d5f3d13e8cae499d5dc0989371103b039c8b102c204bf307e820951" }, "downloads": -1, "filename": "alchemist_stack-0.1.0.dev1-py3-none-any.whl", "has_sig": false, "md5_digest": "50eea3d0a8b236319c6a3785e6ed60b8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3", "size": 13354, "upload_time": "2018-04-24T19:34:08", "url": "https://files.pythonhosted.org/packages/97/09/369627fa8d586ef2caa60cec4ecc548d9d3942f87c6dad8ac8ed289c2a49/alchemist_stack-0.1.0.dev1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "d13ba3bf6718c8889a6ef5f8431db9a3", "sha256": "339c56e09d10fdcdf319e05c643ace288afbb3832be1977f7ae3041e1a14919e" }, "downloads": -1, "filename": "alchemist_stack-0.1.0.dev1.tar.gz", "has_sig": false, "md5_digest": "d13ba3bf6718c8889a6ef5f8431db9a3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3", "size": 11213, "upload_time": "2018-04-24T19:34:09", "url": "https://files.pythonhosted.org/packages/24/87/51f54b231fddc935452d872b179b51fd303ef6708cbf61710e31a72f3835/alchemist_stack-0.1.0.dev1.tar.gz" } ] }