{ "info": { "author": "Omar Nasr", "author_email": "omardev9898@gmail.com", "bugtrack_url": null, "classifiers": [ "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Operating System :: OS Independent", "Programming Language :: Python :: 3.7" ], "description": "# SQLtills\n\n## Simple CRUD utilities for sqlalchemy\n\nFinding myself having to duplicate code for my projects for CRUD even when using SQLAlchemy was very annoying. Thus I created some utilities which I then found annoying to have to copy paste and maintain between different projects. So in all my selfish glory I present to you SQLtills, a simple CRUD tool for sqlalchemy. Why is it called SQLtills because I am extremly horrible at naming things.\n\nSQLtills is available on PyPi so to install simply:\n\n```sh\npip install -U SQLtills\n```\n\n## How to use sqltills\n\nFor this tutorial we will be using an in-memory sqlite database as is typical for an sqlalchemy tutorial however, and this probably doesn't need to be said, we're good with whatever sqlalchemy is good with.\n\nImagine you have a database with two tables: authors and blogs\n\nyour sqlalchemy models would then be\n\n```python\n\nfrom sqlalchemy.ext.declarative import declarative_base\nfrom sqlalchemy import create_engine, Column, Integer, String, ForeignKey\nfrom sqlalchemy.orm import relationship, backref, sessionmaker\n\nBase = declarative_base()\n\nclass Blog(Base):\n __tablename__ = \"blogs\"\n id = Column(Integer, primary_key = True)\n author_id = Column(Integer, ForeignKey(\"authors.id\"))\n title = Column(String)\n blog_text = Column(String)\n\nclass Author(Base):\n __tablename__ = \"authors\"\n id = Column(Integer, primary_key = True)\n name = Column(String)\n blogs = relationship(Blog, backref = backref(\"author\", uselist = False))\n\nengine = create_engine('sqlite:///:memory:', echo=True)\n\nBase.metadata.bind = engine\n\nBase.metadata.create_all()\n\n```\n\nAwesome we now have the two tables in the database and the models defined. In the same script lets write some basic CRUD you would do in an app using sqltills utilities\n\n```python\nfrom sqltills import create_rows\n\nsession_maker = sessionmaker(bind = engine)\nsession = sessionmaker()\n\nnew_author = Author()\nnew_author.name = \"Omar\"\n\nnew_blog = Blog()\nnew_blog.title = \"How SQLAlchemy is Totally Awesome\"\nnew_blog.blog_text = \"too much stuff to put into one blog so the short answer is because\"\n\nnew_author.blogs.append(new_blog)\n\ncreate_rows(sesion, new_author, new_blog)\n\n```\n\nEasy right ! Okay imagine my application explodes and becomes medium.com now I have thousands of blogs and thousands of authors. I want to get all blogs which have the author being either Omar or Nancy\n\n```python\n\nfrom sqltills import read_rows\n\nresults = read_rows(session, Author, filters = [\n {\n 'name': {\n 'comparitor': '==',\n 'data': 'Omar'\n },\n 'join': 'or'\n },\n {\n 'name': {\n 'comparitor':'==',\n 'data': 'Nancy'\n }\n }\n])\n\nresults = results.all()\n\nfor author in results:\n for blog in author.blogs:\n print(blog.title)\n```\n\nThe filters argument is optional, if excluded the whole table will be included in the SQLAlchemy Query object. A parse-(like)-tree is used to build the filter expressions used in the session.query().filter() method\n\nThis filter parser can be used as well.\n\n```python\n\nfrom sqltills import ParseTree\nfilters = [\n {\n 'name': {\n 'comparitor': '==',\n 'data': 'Omar'\n },\n 'join': 'or'\n },\n {\n 'name': {\n 'comparitor':'==',\n 'data': 'Nancy'\n }\n }\n]\nparser = ParseTree(Author, filters)\nresults = parser.query(session)\n\n```\n\nThis is a really simple and almost useless package but it allows me to have a centralized set of tools to do all my CRUD and makes my code clean(er) and easier to maintain.\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/Moro-Code/sqltills", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "SQLtills", "package_url": "https://pypi.org/project/SQLtills/", "platform": "", "project_url": "https://pypi.org/project/SQLtills/", "project_urls": { "Homepage": "https://github.com/Moro-Code/sqltills" }, "release_url": "https://pypi.org/project/SQLtills/0.0.3/", "requires_dist": [ "SQLAlchemy (==1.3)" ], "requires_python": "", "summary": "Simple CRUD utilities for sqlalchemy", "version": "0.0.3" }, "last_serial": 5011126, "releases": { "0.0.3": [ { "comment_text": "", "digests": { "md5": "9305ecf4ce31f391902c6783d75cdd51", "sha256": "ea7c7c44c2c75f93003f7b8b71d1e7122c41b6b0a82b429e52a78f37195b92a0" }, "downloads": -1, "filename": "SQLtills-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "9305ecf4ce31f391902c6783d75cdd51", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9559, "upload_time": "2019-04-01T01:42:10", "url": "https://files.pythonhosted.org/packages/8f/8c/503c55901009e82fc637dd1441dd25bd69f076575b712bc94fb6e26c9dfe/SQLtills-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da51788f675963fe6e1ed06158045757", "sha256": "488404bf049f9a0ad9803184b5739b4c18bbb247783c5775aeeb7fa6887ddd42" }, "downloads": -1, "filename": "SQLtills-0.0.3.tar.gz", "has_sig": false, "md5_digest": "da51788f675963fe6e1ed06158045757", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7822, "upload_time": "2019-04-01T01:42:11", "url": "https://files.pythonhosted.org/packages/da/81/eaee7388d2fa6c683968036967d8f8e9e30c90a0b06850a998a0ec1105c2/SQLtills-0.0.3.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "9305ecf4ce31f391902c6783d75cdd51", "sha256": "ea7c7c44c2c75f93003f7b8b71d1e7122c41b6b0a82b429e52a78f37195b92a0" }, "downloads": -1, "filename": "SQLtills-0.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "9305ecf4ce31f391902c6783d75cdd51", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9559, "upload_time": "2019-04-01T01:42:10", "url": "https://files.pythonhosted.org/packages/8f/8c/503c55901009e82fc637dd1441dd25bd69f076575b712bc94fb6e26c9dfe/SQLtills-0.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da51788f675963fe6e1ed06158045757", "sha256": "488404bf049f9a0ad9803184b5739b4c18bbb247783c5775aeeb7fa6887ddd42" }, "downloads": -1, "filename": "SQLtills-0.0.3.tar.gz", "has_sig": false, "md5_digest": "da51788f675963fe6e1ed06158045757", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7822, "upload_time": "2019-04-01T01:42:11", "url": "https://files.pythonhosted.org/packages/da/81/eaee7388d2fa6c683968036967d8f8e9e30c90a0b06850a998a0ec1105c2/SQLtills-0.0.3.tar.gz" } ] }