Module: Timescaledb::Rails::Model::FinderMethods

Included in:
ClassMethods
Defined in:
lib/timescaledb/rails/model/finder_methods.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#find(*args) ⇒ Object

Adds a warning message to avoid calling find without filtering by time.



11
12
13
14
15
# File 'lib/timescaledb/rails/model/finder_methods.rb', line 11

def find(*args)
  warn "WARNING: Calling `.find` without filtering by `#{hypertable_time_column_name}` could cause performance issues, use built-in find_(at_time|between|after) methods for more performant results." # rubocop:disable Layout/LineLength

  super
end

#find_after(id, from) ⇒ Object

Finds records by primary key and chunk time occurring after given time.

Parameters:

  • id (Array<Integer>, Integer)

    The primary key values.

  • from (Time, Date, Integer)

    The chunk from time value.



38
39
40
# File 'lib/timescaledb/rails/model/finder_methods.rb', line 38

def find_after(id, from)
  after(from).find(id)
end

#find_at_time(id, time) ⇒ Object

Finds records by primary key and chunk time.

Parameters:

  • id (Array<Integer>, Integer)

    The primary key values.

  • time (Time, Date, Integer)

    The chunk time value.



21
22
23
# File 'lib/timescaledb/rails/model/finder_methods.rb', line 21

def find_at_time(id, time)
  at_time(time).find(id)
end

#find_between(id, from, to) ⇒ Object

Finds records by primary key and chunk time occurring between given time range.

Parameters:

  • id (Array<Integer>, Integer)

    The primary key values.

  • from (Time, Date, Integer)

    The chunk from time value.

  • to (Time, Date, Integer)

    The chunk to time value.



30
31
32
# File 'lib/timescaledb/rails/model/finder_methods.rb', line 30

def find_between(id, from, to)
  between(from, to).find(id)
end