Exports data from database tables for DB Sync module.
Provides functions to fetch records from tables with pagination, handle data serialization, and stream large datasets.
Security Considerations
- Uses parameterized queries to prevent SQL injection
- Validates table names against actual database tables
- Respects configured table whitelist/blacklist (future feature)
Example
iex> DataExporter.get_count("users")
{:ok, 150}
iex> DataExporter.fetch_records("users", offset: 0, limit: 100)
{:ok, [
%{"id" => 1, "email" => "user@example.com", ...},
...
]}
Summary
Functions
Fetches records from a table with pagination.
Gets the exact count of records in a table.
Exports all records from a table as a stream.
Functions
Fetches records from a table with pagination.
Records are returned as maps with string keys matching column names. All values are JSON-serializable.
Options
:offset- Number of records to skip (default: 0):limit- Maximum records to return (default: 100, max: 1000):schema- Database schema (default: "public"):order_by- Column(s) to order by (default: primary key)
@spec get_count( String.t(), keyword() ) :: {:ok, non_neg_integer()} | {:error, any()}
Gets the exact count of records in a table.
Options
:schema- Database schema (default: "public")
@spec stream_records( String.t(), keyword() ) :: {:ok, Enumerable.t()} | {:error, any()}
Exports all records from a table as a stream.
Useful for large tables where loading all records into memory is not practical. Returns a stream that yields batches of records.
Options
:batch_size- Records per batch (default: 500):schema- Database schema (default: "public")