# `ExDataSketch.Integration`
[🔗](https://github.com/thanos/ex_data_sketch/blob/main/lib/ex_data_sketch/integration.ex#L1)

Runtime dependency detection for optional integrations.

This module provides a unified interface for checking whether optional
dependencies (Broadway, Flow, CubDB, Ecto) are available at runtime.
It is used internally by integration modules to provide clear error
messages when a dependency is missing.

## Configuration

Optional dependencies can be explicitly disabled via
application config:

    config :ex_data_sketch, :integrations,
      broadway: false

Setting an integration to `true` does not override compile-time
availability. If the dependency is not loaded, `true` has no effect.
Setting to `false` always disables the integration regardless of
whether the dependency is loaded.

When not explicitly configured, availability defaults to whether the
dependency is loaded at compile time. This means adding a dependency
to `mix.exs` after compilation requires a full recompile
(`mix deps.compile`) for the availability check to return `true`.

## Supported Integrations

| Integration  | Dependency        | Always available? |
|-------------|-------------------|-------------------|
| GenStage    | `:gen_stage`       | No                |
| Broadway    | `:broadway`       | No                |
| Flow        | `:flow`           | No                |
| CubDB       | `:cubdb`          | No                |
| Ecto        | `:ecto_sql`       | No                |
| Mnesia      | OTP (always)      | Yes               |
| ETS         | OTP (always)      | Yes               |
| DETS        | OTP (always)      | Yes               |
| OpenTelemetry | `:opentelemetry_api` | No            |

# `broadway_available?`

```elixir
@spec broadway_available?() :: boolean()
```

Returns whether the Broadway library is available.

Checks compile-time availability and runtime configuration. Setting
`broadway: true` in config does not override compile-time unavailability.

## Examples

    iex> is_boolean(ExDataSketch.Integration.broadway_available?())
    true

# `cubdb_available?`

```elixir
@spec cubdb_available?() :: boolean()
```

Returns whether the CubDB library is available.

Checks compile-time availability and runtime configuration. Setting
`cubdb: [enabled: true]` in config does not override compile-time
unavailability.

## Examples

    iex> is_boolean(ExDataSketch.Integration.cubdb_available?())
    true

# `ecto_available?`

```elixir
@spec ecto_available?() :: boolean()
```

Returns whether the Ecto library is available.

Checks compile-time availability and runtime configuration. Setting
`ecto: [enabled: true]` in config does not override compile-time
unavailability.

## Examples

    iex> is_boolean(ExDataSketch.Integration.ecto_available?())
    true

# `flow_available?`

```elixir
@spec flow_available?() :: boolean()
```

Returns whether the Flow library is available.

Checks compile-time availability and runtime configuration. Setting
`flow: true` in config does not override compile-time unavailability.

## Examples

    iex> is_boolean(ExDataSketch.Integration.flow_available?())
    true

# `gen_stage_available?`

```elixir
@spec gen_stage_available?() :: boolean()
```

Returns whether the GenStage library is available.

Checks compile-time availability and runtime configuration. Setting
`gen_stage: true` in config does not override compile-time unavailability.

## Examples

    iex> is_boolean(ExDataSketch.Integration.gen_stage_available?())
    true

# `opentelemetry_available?`

```elixir
@spec opentelemetry_available?() :: boolean()
```

Returns whether the OpenTelemetry API library is available.

Checks compile-time availability and runtime configuration.

## Examples

    iex> is_boolean(ExDataSketch.Integration.opentelemetry_available?())
    true

# `require_broadway!`

```elixir
@spec require_broadway!() :: :ok
```

Raises an error if Broadway is not available.

Provides a clear error message directing the user to add the dependency.

## Examples

    iex> ExDataSketch.Integration.require_broadway!()
    :ok

    # When Broadway is not available:
    # ** (RuntimeError) Broadway integration requires the :broadway dependency.
    # Add {:broadway, "~> 1.0"} to your mix.exs dependencies.

# `require_cubdb!`

```elixir
@spec require_cubdb!() :: :ok
```

Raises an error if CubDB is not available.

Provides a clear error message directing the user to add the dependency.

## Examples

    iex> ExDataSketch.Integration.require_cubdb!()
    :ok

    # When CubDB is not available:
    # ** (RuntimeError) CubDB persistence requires the :cubdb dependency.
    # Add {:cubdb, "~> 2.0"} to your mix.exs dependencies.

# `require_ecto!`

```elixir
@spec require_ecto!() :: :ok
```

Raises an error if Ecto is not available.

Provides a clear error message directing the user to add the dependency.

## Examples

    iex> ExDataSketch.Integration.require_ecto!()
    :ok

    # When Ecto is not available:
    # ** (RuntimeError) Ecto persistence requires the :ecto_sql dependency.
    # Add {:ecto_sql, "~> 3.0"} to your mix.exs dependencies.

# `require_flow!`

```elixir
@spec require_flow!() :: :ok
```

Raises an error if Flow is not available.

Provides a clear error message directing the user to add the dependency.

## Examples

    iex> ExDataSketch.Integration.require_flow!()
    :ok

    # When Flow is not available:
    # ** (RuntimeError) Flow integration requires the :flow dependency.
    # Add {:flow, "~> 1.2"} to your mix.exs dependencies.

# `require_gen_stage!`

```elixir
@spec require_gen_stage!() :: :ok
```

Raises an error if GenStage is not available.

Provides a clear error message directing the user to add the dependency.

## Examples

    iex> ExDataSketch.Integration.require_gen_stage!()
    :ok

    # When GenStage is not available:
    # ** (RuntimeError) GenStage integration requires the :gen_stage dependency.
    # Add {:gen_stage, "~> 1.0"} to your mix.exs dependencies.

# `require_opentelemetry!`

```elixir
@spec require_opentelemetry!() :: :ok
```

Raises an error if OpenTelemetry is not available.

Provides a clear error message directing the user to add the dependency.

## Examples

    iex> ExDataSketch.Integration.require_opentelemetry!()
    :ok

    # When OpenTelemetry is not available:
    # ** (RuntimeError) OpenTelemetry integration requires the :opentelemetry_api dependency.
    # Add {:opentelemetry_api, "~> 1.0"} to your mix.exs dependencies.

---

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