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.LocalImplementations
InfluxElixir.Client.HTTP— production Finch-based clientInfluxElixir.Client.Local— in-memory ETS-backed test client
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 byConnectionSupervisorduring startup.Client.HTTPreturns the keyword config as-isClient.Localcreates an ETS table and returns a conn map
shutdown_connection/1— cleans up resources when a connection is removed. Called byInfluxElixir.remove_connection/1.Client.HTTPis a no-op (Finch pool has its own supervisor)Client.Localdeletes 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 passdatabase:in opts, this value is used.:databases— list of database names.Client.Localpre-creates each;Client.HTTPdefaults:databaseto the first item when:databaseis not set.:profile—Client.Localonly; ignored byClient.HTTP.
Implementations must not silently ignore the singular :database key.
Summary
Types
Callbacks
@callback create_bucket(connection(), binary(), keyword()) :: :ok | {:error, term()}
@callback create_database(connection(), binary(), keyword()) :: :ok | {:error, term()}
@callback create_token(connection(), binary(), keyword()) :: {:ok, map()} | {:error, term()}
@callback delete_bucket(connection(), binary()) :: :ok | {:error, term()}
@callback delete_database(connection(), binary()) :: :ok | {:error, term()}
@callback delete_token(connection(), binary()) :: :ok | {:error, term()}
@callback execute_sql(connection(), binary(), keyword()) :: {:ok, map()} | {:error, term()}
@callback health(connection()) :: {:ok, map()} | {:error, term()}
@callback init_connection(keyword()) :: {:ok, connection()} | {:error, term()}
@callback list_buckets(connection()) :: {:ok, [map()]} | {:error, term()}
@callback list_databases(connection()) :: {:ok, [map()]} | {:error, term()}
@callback query_flux(connection(), binary(), keyword()) :: query_result()
@callback query_influxql(connection(), binary(), keyword()) :: query_result()
@callback query_sql(connection(), binary(), keyword()) :: query_result()
@callback query_sql_stream(connection(), binary(), keyword()) :: Enumerable.t()
@callback shutdown_connection(connection()) :: :ok
@callback write(connection(), binary(), keyword()) :: write_result()
Functions
@spec impl() :: module()
Returns the configured client implementation module.
Defaults to InfluxElixir.Client.HTTP if not configured.