Skip to content

CRUDBase

CRUDBase

Bases: Generic[ModelType]

CRUD object with default methods to Create, Read, Update, Delete (CRUD).

Parameters:

Name Type Description Default
model Type[ModelType]

A Pydantic model class

required

add(*, term)

Add the parameters for a specific term, called by a unique name. If the name already exists, then this will raise a ValueError.

Parameters:

Name Type Description Default
term ModelType | dict

A dictionary conforming to the ModelType. Model names must be unique, so a valid name in the model list will have no collisions.

required

Raises:

Type Description
ValueError

If the term already exists.

add_multi(*, terms)

Add multiple parameters for a specific term, called by a unique name. If the name already exists, then this will raise a ValueError.

Parameters:

Name Type Description Default
terms list[ModelType | dict]

A list of dictionaries conforming to the ModelType.

required

Raises:

Type Description
ValueError

If the term already exists.

get(*, name)

Get a specific model from the list of models defining this schema, called by a unique name.

Parameters:

Name Type Description Default
name str | UUID

Specific name or reference UUID for a field already in the Schema.

required

Returns:

Type Description
ModelType | None

ModelType, or None if no such name or UUID.

get_all()

Get all models from the current list of models.

remove(*, name)

Remove a specific term, called by a unique name.

Parameters:

Name Type Description Default
name str

Specific name or reference UUID for a field already in the Schema.

required

reorder(*, order)

Reorder a list of terms.

Parameters:

Name Type Description Default
order list[UUID]

list of UUID in the desired order. Use .get_all() to view the current list.

required

Raises:

Type Description
ValueError

If the list of UUIDs doesn't conform to that in the list of terms.

reset()

Reset a list of ModelType terms to an empty list.

update(*, term)

Update the parameters for a specific term, called by a unique name. If the name does not exist, then this will raise a ValueError.

Parameters:

Name Type Description Default
term ModelType | dict

A dictionary conforming to the ModelType.

required

Raises:

Type Description
ValueError

If the term does not exist