BaseDB
hololinked.storage.bases.BaseDB
Bases: BaseConfigurationRepository
Base class for database engine based configuration management.
Implements common functionality like loading DB configuration and context management for batch calls.
Specific database engines should inherit from this class and implement the required methods from
BaseConfigurationRepository.
Source code in repo/hololinked/hololinked/storage/bases.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | |
Attributes
config
instance-attribute
config = load_conf(config_file=config_file, default_file_path=join(TEMP_DIR_DB, get_sanitized_filename_from_random_string(f'{__name__}.{id}', extension='db')))
Functions
__init__
Initialize the BaseDB instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Thing
|
The |
required |
|
str | None
|
Path to the database configuration file. |
None
|
Source code in repo/hololinked/hololinked/storage/bases.py
from_thing
classmethod
Build the database engine for a Thing, taking its configuration from the db_config_file argument.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
Thing
|
the |
required |
|
Any
|
the keyword arguments given to the |
{}
|
Returns:
| Type | Description |
|---|---|
Self
|
the database engine, connected and ready to use |
Source code in repo/hololinked/hololinked/storage/bases.py
load_conf
staticmethod
load_conf(config_file: str | None, default_file_path: str = '') -> SQLDBConfig | SQLiteConfig | MongoDBConfig
Load configuration file using JSON serializer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
|
str | None
|
path to configuration file, expected to be in JSON format with fields according to the config classes. |
required |
|
str
|
fallback file path if config_file is not provided, only used for SQLiteConfig, default is empty string which leads to a DB with name of thing ID |
''
|
Returns:
| Type | Description |
|---|---|
SQLDBConfig | SQLiteConfig | MongoDBConfig
|
configuration object according to the provider specified in the config file |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
if the provider specified in the config file is not supported |
ValueError
|
if the config file is not in JSON format |