Skip to content

Storage

The storage module provides a way to store and retrieve data from the backend database. We have abstracted it to provide a common interface to interact with the database. This allows us to switch between different databases without changing the code that interacts with the database.

Abstract Storage

redbox.storage.storage_handler.BaseStorageHandler

BaseStorageHandler()

Bases: ABC

Abstract Class for Storage Handler which manages all file and object IO the Redbox backend.

Initialise the storage handler

Source code in redbox-core/redbox/storage/storage_handler.py
20
21
22
@abstractmethod
def __init__(self):
    """Initialise the storage handler"""

model_type_map class-attribute instance-attribute

model_type_map = {lower(): _Cfor v in [Chunk, File]}

get_model_by_model_type

get_model_by_model_type(model_type)
PARAMETER DESCRIPTION
model_type

Source code in redbox-core/redbox/storage/storage_handler.py
17
18
def get_model_by_model_type(self, model_type):
    return self.model_type_map[model_type.lower()]

write_item abstractmethod

write_item(item)

Write an object to a data store

PARAMETER DESCRIPTION
item

TYPE: PersistableModel

Source code in redbox-core/redbox/storage/storage_handler.py
24
25
26
@abstractmethod
def write_item(self, item: PersistableModel):
    """Write an object to a data store"""

write_items abstractmethod

write_items(items)

Write a list of objects to a data store

PARAMETER DESCRIPTION
items

TYPE: list[PersistableModel]

Source code in redbox-core/redbox/storage/storage_handler.py
28
29
30
@abstractmethod
def write_items(self, items: list[PersistableModel]):
    """Write a list of objects to a data store"""

read_item abstractmethod

read_item(item_uuid, model_type)

Read an object from a data store

PARAMETER DESCRIPTION
item_uuid

TYPE: UUID

model_type

TYPE: str

Source code in redbox-core/redbox/storage/storage_handler.py
32
33
34
@abstractmethod
def read_item(self, item_uuid: UUID, model_type: str):
    """Read an object from a data store"""

read_items abstractmethod

read_items(item_uuids, model_type)

Read a list of objects from a data store

PARAMETER DESCRIPTION
item_uuids

TYPE: list[UUID]

model_type

TYPE: str

Source code in redbox-core/redbox/storage/storage_handler.py
36
37
38
@abstractmethod
def read_items(self, item_uuids: list[UUID], model_type: str):
    """Read a list of objects from a data store"""

update_item abstractmethod

update_item(item)

Update an object in a data store

PARAMETER DESCRIPTION
item

TYPE: PersistableModel

Source code in redbox-core/redbox/storage/storage_handler.py
40
41
42
@abstractmethod
def update_item(self, item: PersistableModel):
    """Update an object in a data store"""

update_items abstractmethod

update_items(items)

Update a list of objects in a data store

PARAMETER DESCRIPTION
items

TYPE: list[PersistableModel]

Source code in redbox-core/redbox/storage/storage_handler.py
44
45
46
@abstractmethod
def update_items(self, items: list[PersistableModel]):
    """Update a list of objects in a data store"""

delete_item abstractmethod

delete_item(item)

Delete an object from a data store

PARAMETER DESCRIPTION
item

TYPE: PersistableModel

Source code in redbox-core/redbox/storage/storage_handler.py
48
49
50
@abstractmethod
def delete_item(self, item: PersistableModel):
    """Delete an object from a data store"""

delete_items abstractmethod

delete_items(items)

Delete a list of objects from a data store

PARAMETER DESCRIPTION
items

TYPE: list[PersistableModel]

Source code in redbox-core/redbox/storage/storage_handler.py
52
53
54
@abstractmethod
def delete_items(self, items: list[PersistableModel]):
    """Delete a list of objects from a data store"""

list_all_items abstractmethod

list_all_items(model_type, user_uuid)

List all objects of a given type from a data store

PARAMETER DESCRIPTION
model_type

TYPE: str

user_uuid

TYPE: UUID

Source code in redbox-core/redbox/storage/storage_handler.py
56
57
58
@abstractmethod
def list_all_items(self, model_type: str, user_uuid: UUID):
    """List all objects of a given type from a data store"""

read_all_items abstractmethod

read_all_items(model_type, user_uuid)

Read all objects of a given type from a data store

PARAMETER DESCRIPTION
model_type

TYPE: str

user_uuid

TYPE: UUID

Source code in redbox-core/redbox/storage/storage_handler.py
60
61
62
@abstractmethod
def read_all_items(self, model_type: str, user_uuid: UUID):
    """Read all objects of a given type from a data store"""

get_file_chunks abstractmethod

get_file_chunks(parent_file_uuid, user_uuid)

get chunks for a given file

PARAMETER DESCRIPTION
parent_file_uuid

TYPE: UUID

user_uuid

TYPE: UUID

Source code in redbox-core/redbox/storage/storage_handler.py
64
65
66
@abstractmethod
def get_file_chunks(self, parent_file_uuid: UUID, user_uuid: UUID) -> list[Chunk]:
    """get chunks for a given file"""