Giter VIP home page Giter VIP logo

timescale's Introduction

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'

timescale's People

Contributors

akoutmos avatar alejandrodnm avatar bnchrch avatar btkostner avatar davydog187 avatar dbernheisel avatar doomspork avatar iamvery avatar kianmeng avatar mattludwigs avatar rajakavitha1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

timescale's Issues

Continuous Aggregate support

Look into what we want to support in Continuous Aggregates.

Since setting a continuous aggregate up involves materialized view syntax, we may want to just have documentation for setting up CAs in Ecto, and then add the following functions

Setup Github Actions for publishing to hex.pm

Automate the publishing of this repo to hex.pm when a github release is created. We can follow what we did for AvroEx.

Additionally, we need to configure the package so that the priv/ directory is not included, as we have added migrations that are intended solely for test purposes.

From the mix help hex.publish docs

  โ€ข :files - List of files and directories to include in the package, can
    include wildcards. Defaults to ["lib", "priv", "mix.exs", "README*",
    "readme*", "LICENSE*", "license*", "CHANGELOG*", "changelog*", "src"].

Validate support for date structs in queries

Validate if you can use Date, DateTime, and NaiveDateTime directly in ecto queries, e.g.

now = Date.utc_today()
from(t in Table, where: t.date < ^now) |> Repo.all()

If you can do this we should make sure it is correctly supported

Add TimescaleDB integration tests

From @akoutmos in slack

akoutmos - We should also add an issue for integration tests in CI

the assert_sql assertion is good for unit testing, but would be great to get some real TimescaleDB integration tests to validate that the functions not only produce expected SQL, but also return the expected results

๐Ÿ’ฏ that we should have integration tests here. The main issue will be finding a way to have ecto migrations without shipping them in the library. We may just need a publishing script that wipes the priv directory when we do mix hex.publish

Support Ecto DSL in `enable_hypertable_compression/2`

We have a function enable_hypertable_compression/2 which corresponds to an alter table, see the timescale docs

Currently we're only allowing you to pass the column name, but we should support the order and nulls rules as well. See below ๐Ÿ‘‡๐Ÿผ

ALTER TABLE <table_name> SET (timescaledb.compress, timescaledb.compress_orderby = '<column_name> [ASC | DESC] [ NULLS { FIRST | LAST } ] [, ...]',
timescaledb.compress_segmentby = '<column_name> [, ...]'
);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.