QuerySet API Reference

QuerySet

class bulkmodel.queryset.BulkModelQuerySet(model=None, query=None, using=None, hints=None)
bulk_create(objs, bm_create_uuid=None, batch_size=None, send_signal=True, concurrent=False, max_concurrent_workers=None, return_queryset=False, **kwargs)

A signal-enabled override of django’s bulk_create

Parameters:
  • objs
  • bm_create_uuid (UUID) – a uuid to use as the bm_create_uuid in the model
  • batch_size
  • send_signal (bool) –
  • concurrent (bool) –
  • max_concurrent_workers (bool) –
  • return_queryset (bool) – whether to return instances; if false, returns the default from django’s method
Returns:

copy_from_objects(objs, bm_create_uuid=None, exclude_id=True, signal=True, concurrent=False, max_concurrent_workers=None, fieldnames=None, batch_size=None, return_queryset=False)

Updates data in the databse using the COPY FROM operaiton, if supported by the database being used

Parameters:
  • objs
  • bm_create_uuid
  • exclude_id
  • signal
  • concurrent
  • max_concurrent_workers
  • fieldnames
  • batch_size
  • return_queryset
Returns:

get_chunks(chunk_size, max_chunks=None)

Splits the queryset results into chunks

WARNING this method is destructive: it returns a list of lists, not a queryset. The queryset object will be lost

Parameters:
  • chunk_size
  • max_chunks
Returns:

populate_values(objects, *fieldnames)

Sets values on objects in the existing queryset from a given set of objects and optional set of fieldnames

Parameters:
  • objects (collections.Iterable) – a list of objects with data to use as a source for updates to apply within the queryset
  • fieldnames (List[str]) – a list of field names to apply updates to. If blank all fields will be updated
Returns:

update(batch_size=None, concurrent=False, max_concurrent_workers=None, send_signals=True, _use_super=False, return_queryset=False, **kwargs)

Performs a homogeneous update of data.

Parameters:
  • batch_size
  • concurrent
  • max_concurrent_workers
  • send_signals
  • _use_super
  • return_queryset
Returns:

update_fields(*fieldnames, objects=None, batch_size=None, send_signal=True, concurrent=False, max_concurrent_workers=None, return_queryset=False)

Performs a hetergeneous update

Parameters:
  • fieldnames
  • objects
  • batch_size
  • send_signal
  • concurrent
  • max_concurrent_workers
  • return_queryset
Returns:

Model Manager

class bulkmodel.managers.BulkModelManager
bulk_create(objs, bm_create_uuid=None, batch_size=None, send_signal=True, concurrent=False, max_concurrent_workers=None, return_queryset=False)

A signal-enabled override of django’s bulk_create

Parameters:
  • objs
  • bm_create_uuid (UUID) – a uuid to use as the bm_create_uuid in the model
  • batch_size
  • send_signal (bool) –
  • concurrent (bool) –
  • max_concurrent_workers (bool) –
  • return_queryset (bool) – whether to return instances; if false, returns the default from django’s method
Returns:

copy_from_objects(objs, bm_create_uuid=None, exclude_id=True, signal=True, concurrent=False, max_concurrent_workers=None, fieldnames=None, batch_size=None, return_queryset=False)

Updates data in the databse using the COPY FROM operaiton, if supported by the database being used

Parameters:
  • objs
  • bm_create_uuid
  • exclude_id
  • signal
  • concurrent
  • max_concurrent_workers
  • fieldnames
  • batch_size
  • return_queryset
Returns:

copy_to_instances(columns=None)

Populates data in instances of the queryset using the COPY TO function, if supported by the database being used

Parameters:columns
Returns:
create_queryset(objects)

Builds a queryset from a set of objects. For objects with a property called “id” or “pk” will be fetching from the database and populated with provided values.

Objects missing these propertie will be created in bulk and re-fetched from the database

Parameters:objects (collections.Iterable) –
Returns:
ensure_connected()

Makes sure the connection is established by running a select 1 against the cursor

Returns:
get_queryset()

Retrieves a queryset that refreshes the database connection when dropped The retry only happens once, and errors raised beyond this single retry attempt will be re-raised

Returns:
populate_values(objects, *fieldnames)

Sets values on objects in the existing queryset from a given set of objects and optional set of fieldnames

Parameters:
  • objects (collections.Iterable) – a list of objects with data to use as a source for updates to apply within the queryset
  • fieldnames (List[str]) – a list of field names to apply updates to. If blank all fields will be updated
Returns:

reset_connection()

Refreshes the connection by closing the existing one The next chained call in the queryset will open a new connection

Returns:
update_fields(*fieldnames, objects=None, batch_size=None, send_signal=True, concurrent=False, max_concurrent_workers=None, return_queryset=False)

Performs a hetergeneous update

Parameters:
  • fieldnames
  • objects
  • batch_size
  • send_signal
  • concurrent
  • max_concurrent_workers
Returns: