Skip to content

tdely/nimflux

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Mar 28, 2022
7164f02 · Mar 28, 2022

History

39 Commits
Mar 28, 2022
Nov 23, 2021
Mar 27, 2022
Nov 23, 2021
Feb 26, 2021
Jun 29, 2021
Nov 23, 2021

Repository files navigation

Nimflux

Nimflux is an InfluxDB API client library for Nim that can be used to ping, write, query, or send custom requests. The DataPoint type is used to easily create measurements for write, but it's also possible to send your own Line Protocol string should the need arise.

import nimflux

var data = DataPoint(measurement: "temp")
data.addTag("loc", "home")
data.addField("ambient", 22.0)

var client = newInfluxClient("localhost", "nimtest")
var resp = client.write(data)
assert resp.code.toInfluxStatus == Ok
resp = client.query("select * from temp")
echo resp.body

Asynchronous actions are also supported through AsyncInfluxClient:

import asyncdispatch, nimflux

var data = DataPoint(measurement: "temp")
data.addTag("loc", "home")
data.addField("ambient", 22.0)

proc asyncProc(data: DataPoint): Future[AsyncResponse] {.async.} =
  var client = newAsyncInfluxClient("localhost", "nimtest")
  var resp = await client.write(data)
  assert resp.code.toInfluxStatus == Ok
  return await client.query("select * from temp")

echo asyncProc(data).waitFor().body.waitFor()