QuestDBClient.jl

Documentation for QuestDBClient.jl

Overview

This is a Julia package that can be used to connect to a QuestDB database server and send data using the InfluxDB Line Protocol.

Note

This package is strictly used to write data to the database. Reading is not supported. To read data from QuestDB, you can use QuestDB's LibPQ or DBInterface through port 8812. Alternatively, you can read the data over through QuestDB's REST API on port 9000. Visit QuestDB's docs to get more information on how to query data.

Tip

You can join the QuestDB Community here.

Installation

You can install the package at the Pkg REPL-mode with:

(@v1.8) pkg> add QuestDBClient

Quick Examples

Functional Approach

Using functions to write to a QuestDB Server:

using QuestDBClient

"""
Assumes the presence of a table called readings created using:

CREATE TABLE readings (
  timestamp TIMESTAMP,
  city SYMBOL,
  temperature DOUBLE,
  humidity DOUBLE,
  make SYMBOL
) TIMESTAMP(timestamp) PARTITION BY DAY;
"""

## Connects to the localhost at port 9009
sender = Sender()

## Connect the sender to the server first
connect(sender)

## Create ILP records
sender |>
    x -> table(x, :readings) |> 
    x -> symbol(x, :make => :Omron) |>
    x -> symbol(x, :city => :Nairobi) |>
    x -> FloatColumn(x, :temperature => 26.8) |> 
    x -> FloatColumn(x, :humidity => 0.51) |>
    x -> AtNow(x)

sender |> 
    x -> table(x, :readings) |> 
    x -> symbol(x, :make => :Honeywell) |> 
    x -> symbol(x, :city => :London) |>
    x -> FloatColumn(x, :temperature => 22.9) |> 
    x -> FloatColumn(x, :humidity => 0.254) |>
    x -> AtNow(x)

sender |> 
    x -> table(x, :readings) |> 
    x -> symbol(x, :make => :Omron) |> 
    x -> symbol(x, :city => :Bristol) |>
    x -> FloatColumn(x, :temperature => 23.9) |> 
    x -> FloatColumn(x, :humidity => 0.233) |>
    x -> AtNow(x)
    

## Flush the output to the server
QuestDBSender.flush(sender)

## Close the socket connection
## Close first calls QuestDBSender.flush(sender) as part of its definition
QuestDBSender.close(sender)
Tip

You can use packages such as Chain.jl, Pipe.jl, Lazy.jl or any other for function chaining, based on your preference.

Macro based approach

Using macros to write to the QuestDB Server:

using QuestDBClient

"""
Assumes the presence of a table called readings created using:

CREATE TABLE readings (
  timestamp TIMESTAMP,
  city SYMBOL,
  temperature DOUBLE,
  humidity DOUBLE,
  make SYMBOL
) TIMESTAMP(timestamp) PARTITION BY DAY;
"""

## Connects to the localhost at port 9009
sender = Sender()

## Connect the sender to the server first
connect(sender)

## Create ILP record statements
sender |>
    @table(:readings) |>
    @symbol(:make => :Omron) |>
    @symbol(:city => :Lisbon) |>
    @FloatColumn(:temperature => 24.8) |>
    @FloatColumn(:humidity => 0.334) |>
    @AtNow

sender |>
    @table(:readings) |>
    @symbol(:make => :HoneyWell) |>
    @symbol(:city => :Kisumu) |>
    @FloatColumn(:temperature => 30.2) |>
    @FloatColumn(:humidity => 0.54) |>
    @AtNow

sender |>
    @table(:readings) |>
    @symbol(:make => :Omron) |>
    @symbol(:city => :Berlin) |>
    @FloatColumn(:temperature => 26.1) |>
    @FloatColumn(:humidity => 0.45) |>
    @AtNow

## Flush the output to the server
QuestDBSender.flush(sender)

## Close the socket connection
## Close first calls QuestDBSender.flush(sender) as part of its definition
QuestDBSender.close(sender)

Package Manual

API

This client exposes a set of endpoints. However, some need to be prefixed with a module name because of the naming collision with existing Base functions.