API

Database

class SSD.Core.Storage.Database.Database(database_dir: str = '', database_name: str = 'database')[source]
__init__(database_dir: str = '', database_name: str = 'database')[source]

Manage the creation and loading of Tables in the Database. User interface to dynamically add, get and update entries.

Parameters:
  • database_dir – Directory which contains the Database file.

  • database_name – Name of the Database file.

add_batch(table_name: str, batch: Dict[str, List[Any]])[source]

Execute a batch insert query.

Parameters:
  • table_name – Name of the Table.

  • batch – New lines of the Table.

add_data(table_name: str, data: Dict[str, Any])[source]

Execute a line insert query.

Parameters:
  • table_name – Name of the Table.

  • data – New line of the Table.

close(erase_file: bool = False)[source]

Close the Database.

Parameters:

erase_file – If True, the Database file will be erased.

connect_signals()[source]

Connect the registered signals between Tables and handlers.

create_fields(table_name: str, fields: Tuple[str, Type] | Tuple[str, Type, Any] | Tuple[str, str] | List[Tuple[str, Type] | Tuple[str, Type, Any] | Tuple[str, str]])[source]

Add new Fields to a Table.

Parameters:
  • table_name – Name of the Table on which to add the new Fields.

  • fields – Name(s), type(s) and default value(s) of the Field(s) to add to the Table.

create_table(table_name: str, storing_table: bool = True, fields: Tuple[str, Type] | Tuple[str, Type, Any] | Tuple[str, str] | List[Tuple[str, Type] | Tuple[str, Type, Any] | Tuple[str, str]] | None = None)[source]

Add a new Table to the Database with customizable Fields.

Parameters:
  • table_name – Name of the Table to add to the Database.

  • storing_table – Specify whether the Table must be a storing or an exchange Table.

  • fields – Name(s), type(s) and default value(s) of the Field(s) to add to the Table.

get_architecture()[source]

Get the content of the Database with Table(s) and their Field(s).

get_fields(table_name: str, only_names: bool = True)[source]

Get the names of the Field(s) of a Tables of the Database.

Parameters:
  • table_name – Name of the Table.

  • only_names – If False, returns a dict containing {‘table_name’: Table}.

get_line(table_name: str, fields: str | List[str] | None = None, line_id: int = -1, joins: str | List[str] | None = None)[source]

Get a line of a Table.

Parameters:
  • table_name – Name of the Table on which to perform the query.

  • fields – Name(s) of the Field(s) to request.

  • line_id – Index of the line to get.

  • joins – Name(s) of Table(s) to join to the selection.

get_lines(table_name: str, fields: str | List[str] | None = None, lines_id: List[int] | None = None, lines_range: List[int] | None = None, joins: str | List[str] | None = None, batched: bool = False)[source]

Get a set of lines of a Table.

Parameters:
  • table_name – Name of the Table on which to perform the query.

  • fields – Name(s) of the Field(s) to select.

  • lines_id – Indices of the lines to get. If not specified, ‘lines_range’ value will be used.

  • lines_range – Range of indices of the lines to get. If not specified, all lines will be selected.

  • joins – Name(s) of Table(s) to join to the selection.

  • batched – If True, data is returned as one batch per field. Otherwise, data is returned as list of lines.

get_path()[source]

Access the Database file path.

get_tables(only_names: bool = True)[source]

Get the names of created Tables in the Database.

Parameters:

only_names – If True, only the names of the Tables will be returned in a List, otherwise the Tables themselves are returned in a Dict.

load(show_architecture: bool = False)[source]

Load an existing Database file.

Parameters:

show_architecture – If True, the loaded models will be printed.

static make_name(table_name: str)[source]

Harmonize the Table names.

Parameters:

table_name – Name of the Table.

property memory_size

Return the Database file memory size in bytes.

nb_lines(table_name: str)[source]

Return the number of entries on a Table.

Parameters:

table_name – Name of the Table.

new(remove_existing: bool = False)[source]

Create a new Database file.

Parameters:

remove_existing – If True, Database file will be overwritten.

print_architecture()[source]

Print the content of the Database with Table(s) and their Field(s).

register_post_save_signal(table_name: str, handler: Callable, name: str | None = None)[source]

Connect a post_save signal from a Table to a handler.

Parameters:
  • table_name – Name of the Table that will be sender.

  • handler – Executable code.

  • name – Name of the signal.

register_pre_save_signal(table_name: str, handler: Callable, name: str | None = None)[source]

Connect a pre_save signal from a Table to a handler.

Parameters:
  • table_name – Name of the Table that will be sender.

  • handler – Executable code.

  • name – Name of the signal.

remove_field(table_name: str, field_name: str)[source]

Remove a Field of a Table of the Database.

Parameters:
  • table_name – Name of the Table.

  • field_name – Current name of the Field to remove.

remove_table(table_name: str)[source]

Remove a Table from the Database.

Parameters:

table_name – Name of the Table.

rename_field(table_name: str, field_name: str, new_field_name: str)[source]

Rename a Field of a Table of the Database.

Parameters:
  • table_name – Name of the Table.

  • field_name – Current name of the Field to rename.

  • new_field_name – New name of the Field.

rename_table(table_name: str, new_table_name: str)[source]

Rename a Table of the Database.

Parameters:
  • table_name – Current name of the Table to rename.

  • new_table_name – New name of the Table.

update(table_name: str, data: Dict[str, Any], line_id: int = -1)[source]

Update a line of a Table.

Parameters:
  • table_name – Name of the Table on which to perform the query.

  • data – Updated data of the line.

  • line_id – Index of the line to update.

Utils

SSD.Core.Storage.utils.merge(database_names: List[str], new_database_name: str = 'merged', remove_existing: bool = False)[source]

Merge Databases in a new Database.

Parameters:
  • database_names – List of Databases files.

  • new_database_name – Name of the new Database.

  • remove_existing – If True, Database file with name ‘new_database_name’ will be overwritten.

SSD.Core.Storage.utils.remove_field(database_name: str, table_name: str, fields: str | List[str])[source]

Remove Fields of a Table of the Database.

Parameters:
  • database_name – Database filename.

  • table_name – Name of the Table.

  • fields – Field(s) to remove from the Table.

SSD.Core.Storage.utils.remove_table(database_name: str, table_names: str | List[str])[source]

Remove Tables of the Database.

Parameters:
  • database_name – Database filename.

  • table_names – Table(s) to remove from the Database.

SSD.Core.Storage.utils.rename_fields(database_name: str, table_name: str, renamed_fields: Tuple[str, str] | List[Tuple[str, str]])[source]

Rename Fields of a Table of the Database.

Parameters:
  • database_name – Database filename.

  • table_name – Name of the Table.

  • renamed_fields – Tuple or list of tuples defined as (‘old_name’, ‘new_name’).

SSD.Core.Storage.utils.rename_tables(database_name: str, renamed_tables: Tuple[str, str] | List[Tuple[str, str]])[source]

Rename Tables of the Database.

Parameters:
  • database_name – Database filename.

  • renamed_tables – Tuple or list of tuples defined as (‘old_name’, ‘new_name’).