View Source TimeSeriesDB (TimeSeriesDB v1.0.0)

A time series database that stores data in a directory of files.

Example:

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db", max_files: 2)
iex> TimeSeriesDB.append_row(pid, 1, %{x: 1, y: 2, z: "hello"})
iex> TimeSeriesDB.append_row(pid, 2, %{x: 2, y: 3, z: "world"})
iex> TimeSeriesDB.append_row(pid, 3, %{x: 3, y: 4, z: "elixir"})
iex> TimeSeriesDB.query_range(pid, 1, 2)
[{1, %{x: 1, y: 2, z: "hello"}}, {2, %{x: 2, y: 3, z: "world"}}]
iex> TimeSeriesDB.query_multiple(pid, [3, 2])
[%{x: 3, y: 4, z: "elixir"}, %{x: 2, y: 3, z: "world"}]

Summary

Functions

Appends a row to the database.

Returns a specification to start this module under a supervisor.

Counts the number of rows in the database.

Counts the number of files in the database.

Flushes the database to disk.

Returns the newest timestamp in the database.

Returns the oldest timestamp in the database.

Queries multiple rows from the database.

Queries a range of rows from the database.

Stops the server.

Functions

Link to this function

append_row(pid, key, value)

View Source

Appends a row to the database.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db", max_files: 2)
iex> TimeSeriesDB.append_row(pid, 1, %{x: 1, y: 2, z: "hello"})
:ok

Returns a specification to start this module under a supervisor.

See Supervisor.

Counts the number of rows in the database.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db")
iex> TimeSeriesDB.append_row(pid, 1, %{x: 1, y: 2, z: "hello"})
iex> TimeSeriesDB.append_row(pid, 2, %{x: 2, y: 3, z: "world"})
iex> TimeSeriesDB.count(pid)
2

Counts the number of files in the database.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db")
iex> for x <- 1..20_000, do: TimeSeriesDB.append_row(pid, x, %{x: x, z: String.duplicate("hello", 100)})
iex> TimeSeriesDB.flush(pid)
iex> TimeSeriesDB.count_files(pid) |> length()
3

Flushes the database to disk.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db")
iex> TimeSeriesDB.flush(pid)
:ok

Returns the newest timestamp in the database.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db")
iex> TimeSeriesDB.append_row(pid, 1, %{x: 1, y: 2, z: "hello"})
iex> TimeSeriesDB.append_row(pid, 2, %{x: 2, y: 3, z: "world"})
iex> TimeSeriesDB.newest(pid)
2

Returns the oldest timestamp in the database.

Link to this function

query_multiple(pid, keys)

View Source

Queries multiple rows from the database.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db")
iex> TimeSeriesDB.append_row(pid, 1, %{x: 1, y: 2, z: "hello"})
iex> TimeSeriesDB.append_row(pid, 2, %{x: 2, y: 3, z: "world"})
iex> TimeSeriesDB.query_multiple(pid, [3, 2, 1])
[nil, %{x: 2, y: 3, z: "world"}, %{x: 1, y: 2, z: "hello"}]
Link to this function

query_range(pid, from, to)

View Source

Queries a range of rows from the database.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db", max_files: 2)
iex> TimeSeriesDB.append_row(pid, 1, %{x: 1, y: 2, z: "hello"})
iex> TimeSeriesDB.append_row(pid, 2, %{x: 2, y: 3, z: "world"})
iex> TimeSeriesDB.query_range(pid, 1, 2)
[{1, %{x: 1, y: 2, z: "hello"}}, {2, %{x: 2, y: 3, z: "world"}}]
Link to this function

start_link(filename, opts \\ [])

View Source

Starts the server.

Options

  • :max_files - The maximum number of files to keep in the database. Defaults to 100.
  • :name - The name of the process.

Example:

iex> {:ok, _pid} = TimeSeriesDB.start_link("testdata/test_db", max_files: 2)

Stops the server.

Examples

iex> {:ok, pid} = TimeSeriesDB.start_link("testdata/test_db")
iex> TimeSeriesDB.stop(pid)
:ok