Skip to main content

Automatic trigger generator for Django

https://img.shields.io/pypi/v/djorm-pgarray.svg?style=flat https://img.shields.io/pypi/dm/djorm-pgarray.svg?style=flat https://travis-ci.org/novafloss/django-aggtrigg.svg

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

  1. Add “django_aggtrigg” to your INSTALLED_APPS setting like this:

    INSTALLED_APPS = (
        ...
        'django_aggtrigg',
    )
  2. Import fields in your models:

    from django_aggtrigg.models import IntegerTriggerField
    from django_aggtrigg.models import FloatTriggerField
  3. 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.

  1. 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)

Release files for django-aggtrigg 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-aggtrigg 1.1.0
File Size Uploaded
django-aggtrigg-1.1.0.tar.gz 22.0 kB Details

Release files / django-aggtrigg-1.1.0.tar.gz

Download URL django-aggtrigg-1.1.0.tar.gz
Size 22.0 kB
Tags Source
SHA-256 checksum
How to use checksums
c7b1a63d0a3e80ae2264d8d8b1d48c9a40db6991c1ccf992c635401d645b37f9
BLAKE2b-256 checksum
How to use checksums
9d5def96bfed3452747e7269399ffb14ffb0954a3005699574fbbd356b709171
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Release history Release notifications | RSS feed

This release

1.1.0 This release

1 release file

1.0.0

1 release file

0.7.1

1 release file

0.7.0

1 release file

0.6.6

1 release file

0.6.5

1 release file

0.6.4

1 release file

0.6.3

1 release file

0.6.2

1 release file

0.6.1

1 release file

0.6.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page