lib/influxer/metrics/relation.rb in influxer-1.2.0 vs lib/influxer/metrics/relation.rb in influxer-1.2.1
- old
+ new
@@ -20,15 +20,15 @@
MULTI_VALUE_METHODS = %i[select where group order].freeze
MULTI_KEY_METHODS = %i[fanout].freeze
- SINGLE_VALUE_METHODS = %i[fill time limit offset slimit soffset from normalized].freeze
+ SINGLE_VALUE_METHODS = %i[fill time limit offset slimit soffset from normalized timezone].freeze
MULTI_VALUE_SIMPLE_METHODS = %i[select group].freeze
- SINGLE_VALUE_SIMPLE_METHODS = %i[fill limit offset slimit soffset from].freeze
+ SINGLE_VALUE_SIMPLE_METHODS = %i[fill limit offset slimit soffset from timezone].freeze
MULTI_VALUE_METHODS.each do |name|
class_eval <<-CODE, __FILE__, __LINE__ + 1
def #{name}_values # def select_values
@values[:#{name}] ||= [] # @values[:select] || []
@@ -119,10 +119,17 @@
@values[:epoch] = val
self
end
+ def timezone(val)
+ return self if val.blank?
+
+ @values[:timezone] = val
+ self
+ end
+
def order(val)
case val
when Hash
val.each { |k, v| order_values << "#{k} #{v}" }
when String
@@ -157,10 +164,11 @@
sql << "limit #{limit_value}" unless limit_value.nil?
sql << "offset #{offset_value}" unless offset_value.nil?
sql << "slimit #{slimit_value}" unless slimit_value.nil?
sql << "soffset #{soffset_value}" unless soffset_value.nil?
+ sql << "TZ('#{timezone_value}')" unless timezone_value.blank?
sql.join " "
end
# rubocop:enable Metrics/AbcSize
# rubocop:enable Metrics/CyclomaticComplexity
# rubocop:enable Metrics/MethodLength
@@ -203,10 +211,14 @@
@loaded = true
@records
end
def delete_all
- sql = ["drop series"]
+ sql = if where_contains_time?
+ ["delete"]
+ else
+ ["drop series"]
+ end
sql << "from #{@instance.series}"
sql << "where #{where_values.join(" and ")}" unless where_values.empty?