# `PhoenixKit.Modules.Sync.DataExporter`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/sync/data_exporter.ex#L1)

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", ...},
      ...
    ]}

# `fetch_records`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/sync/data_exporter.ex#L75)

```elixir
@spec fetch_records(
  String.t(),
  keyword()
) :: {:ok, [map()]} | {:error, any()}
```

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)

# `get_count`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/sync/data_exporter.ex#L40)

```elixir
@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")

# `stream_records`
[🔗](https://github.com/BeamLabEU/phoenix_kit/blob/v1.7.63/lib/modules/sync/data_exporter.ex#L105)

```elixir
@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")

---

*Consult [api-reference.md](api-reference.md) for complete listing*
