Skip to content

Commit f74abb1

Browse files
committed
Add documentation for skips, bump release version.
1 parent c8ebb02 commit f74abb1

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,10 @@ Combine bulk create, update, and delete. Make the DB match a set of in-memory ob
7070
- `filters`: Q() filters specifying the subset of the database to work in. Use `None` or `[]` if you want to sync against the entire table.
7171
- `batch_size`: passes through to Django `bulk_create.batch_size` and `bulk_update.batch_size`, and controls how many objects are created/updated per SQL query.
7272
- `fields`: (optional) List of fields to update. If not set, will sync all fields that are editable and not auto-created.
73+
- `skip_creates`: If truthy, will not perform any object creations needed to fully sync. Defaults to not skip.
74+
- `skip_updates`: If truthy, will not perform any object updates needed to fully sync. Defaults to not skip.
75+
- `skip_deletes`: If truthy, will not perform any object deletions needed to fully sync. Defaults to not skip.
76+
7377
- Returns a dict:
7478

7579
{

bulk_sync/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ def bulk_sync(new_models, key_fields, filters, batch_size=None, fields=None, ski
1515
`batch_size`: passes through to Django `bulk_create.batch_size` and `bulk_update.batch_size`, and controls
1616
how many objects are created/updated per SQL query.
1717
`fields`: (optional) list of fields to update. If not set, will sync all fields that are editable and not auto-created.
18-
18+
`skip_creates`: If truthy, will not perform any object creations needed to fully sync. Defaults to not skip.
19+
`skip_updates`: If truthy, will not perform any object updates needed to fully sync. Defaults to not skip.
20+
`skip_deletes`: If truthy, will not perform any object deletions needed to fully sync. Defaults to not skip.
1921
"""
2022
db_class = new_models[0].__class__
2123

@@ -49,13 +51,13 @@ def get_key(obj):
4951
new_obj.id = old_obj.id
5052
existing_objs.append(new_obj)
5153

52-
if skip_creates is False:
54+
if not skip_creates:
5355
db_class.objects.bulk_create(new_objs, batch_size=batch_size)
5456

55-
if skip_updates is False:
57+
if not skip_updates:
5658
db_class.objects.bulk_update(existing_objs, fields=fields, batch_size=batch_size)
5759

58-
if skip_deletes is False:
60+
if not skip_deletes:
5961
# delete stale objects
6062
objs.filter(pk__in=[_.pk for _ in list(obj_dict.values())]).delete()
6163

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
setuptools.setup(
77
name="django-bulk-sync",
8-
version='2.0.0',
8+
version='2.1.0',
99
description="Combine bulk add, update, and delete into a single call.",
1010
long_description=long_description,
1111
long_description_content_type='text/markdown',

0 commit comments

Comments
 (0)