| | |
- builtins.object
-
- Storage
class Storage(builtins.object) |
| |
A utility class for saving, loading, and deleting database files. |
| |
Static methods defined here:
- backup(db, key=None, compress=False, dir=None, date=False)
- Backup the database to a file.
If none exists, a folder named 'backups_' + db.name will be created in the directory.
The database object is serialized into a JSON format and written to the specified file.
Each backup file is named 'db.name_backup_n.segadb', where n is the number of backups in the directory.
Args:
db (Database): The database object to be saved.
key (bytes, optional): The encryption key. If provided, the data will be encrypted before saving.
compress (bool, optional): If True, the data will be compressed using zlib before saving.
dir (str, optional): The directory where the backup will be saved. Default is None.
date (bool, optional): If True, the date will be appended to the filename. Default is False.
Returns:
status (str): The status of the backup operation, as well as the path to the backup file.
- db_to_dict(db)
- Convert a database object to a dictionary.
Args:
db (Database): The database object to be converted.
Returns:
dict: A dictionary representation of the database object
- decrypt(data, key)
- Decrypt the data using the provided key.
- delete(filename)
- Delete the specified file from the filesystem.
Args:
filename (str): The path to the file to be deleted.
- encrypt(data, key)
- Encrypt the data using the provided key.
- generate_key()
- Generate a key for encryption.
- list_backups(dir=None, print_output=True)
- List the backup files in the specified directory.
Args:
dir (str, optional): The directory to search for backup files. Default is None.
Returns:
list: A list of the backup files in the directory.
- load(filename, key=None, user=None, password=None, compression=False, parrallel=False)
- Load a database from a JSON file.
Args:
filename (str): The path to the JSON file containing the database data.
key (bytes, optional): The encryption key. If provided, the data will be decrypted after loading.
compression (bool, optional): If True, the data will be decompressed using zlib after loading.
parrallel (bool, optional): If True, the data will be loaded in parallel using multiprocessing.
Returns:
Database: An instance of the Database class populated with the data from the JSON file.
- restore(db, key=None, compress=False, user=None, password=None, dir=None, backup_name=None)
- Restore a database from a backup file.
Args:
db (Database): The database object to be restored.
key (bytes, optional): The encryption key. If provided, the data will be decrypted after loading.
compress (bool, optional): If True, the data will be decompressed using zlib after loading.
user (str, optional): The username for authentication. Defaults to None.
password (str, optional): The password for authentication. Defaults to None.
dir (str, optional): The directory where the backup is saved. Default is None.
backup_name (str, optional): The name of the backup file. Default is None. Will use the latest backup if None.
Returns:
Database: An instance of the Database class populated with the data from the backup file.
- save(db, filename, key=None, compress=False)
- Save the database object to a JSON file.
The database object is serialized into a JSON format and written to the specified file.
The JSON structure includes the database name, tables, columns, records, next_id, and constraints.
Args:
db (Database): The database object to be saved.
filename (str): The path to the file where the database will be saved.
key (bytes, optional): The encryption key. If provided, the data will be encrypted before saving.
compress (bool, optional): If True, the data will be compressed using zlib before saving.
- save_table(table, filename, format='csv')
- Save the table to a file in the specified format.
Args:
table (Table): The table object to be saved.
filename (str): The path to the file where the table will be saved.
format (str): The format in which the table will be saved. Default is 'csv'.
Data descriptors defined here:
- __dict__
- dictionary for instance variables
- __weakref__
- list of weak references to the object
| |