InflexDB v0.1.2 InflexDB View Source

Client for InfluxDB

Checkout InflexDB.Client on how to instantiate and configure a client.

Link to this section Summary

Functions

Creates a new database.

Deletes all of the data, measurements, series, continuous queries, and retention policies from the specified database. If you attempt to drop a database that does not exist, InfluxDB does not return an error.

Returns a list of all databases on your instance.

Check the status of yout InfluxDB instance.

Query data with a SELECT statement.

Write a single point to a pre-existing database.

Write points to a pre-existing database.

Link to this section Types

Link to this type

error_response()

View Source
error_response() ::
  {:error, InflexDB.HTTPResponse.t()}
  | {:error, :econnrefused}
  | {:error, term()}

Link to this section Functions

Link to this function

create_database(client, name)

View Source
create_database(client :: InflexDB.Client.t(), name :: String.t()) ::
  :ok | error_response()

Creates a new database.

Example

client = %InflexDB.Client{}

InflexDB.create_database(client, "mydb")
Link to this function

delete_database(client, name)

View Source
delete_database(client :: InflexDB.Client.t(), name :: String.t()) ::
  :ok | error_response()

Deletes all of the data, measurements, series, continuous queries, and retention policies from the specified database. If you attempt to drop a database that does not exist, InfluxDB does not return an error.

Example

client = %InflexDB.Client{}

InflexDB.delete_database(client, "mydb")
Link to this function

list_databases(client)

View Source
list_databases(client :: InflexDB.Client.t()) ::
  {:ok, [String.t()]} | error_response()

Returns a list of all databases on your instance.

client = %InflexDB.Client{}

InflexDB.list_databases(client)
# {:ok, ["_internal", "mydb"]}

Check the status of yout InfluxDB instance.

Example

client = %InflexDB.Client{}

InflexDB.ping(client)
Link to this function

query(client, db, query)

View Source
query(client :: InflexDB.Client.t(), db :: String.t(), query :: String.t()) ::
  {:ok, map()} | error_response()

Query data with a SELECT statement.

Example

client = %InflexDB.Client{}

InflexDB.query(client, "mydb", "SELECT * FROM weather")
# {:ok,
#  [
#    %{
#      name: "weather",
#      statement_id: 0,
#      tags: nil,
#      values: [
#        %{
#          "location" => "us-midwest",
#          "season" => "summer",
#          "temperature" => 82,
#          "time" => "2020-03-29T20:34:46.725338219Z"
#        },
#        %{
#          "season" => "summer",
#          "location" => "us-east",
#          "temperature" => 879,
#          "time" => "2020-03-29T20:40:46.790074049Z"
#        }
#      ]
#    }
#  ]}

Multiple SELECT statements are also supported:

client = %Inflex.Client{}
statement = "SELECT * FROM weather group by location; SELECT * from weather2 group by season"

InflexDB.query(client, "mydb", statement)
# {:ok,
#  [
#    %{
#      name: "weather",
#      statement_id: 0,
#      tags: %{"location" => "us-east"},
#      values: [
#        %{
#          "season" => "summer",
#          "temperature" => 879,
#          "time" => "2020-03-29T20:40:46.790074049Z"
#        },
#        %{
#          "season" => "winter",
#          "temperature" => 8096,
#          "time" => "2020-03-29T20:40:46.790074049Z"
#        }
#      ]
#    },
#    %{
#      name: "weather",
#      statement_id: 0,
#      tags: %{"location" => "us-midwest"},
#      values: [
#        %{
#          "season" => "summer",
#          "temperature" => 82,
#          "time" => "2020-03-29T20:34:46.725338219Z"
#        },
#        %{
#          "season" => "summer",
#          "temperature" => 82,
#          "time" => "2020-03-29T20:35:15.531091771Z"
#        }
#      ]
#    },
#    %{
#      name: "weather2",
#      statement_id: 1,
#      tags: %{"season" => "summer"},
#      values: [
#        %{
#          "location" => "us-east",
#          "temperature" => 842,
#          "time" => "2020-03-29T20:59:41.755035346Z"
#        },
#        %{
#          "location" => "us-midwest",
#          "temperature" => 2342,
#          "time" => "2020-03-29T20:59:41.755035346Z"
#        }
#      ]
#    },
#    %{
#      name: "weather2",
#      statement_id: 1,
#      tags: %{"season" => "winter"},
#      values: [
#        %{
#          "location" => "us-east",
#          "temperature" => 7554,
#          "time" => "2020-03-29T20:59:41.755035346Z"
#        },
#        %{
#          "location" => "us-midwest",
#          "temperature" => 5473,
#          "time" => "2020-03-29T20:59:41.755035346Z"
#        }
#      ]
#    }
#  ]}
Link to this function

write_point(client, db, point)

View Source
write_point(
  client :: InflexDB.Client.t(),
  db :: String.t(),
  point :: InflexDB.Point.t()
) :: :ok | error_response()

Write a single point to a pre-existing database.

Example

client = %InflexDB.Client{}

point = %Point{
  measurement: "weather",
  tag_set: %{location: "us-midwest"},
  field_set: %{temperature: 82}
}

InflexDB.write_point(client, "mydb", point)
Link to this function

write_points(client, db, points)

View Source
write_points(
  client :: InflexDB.Client.t(),
  db :: String.t(),
  points :: [InflexDB.Point.t()]
) :: :ok | error_response()

Write points to a pre-existing database.

Example

client = %InflexDB.Client{}

points = [
  %Point{
    measurement: "weather",
    tag_set: %{location: "us-midwest"},
    field_set: %{temperature: 82}
  },
  %Point{
    measurement: "weather",
    tag_set: %{location: "us-midwest"},
    field_set: %{temperature: 76}
  }
]

InflexDB.write_points(client, "mydb", points)