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.
create
Creates an instance of the InfluxDB client, configuring it to connect to a specific database URL with the necessary credentials.
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.
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 lastndata points in the time range.limit: An integer that limits the result to the firstndata points in the time range.every: The duration of time windows for aggregation (e.g.,'15m','1h'). When used,funcis 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
# bucket
F
# measurement
sensor1
# options
start: -12h
Example 2: Limit to the first 100 records from an absolute start time
# bucket
D
# measurement
machine_vibration
# options
start: 2025-08-29T00:00:00Z
limit: 100
Example 3: Get the latest 20 results
# bucket
H
# measurement
temperature
# options
tail: 20
Example 4: Calculate the average value every 15 minutes over the last day
# bucket
D
# measurement
pressure
# options
start: -1d
every: 15m
func: mean
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
# flux
from(bucket:"iot-data")
|> range(start: -1h)
|> filter(fn: (r) => r._measurement == "temperature" or r._measurement == "humidity")
|> last()
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.
# bucket
Y
# measurement
pressure
# options
start: 2025-08-01T00:00:00Z
stop: 2025-08-01T23:59:59Z
Example 2: Delete an entire measurement
Goal: Delete all data for old_sensor.
# bucket
F
# measurement
old_sensor
Output
Returns true on a successful deletion.
Last updated
