Module: Timescaledb::ActsAsHypertable

Defined in:
lib/timescaledb/acts_as_hypertable.rb,
lib/timescaledb/acts_as_hypertable/core.rb

Overview

Note:

Your model's table needs to have already been converted to a hypertable

If you want your model to hook into its underlying hypertable as well as have access to TimescaleDB specific data, methods, and more, specify this macro in your model.

via the TimescaleDB create_hypertable function for this to work.

via a Rails migration utilizing the standard create_table method.

Examples:

Enabling the macro on your model

class Event < ActiveRecord::Base
  acts_as_hypertable
end

See Also:

Defined Under Namespace

Modules: Core

Constant Summary collapse

DEFAULT_OPTIONS =
{
  time_column: :created_at,
}.freeze

Instance Method Summary collapse

Instance Method Details

#acts_as_hypertable(options = {}) ⇒ Object

Configuration options

Examples:

Enabling the macro on your model with options

class Event < ActiveRecord::Base
  acts_as_hypertable time_column: :timestamp
end

Parameters:

  • options (Hash) (defaults to: {})

    The options to initialize your macro with.

  • options (Hash) (defaults to: {})

    The options to initialize your macro with.

Options Hash (options):

  • :time_column (Symbol)

    The name of the column in your model's table containing time values. The name provided should be the same name as the time_column_name you passed to the TimescaleDB create_hypertable function.

  • :skip_association_scopes (Boolean)

    to avoid .hypertable, .chunks and other scopes related to metadata.

  • :skip_default_scopes (Boolean)

    to avoid the generation of default time related scopes like last_hour, last_week, yesterday and so on...

  • :skip_time_vector (Boolean)

    to avoid the generation of time vector related scopes



49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/timescaledb/acts_as_hypertable.rb', line 49

def acts_as_hypertable(options = {})
  return if acts_as_hypertable?

  include Timescaledb::ActsAsHypertable::Core
  include Timescaledb::Toolkit::TimeVector

  class_attribute :hypertable_options, instance_writer: false

  self.hypertable_options = DEFAULT_OPTIONS.dup
  hypertable_options.merge!(options)
  normalize_hypertable_options

  define_association_scopes unless options[:skip_association_scopes]
  define_default_scopes unless options[:skip_default_scopes]
  define_default_vector_scopes unless options[:skip_time_vector]
end

#acts_as_hypertable?Boolean

Returns:

  • (Boolean)


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

def acts_as_hypertable?
  included_modules.include?(Timescaledb::ActsAsHypertable::Core)
end