Timeseries Database

The Influx class provides a client for interacting with an InfluxDB database, which is a database specifically designed for storing and querying time-series data (e.g., sensor readings, application metrics, financial data). This class simplifies common operations like reading, querying, and deleting time-stamped data points.

Heisenware ships with a pre-initialized timeseries database, which you can directly use without calling create. The instance is called: internal-influx and is always available:

In case you want to connect to another database, you have to create an instance first.

create

Creates an instance of the InfluxDB client, configuring it to connect to a specific database URL with the necessary credentials.

If you want to use the internal timeseries database, this step is not needed. Simply use the functions available under the existing instance named internal-influx.

Parameters

  • url: The URL of your InfluxDB instance (e.g., http://localhost:8086).

  • token: The authentication token with the required permissions for your organization and buckets.

  • org: The name of the organization in InfluxDB.

Example

# url
http://localhost:8086
# token
my-super-secret-auth-token-g9_xyz==
# org
my-organization

read

Reads time-series data from a specific bucket and measurement, with powerful options for filtering by time, limiting results, and aggregating data into time windows.

Internal Database Bucket Names

When reading from the internal Heisenware database, the bucket name reflects the retention policy of the measurement and must be one of: F (Forever), Y (Year), M (Month), W (Week), D (Day), or H (Hour).

Parameters

  • bucket: The name of the bucket (data container) to query.

  • measurement: The name of the measurement (the specific data point, like a sensor name).

  • options: An optional object to refine the query.

    • start: The earliest time to include in results. Can be a relative duration (e.g., '-12h', '-7d') or an absolute ISO timestamp (e.g., '2025-08-01T10:00:00Z'). Defaults to '-1h'.

    • stop: The latest time to include. Defaults to 'now()'.

    • tail: An integer that limits the result to the last n data points in the time range.

    • limit: An integer that limits the result to the first n data points in the time range.

    • every: The duration of time windows for aggregation (e.g., '15m', '1h'). When used, func is required.

    • func: The aggregation function to apply to each window (e.g., 'mean', 'sum', 'count', 'last').

Example 1: Get all values from the last 12 hours

Example 2: Limit to the first 100 records from an absolute start time

Example 3: Get the latest 20 results

Example 4: Calculate the average value every 15 minutes over the last day

Output

An array of objects, where each object has a date (ISO timestamp) and a value.

query

Allows you to execute a raw Flux query string for maximum flexibility. Flux is the native query and scripting language for InfluxDB.

For a complete guide on the Flux language, refer to the official InfluxDB documentation.

Parameters

  • flux: The raw Flux query string.

Example: Get the last known value for two different measurements

Output

The raw, unprocessed result from the InfluxDB query API.

delete

Deletes data from a measurement. You can delete an entire measurement or specify a time range to delete only a portion of its data.

Parameters

  • bucket: The name of the bucket.

  • measurement: The name of the measurement to delete from.

  • options: An object to specify a time range for the deletion.

    • start: The start time of the delete window. Defaults to the beginning of time (1970-01-01...).

    • stop: The end time of the delete window. If omitted, it defaults to the current time.

Example 1: Delete data from a specific time range

Goal: Delete all pressure data from August 1st, 2025.

Example 2: Delete an entire measurement

Goal: Delete all data for old_sensor.

Output

Returns true on a successful deletion.

Last updated