|
| 1 | +================ |
1 | 2 | django-chunkator |
2 | 3 | ================ |
3 | 4 |
|
4 | 5 |
|
5 | | -Chunk large querysetsinto small chunks, and iterate over them without killing |
| 6 | +Chunk large QuerySets into small chunks, and iterate over them without killing |
6 | 7 | your RAM. |
7 | 8 |
|
8 | 9 | .. image:: https://travis-ci.org/novafloss/django-chunkator.svg |
9 | 10 |
|
10 | | -Usage:: |
| 11 | +Usage |
| 12 | +===== |
| 13 | + |
| 14 | +.. code:: python |
11 | 15 |
|
12 | 16 | from chunkator import chunkator |
13 | 17 | for item in chunkator(LargeModel.objects.all(), 200): |
14 | 18 | do_something(item) |
15 | 19 |
|
16 | 20 | This tool is intended to work on Django querysets. |
17 | | -Your model **must** define a pk field (this is done by default, but sometimes |
18 | | -it can be overridden) and this pk has to be unique. ``django-chunkator`` has |
19 | | -been tested with Postgresql and SQLite, using regular PKs and UUIDs as primary |
20 | | -keys. |
21 | 21 |
|
22 | | -You can also use ``values()``:: |
| 22 | +Your model **must** define a ``pk`` field (this is done by default, but |
| 23 | +sometimes it can be overridden) and this pk has to be unique. ``django- |
| 24 | +chunkator`` has been tested with PostgreSQL and SQLite, using regular PKs and |
| 25 | +UUIDs as primary keys. |
| 26 | + |
| 27 | +You can also use ``values()``: |
| 28 | + |
| 29 | +.. code:: python |
23 | 30 |
|
24 | 31 | from chunkator import chunkator |
25 | 32 | for item in chunkator(LargeModel.objects.values('pk', 'name'), 200): |
26 | 33 | do_something(item) |
27 | 34 |
|
28 | 35 | .. important:: |
29 | 36 |
|
30 | | - If you're using ``values`` you **have** to add at least your "pk" field to |
31 | | - the values, otherwise, the chunkator will throw a `MissingPkFieldException`. |
32 | | - |
33 | | ----- |
| 37 | + If you're using ``values()`` you **have** to add at least your "pk" field |
| 38 | + to the values, otherwise, the chunkator will throw a |
| 39 | + ``MissingPkFieldException``. |
34 | 40 |
|
35 | 41 | .. warning:: |
36 | 42 |
|
37 | 43 | This will not **accelerate** your process. Instead of having one BIG query, |
38 | 44 | you'll have several small queries. This will save your RAM instead, because |
39 | 45 | you'll not load a huge queryset result before looping on it. |
| 46 | + |
| 47 | + |
| 48 | +License |
| 49 | +======= |
| 50 | + |
| 51 | +MIT License. |
0 commit comments