EffortlessConfig

EffortlessConfig is the configuration class for EffortlessDB. It holds various configuration options for an EffortlessDB instance.

Properties

required_fields

Require fields for each entry in the DB.

config = EffortlessConfig(required_fields=["id"]) db.configure(config) db.add({}) # Error: Field 'id' is required

backup_path

Make the database automatically back up to the specified path.

config = EffortlessConfig(backup="/folder/backups/") db.configure(config) db.add({"data": True}) print(os.path.exists("/folder/backups/db.effortless")) True

backup_interval

Set the number of operations that occurs before each backup. Backups occur every after operation by default, but can be spaced out to improve performance.

max_size

Set the maximum size of the database in MB. Any changes to the database that would make it exceed this size will fail. There is no limit by default.

readonly

Set the database to read-only mode. In this mode, the entries of the database cannot be modified, but the configuration can be, so this change is revertable.

compressed

Set whether or not the database should be compressed. You may want to compress the database to conserve space, but it will take more time to read/write to it.

debug

Enable debug mode for verbose output. Defaults to False.

encrypted

Set whether or not the database should be encrypted or not. You will need to specify a key to encrypt and decrypt the database, but this feature is not implemented yet.

version

The internal version of the database. This is used for automatic migration between versions of Effortless.

Methods

__init__

Creates an EffortlessConfig with any specified configuration options.

config = EffortlessConfig(compressed=True, required_field=["name"])

to_dict

Converts the configuration to a dictionary representation. You can use this to save a config or edit a config as a dict before re-applying it.

config_dict = config.to_dict() for opt in config_dict: ‎ ...

from_dict

Converts a dictionary into an EffortlessConfig object.

config = EffortlessConfig.from_dict({"readonly": True})

validate_db

Checks if the given database follows the configured rules. Raises ValueError if anything doesn't follow. This must pass for a new configuration to be applied to a database.

EffortlessDB Fields