Raxol.Database (Raxol v0.2.0)
View SourceProvides a safe interface for database operations.
This module:
- Wraps all database operations with retry logic
- Provides convenience functions for common database operations
- Handles database errors gracefully
Summary
Functions
Gets all records of a schema with retry logic.
Creates a record with retry logic.
Deletes a record with retry logic.
Gets a record by ID with retry logic.
Checks if the database connection is healthy.
Restarts the database connection if it becomes unhealthy.
Safely executes a database query with retry logic.
Executes a transaction with retry logic.
Updates a record with retry logic.
Functions
Gets all records of a schema with retry logic.
Parameters
schema- The schema moduleclauses- Optional where clauses
Returns
{:ok, records}- Records found{:error, reason}- Query failed
Creates a record with retry logic.
Parameters
schema- The schema moduleattrs- The attributes for the new record
Returns
{:ok, record}- Record created{:error, changeset}- Validation failed{:error, reason}- Query failed
Deletes a record with retry logic.
Parameters
record- The record to delete
Returns
{:ok, record}- Record deleted{:error, changeset}- Deletion validation failed{:error, reason}- Query failed
Gets a record by ID with retry logic.
Parameters
schema- The schema moduleid- The record ID
Returns
{:ok, record}- Record found{:error, :not_found}- Record not found{:error, reason}- Query failed
Checks if the database connection is healthy.
Returns
true- Connection is healthyfalse- Connection is unhealthy
Restarts the database connection if it becomes unhealthy.
Returns
:ok- Connection restart attempted
Safely executes a database query with retry logic.
Parameters
fun- Function containing database operations
Returns
{:ok, result}- Operation succeeded{:error, reason}- Operation failed after retries
Executes a transaction with retry logic.
Parameters
fun- Function containing transaction operations
Returns
{:ok, result}- Transaction succeeded{:error, reason}- Transaction failed
Updates a record with retry logic.
Parameters
schema- The schema modulerecord- The record to updateattrs- The new attributes
Returns
{:ok, record}- Record updated{:error, changeset}- Validation failed{:error, reason}- Query failed