• Stars
    star
    107
  • Rank 311,765 (Top 7 %)
  • Language
    Elixir
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated 9 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

TimescaleDB made easy with Ecto

Timescale

Build Status Hex pm Hexdocs.pm

Extends the Ecto DSL for easily working with TimescaleDB. Already using Ecto and Postgres? Great, you're all set to start working with time-series data.

Features

Adding the TimescaleDB extension

  1. Make sure your database has Timescale correctly installed
  2. Create a new Ecto migration
  3. Call the create_timescaledb_extension/0 and drop_timescaledb_extension/0 in your migration

E.g.

defmodule MyApp.Repo.Migrations.SetupTimescale do
  use Ecto.Migration

  import Timescale.Migration

  def up do
    create_timescaledb_extension()
  end

  def down do
    drop_timescaledb_extension()
  end
end

Using the Library

Here is an intermediate example querying a timescale reading using Timescale hyperfunctions with timescale's Ecto extensions.

For a more comprehensive example you can check out our guide in the docs here.

import Timescale.Hyperfunctions

Repo.all(
  from(h in "heartbeats",
    where: h.user_id == ^alex_id,
    group_by: selected_as(:minute),
    select: %{
      minute: selected_as(time_bucket(h.timestamp, "1 minute"), :minute),
      bpm: count(h)
    },
    limit: 5
  )
)

Installation

If available in Hex, the package can be installed by adding timescale to your list of dependencies in mix.exs:

def deps do
  [
    {:timescale, "~> 0.1.0"}
  ]
end

Installing Postgres / TimescaleDB on MacOS

There are many ways to install PostgreSQL locally, including Postgres.app, Docker, and building locally. Below is how to install through Homebrew

First, install Postgres

$ brew install postgresql
$ sudo chown $(whoami) /usr/local/var/postgres
$ initdb /usrl/local/var/postgres
$ createuser -s postgres
$ createdb

Make Postgres a service that is started automatically

$ brew services start postgresql

Then install TimescaleDB. For more information about installing TimescaleDB on MacOS, see the official documentation.

$ brew tap timescale/tap
$ brew install timescaledb

# Add the following to `/opt/homebrew/var/postgres/postgresql.conf`
shared_preload_libraries = 'timescaledb'

More Repositories

1

marx

A markdown compiler for the people
Elixir
25
star
2

ecto_range

An Ecto custom type for working Postgres ranges
Elixir
23
star
3

jqex

A command line tool inspired by jq for converting json into elixir terms
Elixir
15
star
4

dash

A full-screen display dashboard for your life. Built for my talk, "Surface: A bridge to the JavaScript community" at The Big Elixir 2022
Elixir
12
star
5

elm-pong

Pong based on the example from the Elm-lang website, with some additional features
Elm
8
star
6

sanity-portable-table

A table plugin for Sanity that supports Portable Text cells
TypeScript
7
star
7

fout-with-fontface-swap

An alternate strategy to achieving FOUT with the CSS Font Loading API
HTML
7
star
8

elm-tic-tac-toe

Game of tic tac toe written in elm and node.js
Elm
7
star
9

tab

Convert nested elixir data into tabular data
Elixir
6
star
10

website

Dave's personal website
Elixir
6
star
11

xombi_spawn

Elixir multiplayer game server
Elixir
4
star
12

baseball

A example NIF for my Code BEAM SF 2020 presentation
Elixir
4
star
13

migrating_from_kafka

Talk for RabbitMQ Summit 2021
3
star
14

udp

An example of sending UDP packets between two containers
Elixir
2
star
15

spongebob

A re-write, for performance, of supersimple's spongebob CLI
Rust
2
star
16

foosball

A phoenix app for testing commanded telemetry integration
Elixir
2
star
17

slack_game_ex

An Elixir Slack bot that plays games! TicTacToe only for now :)
Elixir
1
star
18

surface_talk

Surface: A bridge to the Javascript community - ElixirConf 2021
1
star
19

aoc_2023

Elixir
1
star
20

xebra-web

Xebra Labs website
HTML
1
star
21

ecto_ipa

A tour of Ecto using data from https://en.wikipedia.org/wiki/List_of_breweries_in_New_York
Elixir
1
star
22

og-image

TypeScript
1
star