InfluxElixir.Client behaviour (InfluxElixir v0.1.17)

Copy Markdown View Source

Behaviour defining the InfluxDB client contract.

All library modules use this behaviour — never a concrete implementation directly. The implementation is selected via application configuration:

# config/config.exs (default: production HTTP client)
config :influx_elixir, :client, InfluxElixir.Client.HTTP

# config/test.exs (test: LocalClient)
config :influx_elixir, :client, InfluxElixir.Client.Local

Implementations

Connection Lifecycle

Each implementation defines how connections are created and destroyed:

  • init_connection/1 — converts raw keyword config into the implementation's native connection type. Called by ConnectionSupervisor during startup.

    • Client.HTTP returns the keyword config as-is
    • Client.Local creates an ETS table and returns a conn map
  • shutdown_connection/1 — cleans up resources when a connection is removed. Called by InfluxElixir.remove_connection/1.

    • Client.HTTP is a no-op (Finch pool has its own supervisor)
    • Client.Local deletes the ETS table

Canonical Connection Config Schema

Every implementation must accept the same keys from init_connection/1 so a config is a drop-in replacement across implementations. See InfluxElixir.Config for the canonical schema. Keys consumed by both implementations:

  • :database — connection-level default database name. When the caller does not pass database: in opts, this value is used.
  • :databases — list of database names. Client.Local pre-creates each; Client.HTTP defaults :database to the first item when :database is not set.
  • :profileClient.Local only; ignored by Client.HTTP.

Implementations must not silently ignore the singular :database key.

Summary

Functions

Returns the configured client implementation module.

Types

connection()

@type connection() :: term()

query_result()

@type query_result() :: {:ok, [map()]} | {:error, term()}

write_result()

@type write_result() :: {:ok, :written} | {:error, term()}

Callbacks

create_bucket(connection, binary, keyword)

@callback create_bucket(connection(), binary(), keyword()) :: :ok | {:error, term()}

create_database(connection, binary, keyword)

@callback create_database(connection(), binary(), keyword()) :: :ok | {:error, term()}

create_token(connection, binary, keyword)

@callback create_token(connection(), binary(), keyword()) ::
  {:ok, map()} | {:error, term()}

delete_bucket(connection, binary)

@callback delete_bucket(connection(), binary()) :: :ok | {:error, term()}

delete_database(connection, binary)

@callback delete_database(connection(), binary()) :: :ok | {:error, term()}

delete_token(connection, binary)

@callback delete_token(connection(), binary()) :: :ok | {:error, term()}

execute_sql(connection, binary, keyword)

@callback execute_sql(connection(), binary(), keyword()) ::
  {:ok, map()} | {:error, term()}

health(connection)

@callback health(connection()) :: {:ok, map()} | {:error, term()}

init_connection(keyword)

@callback init_connection(keyword()) :: {:ok, connection()} | {:error, term()}

list_buckets(connection)

@callback list_buckets(connection()) :: {:ok, [map()]} | {:error, term()}

list_databases(connection)

@callback list_databases(connection()) :: {:ok, [map()]} | {:error, term()}

query_flux(connection, binary, keyword)

@callback query_flux(connection(), binary(), keyword()) :: query_result()

query_influxql(connection, binary, keyword)

@callback query_influxql(connection(), binary(), keyword()) :: query_result()

query_sql(connection, binary, keyword)

@callback query_sql(connection(), binary(), keyword()) :: query_result()

query_sql_stream(connection, binary, keyword)

@callback query_sql_stream(connection(), binary(), keyword()) :: Enumerable.t()

shutdown_connection(connection)

@callback shutdown_connection(connection()) :: :ok

write(connection, binary, keyword)

@callback write(connection(), binary(), keyword()) :: write_result()

Functions

impl()

@spec impl() :: module()

Returns the configured client implementation module.

Defaults to InfluxElixir.Client.HTTP if not configured.