{ "info": { "author": "Paul Wolf", "author_email": "paul.wolf@yewleaf.com", "bugtrack_url": null, "classifiers": [ "Development Status :: 2 - Pre-Alpha", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: MIT License", "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7", "Topic :: Software Development :: Libraries :: Python Modules" ], "description": "Djaq: Django Queries\n====================\n\ncopyright (c) Paul Wolf\n\nTo Install:\n\n::\n\n git clone git@github.com:paul-wolf/djaq.git\n cd djaq\n\nCreate the virtualenv:\n\n::\n\n virtualenv -p python3 .venv \n\nActivate the virtual environment:\n\n::\n\n source ../.venv/bin/activate\n\nThe module itself does not install Django and there are no further\nrequirements. The example Django application is in ./bookshop. To\ninstall dependencies for the sample application:\n\n::\n\n cd bookshop\n pip install -r requirements.txt\n\nMake sure the virtualenv is activated! The sample database is already\npart of source code now (sqlite). The example application comes with a\nmanagement command to run queries:\n\n::\n\n ./manage.py djaq \"(Publisher.name, max(Book.price) - round(avg(Book.price)) as diff) Book b\" --format json\n\nIf using in code, you would do this:\n\n::\n\n from xquery.exp import XQuery as XQ\n xq = XQ(\"(avg(b.price) as average_book_price) Book b\"\n print(xq.json())\n\nThere are several generators to choose from to iterate records:\n\n::\n\n XQuery.json() # return json objects\n XQuery.dicts() # dicts\n XQuery.tuples() # tuples of values\n XQuery.objs() # We return for each record, an instance of XQueryInstance\n\nThe XQueryInstance is basically a namespace so you can do this:\n\n::\n\n for inst in XQ('(Book.name, Book.price)').objs():\n print(inst.name)\n print(inst.price)\n\netc.\n\nOutput of the command should look like this:\n\n::\n\n \u25b6 ./manage.py djaq \"(Publisher.name, max(Book.price) - round(avg(Book.price)) as diff) Book b\" --format json\n SELECT books_publisher.name, (max(books_book.price) - round(avg(books_book.price))) FROM books_book LEFT JOIN books_publisher ON (books_book.publisher_id = books_publisher.id) GROUP BY books_publisher.name LIMIT 10\n {\"publisher_name\": \"Avila, Garza and Ward\", \"diff\": 14.0}\n {\"publisher_name\": \"Boyer-Clements\", \"diff\": 16.0}\n {\"publisher_name\": \"Clark, Garza and York\", \"diff\": 15.0}\n {\"publisher_name\": \"Clarke PLC\", \"diff\": 14.0}\n {\"publisher_name\": \"Griffin-Blake\", \"diff\": 16.0}\n {\"publisher_name\": \"Hampton-Davis\", \"diff\": 13.0}\n {\"publisher_name\": \"Jones LLC\", \"diff\": 15.0}\n {\"publisher_name\": \"Lane-Kim\", \"diff\": 15.0}\n {\"publisher_name\": \"Norris-Bennett\", \"diff\": 14.0}\n {\"publisher_name\": \"Singleton-King\", \"diff\": 17.0}\n\nNotice the SQL used to retrieve data is printed first.\n\nThe syntax is like this:\n\n::\n\n (, ... ) ModelName{} Alias\n\nMost of these are optional. You don\u2019t have to reference models in an\nexpression with Alias; you don\u2019t need a filter in curly braces, etc.\nThere is no point in providing the join_operator on the first relation.\nYou can have as many of these as you wish to add more relations. You can\neven skip the join relation on subsequent relations: it will default to\nLEFT JOIN. Don\u2019t bother doing this:\n\n::\n\n (Books.name, Publisher.name) Book -> Publisher\n\nbecause you can just do this:\n\n::\n\n (Books.name, Publisher.name) Book\n\nIt will know to create the join to Publisher. But you might want to\ninclude it for the purpose of having an alias for Publisher:\n\n::\n\n (b.name, p.name) Book b -> Publisher p\n\nUse \u201cas\u201d operator to name columns:\n\n::\n\n (b.name as book_name, p.name as publisher) Book b -> Publisher p\n\nGet the average price of books for each publisher:\n\n::\n\n (avg(b.price)) Book b\n\nGet the difference off the maximum price:\n\n::\n\n (Publisher.name, max(Book.price) - avg(Book.price) as diff) Book b\n\nCount books per publisher:\n\n::\n\n (Publisher.name, count(Book.id) as num_books) Book b\n\nCount books with ratings up to and over 3:\n\n::\n\n (sum(b.rating > 3), sum(b.rating <= 3)) Book b\n\nGet average, maximum, minimum price of books:\n\n::\n\n (avg(b.price), max(b.price), min(b.price)) Book b\n\n##TODO\n\n- Improve group by detection\n- Reference named xqueries as relations (for subqueries)\n- IN operator either subquery, list, m2m, QuerySet\n- startswith, endswith custom functions etc.\n- m2m field relations\n- backwards relations\n- subquery, outter reference\n- map/reduce\n- Native sql backticks\n- Parameter checking and type casting\n- Emit names in double quotes\n- CSV import\n https://github.com/edcrewe/django-csvimport/blob/master/csvimport/parser.py\n- format sql https://pypi.org/project/format-sql/", "description_content_type": "", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/paul-wolf/djaq", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "Djaq", "package_url": "https://pypi.org/project/Djaq/", "platform": "", "project_url": "https://pypi.org/project/Djaq/", "project_urls": { "Homepage": "https://github.com/paul-wolf/djaq" }, "release_url": "https://pypi.org/project/Djaq/0.0.0/", "requires_dist": null, "requires_python": "", "summary": "An alternative Django query language", "version": "0.0.0" }, "last_serial": 4663135, "releases": { "0.0.0": [ { "comment_text": "", "digests": { "md5": "0dbb455db0c1f19832ff583564c56d1b", "sha256": "018cfe670ff03bcfa5d15fca6e229f1983569e994e1d2dac0ba89dcdbc20a450" }, "downloads": -1, "filename": "Djaq-0.0.0.tar.gz", "has_sig": false, "md5_digest": "0dbb455db0c1f19832ff583564c56d1b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13896, "upload_time": "2019-01-05T10:47:47", "url": "https://files.pythonhosted.org/packages/55/ef/527df93f4b50dcb22e7e0b977e3c71757bd066782c340fcf2b944b7a7192/Djaq-0.0.0.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "0dbb455db0c1f19832ff583564c56d1b", "sha256": "018cfe670ff03bcfa5d15fca6e229f1983569e994e1d2dac0ba89dcdbc20a450" }, "downloads": -1, "filename": "Djaq-0.0.0.tar.gz", "has_sig": false, "md5_digest": "0dbb455db0c1f19832ff583564c56d1b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 13896, "upload_time": "2019-01-05T10:47:47", "url": "https://files.pythonhosted.org/packages/55/ef/527df93f4b50dcb22e7e0b977e3c71757bd066782c340fcf2b944b7a7192/Djaq-0.0.0.tar.gz" } ] }