33 lines
No EOL
662 B
Ruby
33 lines
No EOL
662 B
Ruby
|
|
require 'pg'
|
|
|
|
require_relative 'CachingTable.rb'
|
|
require_relative 'TimeseriesTable.rb'
|
|
|
|
module Timeseries
|
|
module Hoarder
|
|
class Database
|
|
attr_reader :pg
|
|
attr_reader :data_sources
|
|
|
|
def initialize(pg)
|
|
@pg = pg
|
|
|
|
@pg.exec("CREATE EXTENSION IF NOT EXISTS timescaledb")
|
|
@pg.exec("CREATE EXTENSION IF NOT EXISTS timescaledb_toolkit")
|
|
|
|
@pg.exec("CREATE SCHEMA IF NOT EXISTS ts_hoarder")
|
|
|
|
@data_sources = CachingTable.new(self, 'sources', 'source')
|
|
|
|
@series = {}
|
|
end
|
|
|
|
def add_timeseries(name, **opts)
|
|
return @series[name] if @series.include? name
|
|
|
|
new_series = SeriesTable.new(self, name, **opts)
|
|
end
|
|
end
|
|
end
|
|
end |