Sha256: 0ec55e88dd0854580a73a3d94ea879ac06432b93246780f68130930cc6e148e0

Contents?: true

Size: 1.41 KB

Versions: 3

Compression:

Stored size: 1.41 KB

Contents

#!/usr/bin/env ruby

require "bundler/setup"
require "timescaledb"
require "pry"

Timescaledb.establish_connection(ARGV[0])

hypertables = Timescaledb.connection.query('SELECT * FROM timescaledb_information.hypertables')

if ARGV.index("--stats")
  if (only = ARGV.index("--only"))
    only_hypertables = ARGV[only+1].split(",")

    hypertables.select! { |hypertable| only_hypertables.includes?(hypertable.hypertable_name) }
  elsif (except = ARGV.index("--except"))
    except_hypertables = ARGV[except+1].split(",")

    hypertables.select! { |hypertable| except_hypertables.includes?(hypertable.hypertable_name) }
  end

  stats = Timescaledb::Stats.new(hypertables).to_h

  Pry::ColorPrinter.pp(stats)
end

if ARGV.index("--console")
  ActiveRecord::Base.establish_connection(ARGV[0])

  Timescaledb::Hypertable.find_each do |hypertable|
    class_name = hypertable.hypertable_name.singularize.camelize
    model = Class.new(ActiveRecord::Base) do
      self.table_name = hypertable.hypertable_name
      acts_as_hypertable time_column: hypertable.main_dimension.column_name
    end
    Timescaledb.const_set(class_name, model)
  end

  Timescaledb::ContinuousAggregates.find_each do |cagg|
    class_name = cagg.view_name.singularize.camelize
    model = Class.new(ActiveRecord::Base) do
      self.table_name = cagg.view_name
      acts_as_hypertable
    end
    Timescaledb.const_set(class_name, model)
  end

  Pry.start(Timescaledb)
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
timescaledb-0.3.0 bin/tsdb
timescaledb-0.2.9 bin/tsdb
timescaledb-0.2.8 bin/tsdb