django-aggtrigg¶
Create triggers to do some aggregate and permit to count objects from database without using COUNT() aggregat.
Detailed documentation is in the “docs” directory.
Quick start¶
Add “django_aggtrigg” to your INSTALLED_APPS setting like this:
INSTALLED_APPS = ( ... 'django_aggtrigg', )
Import fields in your models:
from django_aggtrigg.models import IntegerTriggerField from django_aggtrigg.models import FloatTriggerField
Configure your fields as is:
class Apple(models.Model): indice = IntegerTriggerField(default=0) indice.aggregate_trigger=['count','min'] mark = FloatTriggerField(default=0) mark.aggregate_trigger=['min']
By default only the count aggregat will be created.
Use the new manager on you Model
objects = AggTriggManager()
Howto use the new aggregat¶
Instead of doing a COUNT as the traditionnal way:
Apple.objects.filter(indice=42).count()
you will do:
Apple.objects.optimized_count(indice=42)
This is may be less easy, but so much more efficient when you manipulate billions or tuples in your relations.
What inside¶
The class apple was create in the app called foo so the default name of the table that contains data will be foo_apple, we use the tablename from the Model so if it’s changed in Meta will still be compliant.
A new table foo_apple__indice_agg is created in the same database as foo_apple, it will contain the aggregat:
foo=# \d foo_apple__indice_agg
Table "public.foo_apple__indice_agg"
Column | Type | Modifiers
-----------+---------+-----------
indice | integer |
agg_count | integer |
agg_min | integer |
Indexes:
"foo_apple__indice_agg_indice_idx" btree (indice)
Contents¶
Install¶
django-aggtrigg is open-source software, published under BSD license. See License for details.
If you want to install a development environment, you should go to Contributing documentation.
Prerequisites¶
As a library¶
In most cases, you will use django-aggtrigg as a dependency of another project. In such a case, you should add django-aggtrigg in your main project’s requirements. Typically in setup.py:
from setuptools import setup
setup(
install_requires=[
'django-aggtrigg',
#...
]
# ...
)
Then when you install your main project with your favorite package manager (like pip [2]), django-aggtrigg will automatically be installed.
Standalone¶
You can install django-aggtrigg with your favorite Python package manager. As an example with pip [2]:
pip install django-aggtrigg
Check¶
Check django-aggtrigg has been installed:
python -c "import django_aggtrigg;print(django_aggtrigg.__version__)"
You should get django_aggtrigg‘s version.
References
[1] | https://www.python.org/ |
[2] | (1, 2) https://pypi.python.org/pypi/pip/ |
About django-aggtrigg¶
This section is about the django-aggtrig project itself.
Vision¶
django-json-dbindex helps you integrate and use complex indexes within a Django project.
License¶
Copyright (c) 2014, Rodolphe Quiédeville. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of django-agggtrigg nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Authors & contributors¶
Maintainer: Rodolphe Quiédeville <rodolphe@quiedeville.org>, as a member of the PeopleDoc [1] team: https://github.com/novapost/
Developers: https://github.com/novapost/django-aggtrigg/graphs/contributors
Notes & references
[1] | http://www.people-doc.com |
Changelog¶
This document describes changes between each past release. For information about future releases, check milestones [1] and Vision.
0.0.1 (2014-12-01)¶
Initial release.
- First release of django-aggtrigg, compatibility with PostgreSQL only.
Notes & references
[1] | https://github.com/novapost/django-aggtrigg/milestones |
Contributing¶
This document provides guidelines for people who want to contribute to the django-aggtrigg project.
Create tickets¶
Please use django-aggtrigg bugtracker [1] before starting some work:
- check if the bug or feature request has already been filed. It may have been answered too!
- else create a new ticket.
- if you plan to contribute, tell us, so that we are given an opportunity to give feedback as soon as possible.
- Then, in your commit messages, reference the ticket with some refs #TICKET-ID syntax.
Use topic branches¶
- Work in branches.
- Please never push in master directly.
- Prefix your branch with one the following keyword feature/ when adding a new feature and fix/ when working on a fix. You can also add the ticket ID corresponding to the issue to be explicit.
- If you work in a development branch and want to refresh it with changes from master, please rebase [2] or merge-based rebase [3], i.e. do not merge master.
Fork, clone¶
Clone django-aggtrigg repository (adapt to use your own fork):
git clone git@github.com:novapost/django-aggtrigg.git
cd django-aggtrigg/
Usual actions¶
The Makefile is the reference card for usual actions in development environment:
- Install development toolkit with pip [4]: make develop.
- Run tests with tox [5]: make test.
- Build documentation: make documentation. It builds Sphinx [6] documentation in var/docs/html/index.html.
- Release django-aggtrigg project with zest.releaser [7]: make release.
- Cleanup local repository: make clean, make distclean and make maintainer-clean.
See also make help.
Notes & references
[1] | https://github.com/novapost/django-aggtrigg/issues |
[2] | http://git-scm.com/book/en/Git-Branching-Rebasing |
[3] | http://tech.novapost.fr/psycho-rebasing-en.html |
[4] | https://pypi.python.org/pypi/pip/ |
[5] | https://pypi.python.org/pypi/tox/ |
[6] | https://pypi.python.org/pypi/Sphinx/ |
[7] | https://pypi.python.org/pypi/zest.releaser/ |