EffortlessDB
EffortlessDB is the main class for interacting with the Effortless database. It provides methods for initializing, configuring, and performing operations on the database.
Properties
config
An EffortlessConfig object that holds the configuration settings for the database.
encryption_key
The encryption key (password) used to encrypt and decrypt the database.
Methods
__init__
Initializes an EffortlessDB instance with the given database name. If no name is provided, it defaults to "db". For example, passing in "users" will create a database with the file "users.effortless" in the current directory. If an encryption_key is provided, it will be used to encrypt/decrypt the database.
add
Adds a new entry to the database. The entry must be a JSON-serializable dictionary that follows the configured rules of the database.
update
Updates a single entry in the database that matches the
given condition. The condition must match only one
entry; if you want to update multiple entries at once,
use batch()
. Returns True if an entry was
updated, or False otherwise.
remove
Removes a single entry in the database that matches the
given condition. The condition must match only one
entry; if you want to update multiple entries at once,
use erase()
. Returns True if an entry was
removed, or False otherwise.
get_all
Retrieves all entries from the database, returning a list where each item is an entry in the database.
filter
Filters the database records based on a given Field object, returning a list of records that match the field condition.
batch
Updates all entries in the database that match the given condition. Returns the number of entries that were updated.
erase
Erases all entries from the database that match the given condition. Returns the number of entries that were removed.
wipe
Clears all data from the database, resetting it to its initial state. You cannot wipe a read-only database unless you explicitly set override to True.
configure
Updates the database configuration to reflect a new EffortlessConfig object.
encrypt
Sets a new encryption key and re-encrypts the database if necessary. If the database is already encrypted, this method will attempt to decrypt with both the old and new keys, then re-encrypt with the new key.
unencrypt
Permanently unencrypts the database using the encryption key if the database is currently encrypted. Raises a ValueError if an encryption key is not set.
set_directory
Sets the directory for writing and reading the database file; the directory must exist. The database will be saved to the new directory immediately.
set_storage
Sets the storage filename for the database. The actual file will be named 'db_name.effortless'. You must pass in a valid filename with no special characters. You should probably pass the filename into __init__ instead.
finish_backup
Stops processing until any ongoing backup operation to complete or the timeout is reached. Returns True if the backup completed (or there was no backup running), or returns False if the timeout was reached before the backup completed.