Bardo.DBInterface (Bardo v0.1.0)

View Source

Database interface for Bardo.

This module provides a wrapper around the configured database adapter, allowing for seamless switching between different storage backends.

Usage

In your code, instead of directly calling Bardo.DB or Bardo.DBPostgres, use this module, which will automatically route calls to the configured adapter:

# Read a value
value = Bardo.DBInterface.read(id, :experiment)

# Write a value
:ok = Bardo.DBInterface.write(value, :experiment)

Configuration

In your config/config.exs:

# For ETS storage:
config :bardo, :db, adapter: Bardo.DB

# For PostgreSQL storage:
config :bardo, :db, adapter: Bardo.DBPostgres

Summary

Functions

Get the configured database adapter.

Create a backup of the database.

Delete a value from the database.

Fetch a value from the database.

List all values of a given type.

Read a value from the database.

Store a value in the database.

Write a value to the database.

Functions

adapter()

Get the configured database adapter.

backup(backup_path \\ "backups")

Create a backup of the database.

Parameters

  • backup_path: Directory to store the backup (default: "backups")

Returns

on success, {:error, reason} on failure.

delete(id, type)

Delete a value from the database.

Parameters

  • id: Unique identifier for the data
  • type: Type of data to delete (e.g., :experiment, :population, :genotype)

Returns

:ok on success, {:error, reason} on failure.

fetch(id, type)

Fetch a value from the database.

Parameters

  • id: Unique identifier for the data
  • type: Type of data to read (e.g., :experiment, :population, :genotype)

Returns

on success, {:error, reason} on failure.

list(type)

List all values of a given type.

Parameters

  • type: Type of data to list (e.g., :experiment, :population, :genotype)

Returns

List of values on success, [] on failure.

read(id, type)

Read a value from the database.

Parameters

  • id: Unique identifier for the data
  • type: Type of data to read (e.g., :experiment, :population, :genotype)

Returns

The value if found, nil otherwise.

store(type, id, value)

Store a value in the database.

Parameters

  • type: Type of data being stored (e.g., :experiment, :population, :genotype)
  • id: Unique identifier for the data
  • value: The data to store

Returns

:ok on success, {:error, reason} on failure.

write(value, table)

Write a value to the database.

Parameters

  • value: The value to store (must have an :id field in its data map)
  • table: The table/type to write to

Returns

:ok on success, {:error, reason} on failure.