Skip to content

diffsync.store

BaseStore module.

diffsync.store.BaseStore

Reference store to be implemented in different backends.

__init__(*args, adapter=None, name='', **kwargs)

Init method for BaseStore.

__str__()

Render store name.

add(*, obj)

Add a DiffSyncModel object to the store.

Parameters:

Name Type Description Default
obj DiffSyncModel

Object to store

required

Raises:

Type Description
ObjectAlreadyExists

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

count(*, model=None)

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

get(*, model, identifier)

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

Parameters:

Name Type Description Default
model Union[str, DiffSyncModel, Type[DiffSyncModel]]

DiffSyncModel class or instance, or modelname string, that defines the type of the object to retrieve

required
identifier Union[str, Dict]

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

required

Raises:

Type Description
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)

Get all objects of a given type.

Parameters:

Name Type Description Default
model Union[str, DiffSyncModel, Type[DiffSyncModel]]

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

required

Returns:

Type Description
List[DiffSyncModel]

List of Object

get_all_model_names()

Get all the model names stored.

Return

Set of all the model names.

get_by_uids(*, uids, model)

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

Parameters:

Name Type Description Default
uids List[str]

List of unique id / key identifying object in the database.

required
model Union[str, DiffSyncModel, Type[DiffSyncModel]]

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

required

Raises:

Type Description
ObjectNotFound

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

get_or_add_model_instance(obj)

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

Parameters:

Name Type Description Default
obj DiffSyncModel

An obj of the DiffSyncModel to get or add.

required

Returns:

Type Description
Tuple[DiffSyncModel, bool]

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

get_or_instantiate(*, model, ids, attrs=None)

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

Parameters:

Name Type Description Default
model Type[DiffSyncModel]

The DiffSyncModel to get or create.

required
ids Dict

Identifiers for the DiffSyncModel to get or create with.

required
attrs Optional[Dict]

Attributes when creating an object if it doesn't exist. Defaults to None.

None

Returns:

Type Description
Tuple[DiffSyncModel, bool]

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

remove(*, obj, remove_children=False)

Remove a DiffSyncModel object from the store.

Parameters:

Name Type Description Default
obj DiffSyncModel

object to remove

required
remove_children bool

If True, also recursively remove any children of this object

False

Raises:

Type Description
ObjectNotFound

if the object is not present

remove_item(modelname, uid)

Remove one item from store.

update(*, obj)

Update a DiffSyncModel object to the store.

Parameters:

Name Type Description Default
obj DiffSyncModel

Object to update

required

update_or_add_model_instance(obj)

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

Parameters:

Name Type Description Default
obj DiffSyncModel

An instance of the DiffSyncModel to update or create.

required

Returns:

Type Description
Tuple[DiffSyncModel, bool]

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

update_or_instantiate(*, model, ids, attrs)

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

Parameters:

Name Type Description Default
model Type[DiffSyncModel]

The DiffSyncModel to get or create.

required
ids Dict

Identifiers for the DiffSyncModel to get or create with.

required
attrs Dict

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

required

Returns:

Type Description
Tuple[DiffSyncModel, bool]

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