InfluxElixir.Query.SQL (InfluxElixir v0.1.35)

Copy Markdown View Source

v3 SQL query builder and executor.

Supports parameterized queries with $param placeholders and multiple response formats (JSON, JSONL, CSV, Parquet).

Parameterized Queries

Always use $param placeholders to prevent injection:

InfluxElixir.Query.SQL.query(conn,
  "SELECT * FROM prices WHERE symbol = $symbol",
  params: %{symbol: "BTC-USD"}
)

Response Formats

Supported via the :format option:

  • :json — default, returns parsed list of maps
  • :jsonl — newline-delimited JSON
  • :csv — rows whose values are the engine's CSV strings ("1.5", "1e16", "true"); timestamps are still DateTimes and an empty cell is absent, as a null column is in JSON. A nested value (array_agg, a selector_* struct) cannot be written as CSV: the server closes the connection, {:error, {:connection_error, _}}
  • :parquet — Apache Parquet binary (Client.Local refuses it by name)

Transport

Use :transport option to select query transport:

  • :http — default, via Finch HTTP client
  • :flight — via Arrow Flight gRPC

Summary

Functions

Sends a SQL statement as it is; see InfluxElixir.execute_sql/3 for what InfluxDB 3 accepts (Core refuses DML and DDL).

Executes a SQL query and returns parsed results.

Executes a SQL query and returns a lazy Stream.

Types

format()

@type format() :: :json | :jsonl | :csv | :parquet

transport()

@type transport() :: :http | :flight

Functions

execute(connection, sql, opts \\ [])

@spec execute(
  InfluxElixir.Client.connection(),
  binary(),
  keyword()
) :: {:ok, map() | [map()]} | {:error, term()}

Sends a SQL statement as it is; see InfluxElixir.execute_sql/3 for what InfluxDB 3 accepts (Core refuses DML and DDL).

Options

  • :params - parameter map for $param substitution
  • :database - override the default database

query(connection, sql, opts \\ [])

Executes a SQL query and returns parsed results.

Options

  • :params - parameter map for $param substitution
  • :database - override the default database
  • :format - response format (default: :json)
  • :transport - query transport (default: :http)

query_stream(connection, sql, opts \\ [])

@spec query_stream(
  InfluxElixir.Client.connection(),
  binary(),
  keyword()
) :: Enumerable.t()

Executes a SQL query and returns a lazy Stream.

For large result sets to avoid loading all rows into memory.

Options

Same as query/3.