database
DataStore
DataStore(location: str = None, extension: str = '.txt', glob_extension: str = None, load_file: Callable = None, save_file: Callable = None, sql=None, log: Logger = logger)
Stores data (currently in a directory) for a singular type of data with particular load and save behaviors
Parameters:
-
location
(str
, default:None
) –The location to store/retrieve data if directories are used
-
extension
(str
, default:'.txt'
) –The extension of files to use during file handling. If extension is other than .txt or .json, the arguments load_file/save_file must be provided to handle storage
-
load_file
(Callable
, default:None
) –Callable taking the file_name as first argument
-
save_file
(Callable
, default:None
) –Callable taking the object to save as first argument and file_name as second argument
-
sql
–The database to use if the storage is based on a SQL database
-
log
(Logger
, default:logger
) –The Logger to handle operation reporting
Source code in symdesign/resources/database.py
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 |
|
make_path
make_path(condition: bool = True)
Make all required directories in specified path if it doesn't exist, and optional condition is True
Parameters:
-
condition
(bool
, default:True
) –A condition to check before the path production is executed
Source code in symdesign/resources/database.py
112 113 114 115 116 117 118 119 |
|
path_to
path_to(name: str = '*') -> AnyStr
Return the path_to the storage location given an entity name
Source code in symdesign/resources/database.py
121 122 123 |
|
glob_path
glob_path(name: str = '*') -> AnyStr
Return the glob_path of the storage location given an entity name
Source code in symdesign/resources/database.py
125 126 127 |
|
retrieve_file
retrieve_file(name: str) -> AnyStr | None
Returns the actual location by combining the requested name with the stored .location
Source code in symdesign/resources/database.py
129 130 131 132 133 134 135 136 137 138 139 140 |
|
retrieve_files
retrieve_files() -> list
Returns the actual location of all files in the stored .location
Source code in symdesign/resources/database.py
142 143 144 145 146 147 148 |
|
retrieve_names
retrieve_names() -> list[str]
Returns the names of all objects in the stored .location
Source code in symdesign/resources/database.py
150 151 152 153 154 155 156 |
|
store_data
store_data(data: Any, name: str, **kwargs)
Store the data specfied by data and name to the DataStore. Saves the data as well
Parameters:
-
data
(Any
) –The data object to be stored with name
-
name
(str
) –The name of the data to be used
Sets
self.name = data
Source code in symdesign/resources/database.py
158 159 160 161 162 163 164 165 166 167 168 169 |
|
retrieve_data
retrieve_data(name: str = None) -> Any | None
Return the data requested by name. Otherwise, load into the Database from a specified location
Parameters:
-
name
(str
, default:None
) –The name of the data to be retrieved. Will be found with location and extension attributes
Returns:
-
Any | None
–If the data is available, the object requested will be returned, else None
Source code in symdesign/resources/database.py
171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 |
|
load_data
load_data(name: str, **kwargs) -> Any | None
Return the data located in a particular entry specified by name
Parameters:
-
name
(str
) –The name of the data to be used
Returns:
-
Any | None
–The data found at the requested name if any
Source code in symdesign/resources/database.py
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
|
load_all_data
load_all_data(**kwargs)
Loads all data located in the particular DataStore storage location
Source code in symdesign/resources/database.py
229 230 231 232 233 234 235 236 |
|
Database
Database(sql=None, log: Logger = logger)
A common interface to interact with DataStore instances
Parameters:
-
sql
–The database to use if the storage is based on a SQL database
-
log
(Logger
, default:logger
) –The Logger to handle operation reporting
Source code in symdesign/resources/database.py
243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
load_all_data
load_all_data()
For every resource, acquire all existing data in memory
Source code in symdesign/resources/database.py
258 259 260 261 262 263 264 265 |
|
source
source(name: str) -> DataStore
Return on of the various DataStores supported by the Database
Parameters:
-
name
(str
) –The name of the data source to use
Source code in symdesign/resources/database.py
267 268 269 270 271 272 273 274 275 276 277 278 |
|
retrieve_data
retrieve_data(source: str = None, name: str = None) -> Any | None
Return the data requested by name from the specified source. Otherwise, load into the Database from a specified location
Parameters:
-
source
(str
, default:None
) –The name of the data source to use
-
name
(str
, default:None
) –The name of the data to be retrieved. Will be found with location and extension attributes
Returns:
-
Any | None
–If the data is available, the object requested will be returned, else None
Source code in symdesign/resources/database.py
280 281 282 283 284 285 286 287 288 289 290 291 |
|
retrieve_file
retrieve_file(source: str = None, name: str = None) -> AnyStr | None
Retrieve the file specified by the source and identifier name
Parameters:
-
source
(str
, default:None
) –The name of the data source to use
-
name
(str
, default:None
) –The name of the data to be retrieved. Will be found with location and extension attributes
Returns:
-
AnyStr | None
–If the file is available, it will be returned, else None
Source code in symdesign/resources/database.py
293 294 295 296 297 298 299 300 301 302 303 |
|
read_file
read_file(file, **kwargs) -> list[AnyStr]
The simplest form of parsing a file encoded in ASCII characters
Source code in symdesign/resources/database.py
17 18 19 20 |
|
write_str_to_file
write_str_to_file(string, file_name, **kwargs) -> AnyStr
Use standard file IO to write a string to a file
Parameters:
-
string
–The string to write
-
file_name
–The location of the file to write
Returns:
-
AnyStr
–The name of the written file
Source code in symdesign/resources/database.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
|
write_list_to_file
write_list_to_file(_list, file_name, **kwargs) -> AnyStr
Use standard file IO to write a string to a file
Parameters:
-
_list
–The string to write
-
file_name
–The location of the file to write
Returns:
-
AnyStr
–The name of the written file
Source code in symdesign/resources/database.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
|