{ "info": { "author": "Brad Martsberger", "author_email": "bmarts@lumere.com", "bugtrack_url": null, "classifiers": [ "Programming Language :: Python :: 2", "Programming Language :: Python :: 2.7", "Programming Language :: Python :: 3", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Programming Language :: Python :: 3.7" ], "description": ".. image:: https://travis-ci.org/martsberger/django-sql-utils.svg?branch=master\n :target: https://travis-ci.org/martsberger/django-sql-utils\n\n\nDjango SQL Utils\n================\n\nThis package provides utilities for working with Django querysets so that\nyou can generate the SQL that you want, with an API you enjoy.\n\nSubquery Aggregates\n-------------------\n\nThe `Count` aggregation in Django::\n\n Parent.objects.annotate(child_count=Count('child'))\n\ngenerates SQL like the following::\n\n SELECT parent.*, Count(child.id) as child_count\n FROM parent\n JOIN child on child.parent_id = parent.id\n GROUP BY parent.id\n\nIn many cases, this is not as performant as doing the count in a SUBQUERY\ninstead of with a JOIN::\n\n SELECT parent.*,\n (SELECT Count(id)\n FROM child\n WHERE parent_id = parent.id) as child_count\n FROM parent\n\nDjango allows us to generate this SQL using The Subquery and OuterRef classes::\n\n\n subquery = Subquery(Child.objects.filter(parent_id=OuterRef('id')).order_by()\n .values('parent').annotate(count=Count('pk'))\n .values('count'), output_field=IntegerField())\n Parent.objects.annotate(child_count=Coalesce(subquery, 0))\n\nHoly cow! It's not trivial to figure what everything is doing in the above\ncode and it's not particularly good for maintenance. SubqueryAggregates allow\nyou to forget all that complexity and generate the subquery count like this::\n\n Parent.objects.annotate(child_count=SubqueryCount('child'))\n\nPhew! Much easier to read and understand. It's the same API as the original `Count`\njust specifying the Subquery version.\n\nEasier API for Exists\n---------------------\nIf you have a Parent/Child relationship (Child has a ForeignKey to Parent), you can annotate a queryset\nof Parent objects with a boolean indicating whether or not the parent has children::\n\n from django.db.models import Exists\n\n parents = Parent.objects.annotate(\n has_children=Exists(Child.objects.filter(parent=OuterRef('pk'))\n )\n\nThat's a bit more boilerplate than should be necessary, so we provide a simpler API for Exists::\n\n from sql_util.utils import Exists\n\n parents = Parent.objects.annotate(\n has_children=Exists('child')\n )\n\nThe child queryset can be filtered with the keyword argument `filter`. E.g.,::\n\n parents = Parent.objects.annotate(\n has_child_named_John = Exists('child', filter=Q(name='John'))\n )\n\nThe `sql_util` version of `Exists` can also take a queryset as the first parameter and behave just like\nthe Django `Exists` class, so you are able to use it everywhere without worrying about name confusion.\n\nInstallation and Usage\n----------------------\n\nInstall from PyPI::\n\n pip install django-sql-utils\n\nThen you can::\n\n from sql_util.utils import SubqueryCount\n\nAnd use that as shown above.\n\nIn addition to `SubqueryCount`, this package provides\n\n* `SubqueryMin`\n* `SubqueryMax`\n* `SubquerySum`\n* `SubqueryAvg`\n\nIf you want to use other aggregates, you can use the\ngeneric `SubqueryAggregate` class. For example, if you want to use Postgres' `ArrayAgg`\nto get an array of `Child.name` for each `Parent`::\n\n from django.contrib.postgres.aggregates import ArrayAgg\n\n aggregate = SubqueryAggregate('child__name', aggregate=ArrayAgg)\n Parent.objects.annotate(child_names=aggregate)\n\nOr subclass SubqueryAggregate::\n\n from django.contrib.postgres.aggregates import ArrayAgg\n\n class SubqueryArrayAgg(SubqueryAggregate)\n aggregate = ArrayAgg\n unordered = True\n\n Parent.objects.annotate(avg_child_age=SubqueryArrayAgg('child__age'))\n\n\n\n", "description_content_type": "", "docs_url": null, "download_url": "https://github.com/martsberger/django-sql-utils/archive/0.4.2.tar.gz", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/martsberger/django-sql-utils", "keywords": "", "license": "MIT", "maintainer": "", "maintainer_email": "", "name": "django-sql-utils", "package_url": "https://pypi.org/project/django-sql-utils/", "platform": "", "project_url": "https://pypi.org/project/django-sql-utils/", "project_urls": { "Download": "https://github.com/martsberger/django-sql-utils/archive/0.4.2.tar.gz", "Homepage": "https://github.com/martsberger/django-sql-utils" }, "release_url": "https://pypi.org/project/django-sql-utils/0.4.2/", "requires_dist": [ "django (>=1.11)", "sqlparse" ], "requires_python": "", "summary": "Improved API for aggregating using Subquery", "version": "0.4.2" }, "last_serial": 5739862, "releases": { "0.1.0": [ { "comment_text": "", "digests": { "md5": "60f9e5e9c0bb15b829dc40861663da99", "sha256": "df4588b72af0e058404db99271276949ff0b14211d73a0733f3a3fc916cfcbed" }, "downloads": -1, "filename": "django_sql_utils-0.1.0-py3-none-any.whl", "has_sig": false, "md5_digest": "60f9e5e9c0bb15b829dc40861663da99", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9800, "upload_time": "2019-04-02T15:40:24", "url": "https://files.pythonhosted.org/packages/80/79/2fb937297d2e6ef115f4b7545275534bc9661ac247e359c847082cc9564c/django_sql_utils-0.1.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3be282537a9c246203e49a46b6ca06bd", "sha256": "009666c52b1425b82d81be43e998ce5b2882454cd9e5f057a8713d6120d86cf9" }, "downloads": -1, "filename": "django-sql-utils-0.1.0.tar.gz", "has_sig": false, "md5_digest": "3be282537a9c246203e49a46b6ca06bd", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6717, "upload_time": "2019-04-02T15:40:26", "url": "https://files.pythonhosted.org/packages/59/1c/cd46b0333daf78751da5a9fff21919c6d78ce1fe569427db77325109353e/django-sql-utils-0.1.0.tar.gz" } ], "0.1.1": [ { "comment_text": "", "digests": { "md5": "4622c6028e9c0636c9f77a44ed36e913", "sha256": "ba11c283977be595bc657581ea450dadf33dada4e66b1447b20f8e23fd94134d" }, "downloads": -1, "filename": "django_sql_utils-0.1.1-py3-none-any.whl", "has_sig": false, "md5_digest": "4622c6028e9c0636c9f77a44ed36e913", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 9830, "upload_time": "2019-04-02T16:10:40", "url": "https://files.pythonhosted.org/packages/f8/da/c78747478c9b2a4e2d16ed954bed72d5fcb768bf1314780b4eefcd1abb95/django_sql_utils-0.1.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "0476077fd9186359e8d5458a722d65af", "sha256": "e6e6277bc2c89eb617d7e5665b6898d858ed98cdfe09e1bfcaff8c55246da3d6" }, "downloads": -1, "filename": "django-sql-utils-0.1.1.tar.gz", "has_sig": false, "md5_digest": "0476077fd9186359e8d5458a722d65af", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 6748, "upload_time": "2019-04-02T16:10:41", "url": "https://files.pythonhosted.org/packages/d0/54/11cc7195efe20b08a862c44594aad6e67e4aa15b0175ee923edcc2a1129d/django-sql-utils-0.1.1.tar.gz" } ], "0.2.0": [ { "comment_text": "", "digests": { "md5": "0e4113bfe46d65669ef5c34b0f02c776", "sha256": "63194adee92b661b9347528274c022c30cb614d64b4bb01f585c3ebed5660649" }, "downloads": -1, "filename": "django_sql_utils-0.2.0-py3-none-any.whl", "has_sig": false, "md5_digest": "0e4113bfe46d65669ef5c34b0f02c776", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11585, "upload_time": "2019-05-12T18:05:50", "url": "https://files.pythonhosted.org/packages/3e/f9/400061be37203fb6c87249fe83935f6c33336614881c0d1594792565c04a/django_sql_utils-0.2.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "b66736e767e7d24d05ab793e03a1735b", "sha256": "0f69a531e1dfde35a21dcdf6c5da20f9a93ec662cfae5637471569f8e03f16ad" }, "downloads": -1, "filename": "django-sql-utils-0.2.0.tar.gz", "has_sig": false, "md5_digest": "b66736e767e7d24d05ab793e03a1735b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8494, "upload_time": "2019-05-12T18:05:51", "url": "https://files.pythonhosted.org/packages/0d/17/7849ad977ce741046df24917a4cfaa80a9fdc4ad96452b9638854a290869/django-sql-utils-0.2.0.tar.gz" } ], "0.2.1": [ { "comment_text": "", "digests": { "md5": "ffa2ddb9b288eb36ce5d5112d41a692e", "sha256": "7c468996bf34a00bebdb58f945a5527374f3ad180f860b8b2d14964042ff0efd" }, "downloads": -1, "filename": "django_sql_utils-0.2.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ffa2ddb9b288eb36ce5d5112d41a692e", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11748, "upload_time": "2019-05-17T03:46:00", "url": "https://files.pythonhosted.org/packages/45/2f/3db39e75be819933300ba7139ed10d7c350c2095cfb6b4542eb1d53c5ab9/django_sql_utils-0.2.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "67c4b15dc514a0c7020b8caa44203f6e", "sha256": "f0a222d0eacf2bec62317f78a24d41d0208a7cb436a0276bd1b3b5d4dc571848" }, "downloads": -1, "filename": "django-sql-utils-0.2.1.tar.gz", "has_sig": false, "md5_digest": "67c4b15dc514a0c7020b8caa44203f6e", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8665, "upload_time": "2019-05-17T03:46:01", "url": "https://files.pythonhosted.org/packages/f1/ac/8ea2b8202de85c59560e3f7f5f4b57de461c387e512eb40574de11d4fa38/django-sql-utils-0.2.1.tar.gz" } ], "0.2.2": [ { "comment_text": "", "digests": { "md5": "fc8aece7e19a3965c2ad0f9f6f49060a", "sha256": "06e41e7e05b1262acd84faa8cddf9b7d723b9e0ef52e2be99bf167a7495e8ed2" }, "downloads": -1, "filename": "django_sql_utils-0.2.2-py3-none-any.whl", "has_sig": false, "md5_digest": "fc8aece7e19a3965c2ad0f9f6f49060a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 11749, "upload_time": "2019-06-20T14:23:04", "url": "https://files.pythonhosted.org/packages/93/d9/a04339cebaf11b3fa4c72617fc35ba73fe1c9dd779cfc7b25e921e21ad53/django_sql_utils-0.2.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "85f42dc4793c172d383ac0404b2bdcfe", "sha256": "ce755d66eec354fd579efad0a69d223ffe6c5c34d7c07f096178dcc9e6a24943" }, "downloads": -1, "filename": "django-sql-utils-0.2.2.tar.gz", "has_sig": false, "md5_digest": "85f42dc4793c172d383ac0404b2bdcfe", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8685, "upload_time": "2019-06-20T14:23:05", "url": "https://files.pythonhosted.org/packages/01/7d/277319cc6c1a8cf2ccd97984d12230711182e8cb1fd14d71b8ed8c00ae10/django-sql-utils-0.2.2.tar.gz" } ], "0.3.0": [ { "comment_text": "", "digests": { "md5": "5b2e827e735ff18a42d1674af3b3b00f", "sha256": "8a08b032df0f662396e09fe336383971bdb9fc3fc7f7708392ab86c28541eceb" }, "downloads": -1, "filename": "django_sql_utils-0.3.0-py3-none-any.whl", "has_sig": false, "md5_digest": "5b2e827e735ff18a42d1674af3b3b00f", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12066, "upload_time": "2019-07-11T18:23:09", "url": "https://files.pythonhosted.org/packages/cf/1d/bc6c07638ae4d9752567c8315c9270258cb894a5e55ba44136361541d0a4/django_sql_utils-0.3.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "6b29aef9b22e82acb608beda8b86e149", "sha256": "80f259dce0b2e7f913f02c3bad724e59b6cd219212eaf11cb904e235ca1be972" }, "downloads": -1, "filename": "django-sql-utils-0.3.0.tar.gz", "has_sig": false, "md5_digest": "6b29aef9b22e82acb608beda8b86e149", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8829, "upload_time": "2019-07-11T18:23:10", "url": "https://files.pythonhosted.org/packages/df/a0/6b8c8d9f7d038ff3de5ac68bb71a2a6b63bb50575f66c5354a1691a17e94/django-sql-utils-0.3.0.tar.gz" } ], "0.3.1": [ { "comment_text": "", "digests": { "md5": "37e09e3026dd7dafaba86df8f0fb1f1a", "sha256": "452841fe7a780c02ef84e6fdce33aaa38c37d8c1258040e7fdfebbb49babd83b" }, "downloads": -1, "filename": "django_sql_utils-0.3.1-py3-none-any.whl", "has_sig": false, "md5_digest": "37e09e3026dd7dafaba86df8f0fb1f1a", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12621, "upload_time": "2019-07-12T14:22:17", "url": "https://files.pythonhosted.org/packages/a3/27/b3e0b2c5d326a039e7e2e6609d4bca52b236aad8b9fd4bc4bd9c71c81869/django_sql_utils-0.3.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "23f845b61c76d6019dfefd908ccd8726", "sha256": "7481726e03da3d344089e0ebc84a99d912778840620a4a05a880a8511da58674" }, "downloads": -1, "filename": "django-sql-utils-0.3.1.tar.gz", "has_sig": false, "md5_digest": "23f845b61c76d6019dfefd908ccd8726", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9430, "upload_time": "2019-07-12T14:22:19", "url": "https://files.pythonhosted.org/packages/d0/10/47b2bf3ac3fb928ce906ec2c87e249da2a07d9b8e8dbf0fa0c8eaf05b55b/django-sql-utils-0.3.1.tar.gz" } ], "0.3.2": [ { "comment_text": "", "digests": { "md5": "d75e32ca3765136773afc152bf008d46", "sha256": "c5a0275ca2f42cc0d3cf049882291cdc12497e50cf8b26d8e87c3589595cf058" }, "downloads": -1, "filename": "django_sql_utils-0.3.2-py3-none-any.whl", "has_sig": false, "md5_digest": "d75e32ca3765136773afc152bf008d46", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 12600, "upload_time": "2019-07-13T05:26:57", "url": "https://files.pythonhosted.org/packages/8c/dd/1bb4043e5449e7c24e1a91dfa658571e697e01c9ab7634212bbedeeeaaf2/django_sql_utils-0.3.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "14b896ec7a90457a94f13cf021627904", "sha256": "effb5aad9e578f5da951787f4988b169f6db62633f60c2973a1f146b2a6d57c3" }, "downloads": -1, "filename": "django-sql-utils-0.3.2.tar.gz", "has_sig": false, "md5_digest": "14b896ec7a90457a94f13cf021627904", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9396, "upload_time": "2019-07-13T05:26:59", "url": "https://files.pythonhosted.org/packages/68/7a/493a5e60cf18c725ebac8017ed0fa621a2aa04f262f49945b585de16d00a/django-sql-utils-0.3.2.tar.gz" } ], "0.4.0": [ { "comment_text": "", "digests": { "md5": "06027e2b7023cd3ddc1c3908baa07dc4", "sha256": "2b854443b5b36f548a4c9db5fb3bf407d52cdc951a7d51ae8f2f3db00d29e5a5" }, "downloads": -1, "filename": "django_sql_utils-0.4.0-py3-none-any.whl", "has_sig": false, "md5_digest": "06027e2b7023cd3ddc1c3908baa07dc4", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13111, "upload_time": "2019-07-15T19:38:14", "url": "https://files.pythonhosted.org/packages/a0/56/771b327b3cfb99bad5334789757ccb648698d0433f14802b504553811b15/django_sql_utils-0.4.0-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "fb89ae9f9a5c0f1339de388c2887adea", "sha256": "79ceac513270cca55da2bb13df7640dd90b66a0164ded724011c40864b7129ca" }, "downloads": -1, "filename": "django-sql-utils-0.4.0.tar.gz", "has_sig": false, "md5_digest": "fb89ae9f9a5c0f1339de388c2887adea", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9817, "upload_time": "2019-07-15T19:38:15", "url": "https://files.pythonhosted.org/packages/0d/71/6714935b3d45ef5d09d06c56f4eeb0f80d49e4541a887fda73739884c571/django-sql-utils-0.4.0.tar.gz" } ], "0.4.1": [ { "comment_text": "", "digests": { "md5": "ebdaa0d8831825b42386553193e6df38", "sha256": "00e1d59993d9e64088b05f17bd2358b19996adc69a2dfa65426725a1695224c3" }, "downloads": -1, "filename": "django_sql_utils-0.4.1-py3-none-any.whl", "has_sig": false, "md5_digest": "ebdaa0d8831825b42386553193e6df38", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13476, "upload_time": "2019-08-07T12:03:15", "url": "https://files.pythonhosted.org/packages/f6/6d/b594b5d2aa4803df12cbded3c7af84d0a76cded8c7966981619f79ecb266/django_sql_utils-0.4.1-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "3a5bb71e940dbede388e937c94f2fd38", "sha256": "d2308d6b23dad8a3e7739482c20ed10b8b9a24a1d30c722f0bb018baab16500e" }, "downloads": -1, "filename": "django-sql-utils-0.4.1.tar.gz", "has_sig": false, "md5_digest": "3a5bb71e940dbede388e937c94f2fd38", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 9948, "upload_time": "2019-08-07T12:03:17", "url": "https://files.pythonhosted.org/packages/8f/c4/8f7d8d564e2e3e931e5a6a297656297fae3094f52d6ba6be629a59d90e42/django-sql-utils-0.4.1.tar.gz" } ], "0.4.2": [ { "comment_text": "", "digests": { "md5": "5e2b14b53e64c15806df1a31a1fcf1d7", "sha256": "8362de43eda77102c3f9b5a4be936352198caa68bab9b9098ab9c15074edc3f9" }, "downloads": -1, "filename": "django_sql_utils-0.4.2-py3-none-any.whl", "has_sig": false, "md5_digest": "5e2b14b53e64c15806df1a31a1fcf1d7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13745, "upload_time": "2019-08-27T23:39:55", "url": "https://files.pythonhosted.org/packages/c2/40/726a6d9869fbb8450b39f27bd3c616d8c68919f198f0e5e74134ebbad82b/django_sql_utils-0.4.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aa020491c956f992aec0086ef1370f0b", "sha256": "bb6989dfdda8bdd915977d5364e02ce41de7cdda16e432f8da0568fa708e7d7d" }, "downloads": -1, "filename": "django-sql-utils-0.4.2.tar.gz", "has_sig": false, "md5_digest": "aa020491c956f992aec0086ef1370f0b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10176, "upload_time": "2019-08-27T23:39:57", "url": "https://files.pythonhosted.org/packages/6b/1e/fadded79466aad0a3dbb9e7b044481777ffd9476d7a65d5cfbd5c6791c67/django-sql-utils-0.4.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "5e2b14b53e64c15806df1a31a1fcf1d7", "sha256": "8362de43eda77102c3f9b5a4be936352198caa68bab9b9098ab9c15074edc3f9" }, "downloads": -1, "filename": "django_sql_utils-0.4.2-py3-none-any.whl", "has_sig": false, "md5_digest": "5e2b14b53e64c15806df1a31a1fcf1d7", "packagetype": "bdist_wheel", "python_version": "py3", "requires_python": null, "size": 13745, "upload_time": "2019-08-27T23:39:55", "url": "https://files.pythonhosted.org/packages/c2/40/726a6d9869fbb8450b39f27bd3c616d8c68919f198f0e5e74134ebbad82b/django_sql_utils-0.4.2-py3-none-any.whl" }, { "comment_text": "", "digests": { "md5": "aa020491c956f992aec0086ef1370f0b", "sha256": "bb6989dfdda8bdd915977d5364e02ce41de7cdda16e432f8da0568fa708e7d7d" }, "downloads": -1, "filename": "django-sql-utils-0.4.2.tar.gz", "has_sig": false, "md5_digest": "aa020491c956f992aec0086ef1370f0b", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 10176, "upload_time": "2019-08-27T23:39:57", "url": "https://files.pythonhosted.org/packages/6b/1e/fadded79466aad0a3dbb9e7b044481777ffd9476d7a65d5cfbd5c6791c67/django-sql-utils-0.4.2.tar.gz" } ] }