API Reference

BaseStore module.

class diffsync.store.BaseStore(*args: Any, adapter: Adapter | None = None, name: str = '', **kwargs: Any)

Bases: object

Reference store to be implemented in different backends.

__init__(*args: Any, adapter: Adapter | None = None, name: str = '', **kwargs: Any) None

Init method for BaseStore.

add(*, obj: DiffSyncModel) None

Add a DiffSyncModel object to the store.

Parameters:

obj – Object to store

Raises:

ObjectAlreadyExists – if a different object with the same uid is already present.

count(*, model: str | DiffSyncModel | Type[DiffSyncModel] | None = None) int

Returns the number of elements of a specific model, or all elements in the store if not specified.

get(*, model: str | DiffSyncModel | Type[DiffSyncModel], identifier: str | Dict) DiffSyncModel

Get one object from the data store based on its unique id.

Parameters:
  • model – DiffSyncModel class or instance, or modelname string, that defines the type of the object to retrieve

  • identifier – Unique ID of the object to retrieve, or dict of unique identifier keys/values

Raises:
  • ValueError – if obj is a str and identifier is a dict (can’t convert dict into a uid str without a model class)

  • ObjectNotFound – if the requested object is not present

get_all(*, model: str | DiffSyncModel | Type[DiffSyncModel]) List[DiffSyncModel]

Get all objects of a given type.

Parameters:

model – DiffSyncModel class or instance, or modelname string, that defines the type of the objects to retrieve

Returns:

List of Object

get_all_model_names() Set[str]

Get all the model names stored.

Returns:

Set of all the model names.

get_by_uids(*, uids: List[str], model: str | DiffSyncModel | Type[DiffSyncModel]) List[DiffSyncModel]

Get multiple objects from the store by their unique IDs/Keys and type.

Parameters:
  • uids – List of unique id / key identifying object in the database.

  • model – DiffSyncModel class or instance, or modelname string, that defines the type of the objects to retrieve

Raises:

ObjectNotFound – if any of the requested UIDs are not found in the store

get_or_add_model_instance(obj: DiffSyncModel) Tuple[DiffSyncModel, bool]

Attempt to get the object with provided obj identifiers or instantiate obj.

Parameters:

obj – An obj of the DiffSyncModel to get or add.

Returns:

Provides the existing or new object and whether it was added or not.

get_or_instantiate(*, model: Type[DiffSyncModel], ids: Dict, attrs: Dict | None = None) Tuple[DiffSyncModel, bool]

Attempt to get the object with provided identifiers or instantiate it with provided identifiers and attrs.

Parameters:
  • model – The DiffSyncModel to get or create.

  • ids – Identifiers for the DiffSyncModel to get or create with.

  • attrs – Attributes when creating an object if it doesn’t exist. Defaults to None.

Returns:

Provides the existing or new object and whether it was created or not.

remove(*, obj: DiffSyncModel, remove_children: bool = False) None

Remove a DiffSyncModel object from the store.

Parameters:
  • obj – object to remove

  • remove_children – If True, also recursively remove any children of this object

Raises:

ObjectNotFound – if the object is not present

remove_item(modelname: str, uid: str) None

Remove one item from store.

update(*, obj: DiffSyncModel) None

Update a DiffSyncModel object to the store.

Parameters:

obj – Object to update

update_or_add_model_instance(obj: DiffSyncModel) Tuple[DiffSyncModel, bool]

Attempt to update an existing object with provided ids/attrs or instantiate obj.

Parameters:

obj – An instance of the DiffSyncModel to update or create.

Returns:

Provides the existing or new object and whether it was added or not.

update_or_instantiate(*, model: Type[DiffSyncModel], ids: Dict, attrs: Dict) Tuple[DiffSyncModel, bool]

Attempt to update an existing object with provided ids/attrs or instantiate it with provided identifiers and attrs.

Parameters:
  • model – The DiffSyncModel to get or create.

  • ids – Identifiers for the DiffSyncModel to get or create with.

  • attrs – Attributes when creating/updating an object if it doesn’t exist. Pass in empty dict, if no specific attrs.

Returns:

Provides the existing or new object and whether it was created or not.