Module: Timescaledb

Defined in:
lib/timescaledb/toolkit/helpers.rb,
lib/timescaledb.rb,
lib/timescaledb/job.rb,
lib/timescaledb/chunk.rb,
lib/timescaledb/stats.rb,
lib/timescaledb/version.rb,
lib/timescaledb/database.rb,
lib/timescaledb/extension.rb,
lib/timescaledb/job_stats.rb,
lib/timescaledb/connection.rb,
lib/timescaledb/dimensions.rb,
lib/timescaledb/hypertable.rb,
lib/timescaledb/stats/chunks.rb,
lib/timescaledb/stats_report.rb,
lib/timescaledb/counter_cache.rb,
lib/timescaledb/schema_dumper.rb,
lib/timescaledb/database/types.rb,
lib/timescaledb/scenic/adapter.rb,
lib/timescaledb/stats/job_stats.rb,
lib/timescaledb/database/quoting.rb,
lib/timescaledb/scenic/extension.rb,
lib/timescaledb/migration_helpers.rb,
lib/timescaledb/stats/hypertables.rb,
lib/timescaledb/acts_as_hypertable.rb,
lib/timescaledb/application_record.rb,
lib/timescaledb/connection_handling.rb,
lib/timescaledb/toolkit/time_vector.rb,
lib/timescaledb/compression_settings.rb,
lib/timescaledb/continuous_aggregates.rb,
lib/timescaledb/acts_as_hypertable/core.rb,
lib/timescaledb/database/chunk_statements.rb,
lib/timescaledb/database/schema_statements.rb,
lib/timescaledb/stats/continuous_aggregates.rb,
lib/timescaledb/continuous_aggregates_helper.rb,
lib/timescaledb/database/hypertable_statements.rb

Overview

Useful methods to run TimescaleDB in you Ruby app.

Defined Under Namespace

Modules: ActsAsHypertable, ContinuousAggregatesHelper, CounterCache, Extension, MigrationHelpers, Scenic, SchemaDumper, StatsReport, Toolkit Classes: ApplicationRecord, Chunk, CompressionSetting, Connection, ConnectionNotEstablishedError, ContinuousAggregates, Database, Dimension, Hypertable, Job, JobStat, Stats

Constant Summary collapse

VERSION =
'0.3.2'
JobStats =
JobStat
Dimensions =

attribute :time_interval, :interval

Dimension
CompressionSettings =
CompressionSetting

Class Method Summary collapse

Class Method Details

.chunksObject



35
36
37
# File 'lib/timescaledb.rb', line 35

def chunks
  Chunk.all
end

.compression_settingsObject



47
48
49
# File 'lib/timescaledb.rb', line 47

def compression_settings
  CompressionSettings.all
end

.connectionObject



27
28
29
# File 'lib/timescaledb.rb', line 27

def connection
  Connection.instance
end

.continuous_aggregatesObject



43
44
45
# File 'lib/timescaledb.rb', line 43

def continuous_aggregates
  ContinuousAggregates.all
end

.default_hypertable_optionsObject



63
64
65
# File 'lib/timescaledb.rb', line 63

def default_hypertable_options
  Timescaledb::ActsAsHypertable::DEFAULT_OPTIONS
end

.establish_connection(config) ⇒ Object

Parameters:

  • config (String)

    with the postgres connection string.



7
8
9
10
11
12
13
14
15
# File 'lib/timescaledb/connection_handling.rb', line 7

def establish_connection(config)
  # Establish connection for Timescaledb
  Connection.instance.config = config
  
  # Also establish connection for ActiveRecord if it's defined
  if defined?(ActiveRecord::Base)
    ActiveRecord::Base.establish_connection(config)
  end
end

.extensionObject



31
32
33
# File 'lib/timescaledb.rb', line 31

def extension
  Extension
end

.hypertablesObject



39
40
41
# File 'lib/timescaledb.rb', line 39

def hypertables
  Hypertable.all
end

.job_statsObject



55
56
57
# File 'lib/timescaledb.rb', line 55

def job_stats
  JobStats.all
end

.jobsObject



51
52
53
# File 'lib/timescaledb.rb', line 51

def jobs
  Job.all
end

.stats(scope = Hypertable.all) ⇒ Object



59
60
61
# File 'lib/timescaledb.rb', line 59

def stats(scope=Hypertable.all)
  StatsReport.resume(scope)
end

.use_connection(conn) ⇒ Object

Parameters:

  • to (PG::Connection)

    use it directly from a raw connection



18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/timescaledb/connection_handling.rb', line 18

def use_connection(conn)
  Connection.instance.use_connection(conn)
  
  # Also set ActiveRecord connection if it's defined
  if defined?(ActiveRecord::Base) && ActiveRecord::Base.connected?
    ar_conn = ActiveRecord::Base.connection
    current_conn = ar_conn.raw_connection
    
    # Only set if it's different to avoid redundant assignment
    if current_conn != conn
      ar_conn.instance_variable_set(:@raw_connection, conn)
    end
  end
end