Bardo.DB (Bardo v0.1.0)
View SourceA simple, efficient database for the Bardo neuroevolution system.
Uses ETS (Erlang Term Storage) for in-memory storage with periodic backups. This implementation is designed for efficiency and simplicity, making it ideal for use as a library dependency in other projects.
Summary
Functions
Back up the database to disk.
Returns a specification to start this module under a supervisor.
Delete a value from the database.
Check if a key exists in the database.
Fetch a value from the database.
List all values for a specific table type.
Read a value from the database using the models format.
Restore the database from a backup file.
Start the database server.
Store a value in the database.
Write a value to the database using the models format.
Functions
Back up the database to disk.
Parameters
backup_path
- Directory to store the backup (default: "backups")
Returns
{:ok, backup_file}
on success{:error, reason}
on failure
Returns a specification to start this module under a supervisor.
See Supervisor
.
Delete a value from the database.
Parameters
table
- The table to delete fromkey
- The key to delete
Check if a key exists in the database.
Parameters
table
- The table to checkkey
- The key to check
Returns
true
if the key existsfalse
if the key doesn't exist
Fetch a value from the database.
Parameters
table
- The table to fetch fromkey
- The key to fetch
Returns
{:ok, value}
on success{:error, :not_found}
if the key doesn't exist
List all values for a specific table type.
Parameters
table
- The table to list values from
Returns
{:ok, [values]}
on success{:ok, []}
if the table is empty
Read a value from the database using the models format.
This is a compatibility function for code that uses the Models module.
Parameters
id
- The ID to readtable
- The table to read from
Returns
- The value if found
:not_found
if the key doesn't exist
Restore the database from a backup file.
Parameters
backup_file
- Path to the backup file
Returns
:ok
on success{:error, reason}
on failure
Start the database server.
Options
:auto_backup
- Whether to run automatic backups (default: true):backup_dir
- Directory to store backups (default: "backups")
Store a value in the database.
Parameters
table
- The table to store the value in (e.g., :experiment, :population)key
- The key to store the value undervalue
- The value to store
Write a value to the database using the models format.
This is a compatibility function for code that uses the Models module.
Parameters
value
- The model value to writetable
- The table to write to