{ "info": { "author": "William Vaughn", "author_email": "vaughnwilld@gmail.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": "# aiosql\n\nSimple SQL in Python.\n\nSQL is code, you should be able to write it, version control it, comment on it, and use it in database tools\nlike `psql` as you would any other SQL. But, you also want to be able to use it from your python\napplications, and that's where `aiosql` can help. With `aiosql` you can organize your SQL statements in `.sql`\nfiles and load them into a python object as methods to call.\n\nThis project supports sync and asyncio based drivers for SQLite (`sqlite3`, `aiosqlite`) and PostgreSQL\n(`psycopg2`, `asyncpg`) out of the box, and can be extended to support other database drivers by you! The ``asyncio``\nsupport restricts this package to python versions >3.6. If you are using older versions of python please see the\nrelated [anosql](https://github.com/honza/anosql) package which this project is based on.\n\n## Install\n\n```\npip install aiosql\n```\n\nOr if you you use [poetry](https://poetry.eustace.io/):\n\n```\npoetry add aiosql\n```\n\n## Getting Started\n\n#### Basic Usage\n\nGiven you have a SQL file like the one below called `users.sql`\n\n```sql\n-- name: get-all-users\n-- Get all user records\nselect * from users;\n\n\n-- name: get-user-by-username\n-- Get user with the given username field.\nselect userid,\n username,\n firstname,\n lastname\n from users\n where username = :username;\n```\n\nYou can use `aiosql` to load the queries in this file for use in your Python application:\n\n```python\nimport aiosql\nimport sqlite3\n\nconn = sqlite3.connect(\"myapp.db\")\nqueries = aiosql.from_path(\"users.sql\", \"sqlite3\")\n\nusers = queries.get_all_users(conn)\n# >>> [(1, \"nackjicholson\", \"William\", \"Vaughn\"), (2, \"johndoe\", \"John\", \"Doe\"), ...]\n\nusers = queries.get_user_by_username(conn, username=\"nackjicholson\")\n# >>> [(1, \"nackjicholson\", \"William\", \"Vaughn\")\n```\n\nThis is pretty nice, we're able to define our methods in SQL and use them as methods from python!\n\n#### Query Operators to define different types of SQL actions\n\n`aiosql` can help you do even more by allowing you to declare in the SQL how you would like a query to be executed\nand returned in python. For instance, the `get-user-by-username` query above should really only return a single result\ninstead of a list containing one user. With the raw `sqlite3` driver in python we would probably have used \n`cur.fetchone()` instead of `cur.fetchall()` to retrieve a single row. We can inform `aiosql` to select a single row\nby using the `^` (select one) operator on the end of our query name.\n\n```sql\n-- name: get-user-by-username^\n-- Get user with the given username field.\nselect userid,\n username,\n firstname,\n lastname\n from users\n where username = :username;\n```\n\n```python\nnack = queries.get_user_by_username(conn, username=\"nackjicholson\")\n# >>> (1, \"nackjicholson\", \"William\", \"Vaughn\")\n```\n\n#### Using your own python types for SQL data.\n\nBy declaring a `record_class` directive in our SQL file we can inform `aiosql` to automatically marshal our data to a\ncustom class we've defined in python. In python3.7 a good choice for this is the new `dataclass` package.\n\n```sql\n-- name: get-user-by-username^\n-- record_class: User\n-- Get user with the given username field.\nselect userid,\n username,\n firstname,\n lastname\n from users\n where username = :username;\n```\n\nAll we have to do is provide our custom type to `aiosql` when we load our queries via the `record_classes` argument.\n\n```python\nimport aiosql\nimport sqlite3\nfrom dataclasses import dataclass\n\n\n@dataclass\nclass User:\n userid: int\n username: str\n firstname: str\n lastname: str\n\n\nconn = sqlite3.connect(\"myapp.db\")\nqueries = aiosql.from_path(\"users.sql\", \"sqlite3\", record_classes={\"User\": User})\n\nnack = queries.get_user_by_username(conn, username=\"nackjicholson\")\n# >>> User(userid=1, username=\"nackjicholson\", firstname=\"William\", lastname=\"Vaughn\")\n```\n\nHopefully this is enough to intrigue you and entice you to give aiosql a try. Check the documentation site for more\ninformation, and more features. Happy SQLing!\n\n## Documentation\n\nProject and API docs https://nackjicholson.github.io/aiosql\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/nackjicholson/aiosql", "keywords": "SQL,asyncio,PostgreSQL,sqlite,psycopg2", "license": "", "maintainer": "William Vaughn", "maintainer_email": "vaughnwilld@gmail.com", "name": "aiosql", "package_url": "https://pypi.org/project/aiosql/", "platform": "", "project_url": "https://pypi.org/project/aiosql/", "project_urls": { "Homepage": "https://github.com/nackjicholson/aiosql", "Repository": "https://github.com/nackjicholson/aiosql" }, "release_url": "https://pypi.org/project/aiosql/3.0.0/", "requires_dist": null, "requires_python": ">=3.6,<4.0", "summary": "Simple SQL in Python.", "version": "3.0.0" }, "last_serial": 5319925, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "0f77e8b4b66be0213cc06f86a935e7d8", "sha256": "8d111aec8ceb52f4575eba43e568d0c00b3e238a24c97e2a7540d184c5071453" }, "downloads": -1, "filename": "aiosql-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "0f77e8b4b66be0213cc06f86a935e7d8", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 26704, "upload_time": "2018-12-01T00:33:56", "url": "https://files.pythonhosted.org/packages/e0/b1/9c76701d48ccdb43df79de24194602828ba13c58ec171129e2899e5fb4de/aiosql-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "271de3ca90c93970c91786251087559e", "sha256": "aa709b65ebf3ed74208773c479015709ca32df014193c985a81b6642e5319578" }, "downloads": -1, "filename": "aiosql-0.1.1.tar.gz", "has_sig": false, "md5_digest": "271de3ca90c93970c91786251087559e", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 9243, "upload_time": "2018-12-01T00:33:57", "url": "https://files.pythonhosted.org/packages/6e/77/96211f82d676477dae5214159565452d51a27ca0d9a6e54cb8a14a6d9bdb/aiosql-0.1.1.tar.gz" } ], "1.0.0": [ { "comment_text": "", "digests": { "md5": "35600764a1c16953594833b3341529ba", "sha256": "8d184ae10393b23b01a9987437dc307e3bcfdb4d7d3536c4cf4fc379cee10ec7" }, "downloads": -1, "filename": "aiosql-1.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "35600764a1c16953594833b3341529ba", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 26304, "upload_time": "2018-12-02T09:13:58", "url": "https://files.pythonhosted.org/packages/89/92/314a8bfaf2ea2704d589c87cd72417cf94d9e5663897b348a71cdedc5941/aiosql-1.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a2a7f1d49b7474a6208279fe31da078a", "sha256": "31e37e8faee31ca36a4e60580d6cb8b8be36ae8a8732919e86b7a1785f938966" }, "downloads": -1, "filename": "aiosql-1.0.0.tar.gz", "has_sig": false, "md5_digest": "a2a7f1d49b7474a6208279fe31da078a", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 8452, "upload_time": "2018-12-02T09:13:59", "url": "https://files.pythonhosted.org/packages/6f/da/eaa52af21ff47fd742acd6f6d74cf4fd761bc701ee0a9f6fa0e0d248b87c/aiosql-1.0.0.tar.gz" } ], "2.0.0": [ { "comment_text": "", "digests": { "md5": "bd2fb0a40dd2270f3465dad379ad9fec", "sha256": "f9014ebc5dd31e7753cefb0498a25018e29943006c698b0a7e098ab435cc5b79" }, "downloads": -1, "filename": "aiosql-2.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "bd2fb0a40dd2270f3465dad379ad9fec", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 28950, "upload_time": "2018-12-07T17:33:10", "url": "https://files.pythonhosted.org/packages/0e/6d/ecb7c459ff79a4d25c1cefe13391234933c58f9c5bd5f9104c07fe07b1be/aiosql-2.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "7473f02b2e607dbe998cfe603e9e53f2", "sha256": "41a9adeaf54e776fe087d9b81c5ef896b5ba6e029e57d29a068dfd1243c372ba" }, "downloads": -1, "filename": "aiosql-2.0.0.tar.gz", "has_sig": false, "md5_digest": "7473f02b2e607dbe998cfe603e9e53f2", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 8821, "upload_time": "2018-12-07T17:33:12", "url": "https://files.pythonhosted.org/packages/8b/02/2c2505fc91a91612d3808b6afa974e0a1a8ea21b1c592524c33abcd55af8/aiosql-2.0.0.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "0894e3e8c91e86d57f584b83388127fb", "sha256": "4c134ab9afe4f8b96fb21b5ab10912a5892e4a75a714799fdc50a3f1682f0dc2" }, "downloads": -1, "filename": "aiosql-2.0.1-py3-none-any.whl", "has_sig": false, "md5_digest": "0894e3e8c91e86d57f584b83388127fb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 28956, "upload_time": "2018-12-08T17:24:29", "url": "https://files.pythonhosted.org/packages/32/fe/a80e428db5ffa7e690769274461db2634582a53fe2dfa35aea592037829f/aiosql-2.0.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "8b4a34e7600d21ead0f87f87eab3c4b3", "sha256": "62bcf91a80983b95b99483d5da42711acb74ce65289088a7030a080b0597eed0" }, "downloads": -1, "filename": "aiosql-2.0.1.tar.gz", "has_sig": false, "md5_digest": "8b4a34e7600d21ead0f87f87eab3c4b3", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 8834, "upload_time": "2018-12-08T17:24:30", "url": "https://files.pythonhosted.org/packages/59/8b/af8d5737b6817b710dbf87a8ef755c129af008d20bf083dcaa75b007d7b8/aiosql-2.0.1.tar.gz" } ], "2.0.2": [ { "comment_text": "", "digests": { "md5": "3b6b2df0f71f801c7ae6d433d7374f48", "sha256": "ddd03f6fbeda72500871fa6e3adc3a0c23218ff9eeb5cd3ff00dd4872f2788d1" }, "downloads": -1, "filename": "aiosql-2.0.2-py3-none-any.whl", "has_sig": false, "md5_digest": "3b6b2df0f71f801c7ae6d433d7374f48", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 28985, "upload_time": "2018-12-08T21:45:21", "url": "https://files.pythonhosted.org/packages/d4/f2/bc45f9e295e6f6c6c624b82610d722e664a2e456b84dd9e8387abc653eba/aiosql-2.0.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "a1a37f3f324f6306ca71a173a233340f", "sha256": "84567a37572614abe5798f379f95ca0b7137ba1bfecf79f264de380c170565bf" }, "downloads": -1, "filename": "aiosql-2.0.2.tar.gz", "has_sig": false, "md5_digest": "a1a37f3f324f6306ca71a173a233340f", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 8846, "upload_time": "2018-12-08T21:45:22", "url": "https://files.pythonhosted.org/packages/2c/08/d74d7eef7120efd576fa9443212dfdd28e887b26938c7a334d0dbcf572a5/aiosql-2.0.2.tar.gz" } ], "2.0.3": [ { "comment_text": "", "digests": { "md5": "5f1c7237b78b4f9fce0fec5460d9efeb", "sha256": "2d4b5d4ad0f918ed77ea2d10ae7661e6eb77f0931b9639afdcc76f272c0144a7" }, "downloads": -1, "filename": "aiosql-2.0.3-py3-none-any.whl", "has_sig": false, "md5_digest": "5f1c7237b78b4f9fce0fec5460d9efeb", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 29145, "upload_time": "2018-12-08T22:36:57", "url": "https://files.pythonhosted.org/packages/1f/68/289729777c7831bac734c0a00708ea9bab3049e24444846dc22fb2a10752/aiosql-2.0.3-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "75f1207749aed27ef15158fcc71a92ab", "sha256": "8fe9b60b6e0ac87137bc974c6a9bc5da60f0a0b13c185d2775ef5aa55e00f711" }, "downloads": -1, "filename": "aiosql-2.0.3.tar.gz", "has_sig": false, "md5_digest": "75f1207749aed27ef15158fcc71a92ab", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 8855, "upload_time": "2018-12-08T22:36:58", "url": "https://files.pythonhosted.org/packages/a3/d4/448bfd03d137dce6fb7bb5a5ba0eff4a166178b80e04aec916b6d8abbc87/aiosql-2.0.3.tar.gz" } ], "3.0.0": [ { "comment_text": "", "digests": { "md5": "0c3a51e9679cb66f01113e9c55b21ee3", "sha256": "b7842de7e4ab2e3aa20c0a721c7a173e2cfdbea6197d0e24a0261061413b3ea1" }, "downloads": -1, "filename": "aiosql-3.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0c3a51e9679cb66f01113e9c55b21ee3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 14004, "upload_time": "2019-05-26T22:08:49", "url": "https://files.pythonhosted.org/packages/bd/a4/8d539e82d977b495c1d3929967d33d459bf1529f1f9743b18aa4360070d8/aiosql-3.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da34dcaa8a35d6ba0ffb42c2aa6bb935", "sha256": "9256d6825ed958cfe70c4af483a05c220fbbdbfbdd237122325dd853ccc1569b" }, "downloads": -1, "filename": "aiosql-3.0.0.tar.gz", "has_sig": false, "md5_digest": "da34dcaa8a35d6ba0ffb42c2aa6bb935", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 12034, "upload_time": "2019-05-26T22:08:50", "url": "https://files.pythonhosted.org/packages/55/86/1a699186cdeb97952aeadc94a70c680093f1b27e2bcc0e64bf747b407e23/aiosql-3.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0c3a51e9679cb66f01113e9c55b21ee3", "sha256": "b7842de7e4ab2e3aa20c0a721c7a173e2cfdbea6197d0e24a0261061413b3ea1" }, "downloads": -1, "filename": "aiosql-3.0.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0c3a51e9679cb66f01113e9c55b21ee3", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": ">=3.6,<4.0", "size": 14004, "upload_time": "2019-05-26T22:08:49", "url": "https://files.pythonhosted.org/packages/bd/a4/8d539e82d977b495c1d3929967d33d459bf1529f1f9743b18aa4360070d8/aiosql-3.0.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "da34dcaa8a35d6ba0ffb42c2aa6bb935", "sha256": "9256d6825ed958cfe70c4af483a05c220fbbdbfbdd237122325dd853ccc1569b" }, "downloads": -1, "filename": "aiosql-3.0.0.tar.gz", "has_sig": false, "md5_digest": "da34dcaa8a35d6ba0ffb42c2aa6bb935", "packagetype": "sdist", "python_version": "source", "requires_python": ">=3.6,<4.0", "size": 12034, "upload_time": "2019-05-26T22:08:50", "url": "https://files.pythonhosted.org/packages/55/86/1a699186cdeb97952aeadc94a70c680093f1b27e2bcc0e64bf747b407e23/aiosql-3.0.0.tar.gz" } ] }