Class: Zermelo::Backends::InfluxDB
- Inherits:
-
Object
- Object
- Zermelo::Backends::InfluxDB
- Includes:
- Zermelo::Backend
- Defined in:
- lib/zermelo/backends/influxdb.rb
Instance Method Summary collapse
- #abort_transaction ⇒ Object
- #begin_transaction ⇒ Object
- #commit_transaction ⇒ Object
-
#exists?(key) ⇒ Boolean
TODO get filter calling this instead of using same logic.
-
#filter(ids_key, associated_class, callback_target_class = nil, callback_target_id = nil, callbacks = nil, sort_order = nil) ⇒ Object
def default_sorted_set_key :time end.
-
#get_multiple(*attr_keys) ⇒ Object
nb: does lots of queries, should batch, but ensuring single operations are correct for now.
Methods included from Zermelo::Backend
#add, #clear, #delete, #escape_key_name, #get, #index_keys, #lock, #move, #purge, #safe_value, #set, #unescape_key_name
Instance Method Details
#abort_transaction ⇒ Object
111 112 113 114 115 |
# File 'lib/zermelo/backends/influxdb.rb', line 111 def abort_transaction return false unless @in_transaction @in_transaction = false @changes = [] end |
#begin_transaction ⇒ Object
98 99 100 101 102 |
# File 'lib/zermelo/backends/influxdb.rb', line 98 def begin_transaction return false if @in_transaction @in_transaction = true @changes = [] end |
#commit_transaction ⇒ Object
104 105 106 107 108 109 |
# File 'lib/zermelo/backends/influxdb.rb', line 104 def commit_transaction return false unless @in_transaction apply_changes(@changes) @in_transaction = false @changes = [] end |
#exists?(key) ⇒ Boolean
TODO get filter calling this instead of using same logic
32 33 34 35 36 |
# File 'lib/zermelo/backends/influxdb.rb', line 32 def exists?(key) return if key.id.nil? class_key = attr_key.klass.send(:class_key) Zermelo.influxdb.query("SELECT id FROM /#{class_key}\\/.*/ LIMIT 1").size > 0 end |
#filter(ids_key, associated_class, callback_target_class = nil, callback_target_id = nil, callbacks = nil, sort_order = nil) ⇒ Object
def default_sorted_set_key
:time
end
24 25 26 27 28 29 |
# File 'lib/zermelo/backends/influxdb.rb', line 24 def filter(ids_key, associated_class, callback_target_class = nil, callback_target_id = nil, callbacks = nil, sort_order = nil) Zermelo::Filters::InfluxDB.new(self, ids_key, associated_class, callback_target_class, callback_target_id, callbacks, sort_order) end |
#get_multiple(*attr_keys) ⇒ Object
nb: does lots of queries, should batch, but ensuring single operations are correct for now
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/zermelo/backends/influxdb.rb', line 40 def get_multiple(*attr_keys) attr_keys.inject({}) do |memo, attr_key| class_key = attr_key.klass.send(:class_key) begin records = Zermelo.influxdb.query("SELECT #{attr_key.name} FROM " + "\"#{class_key}/#{attr_key.id}\" LIMIT 1")["#{class_key}/#{attr_key.id}"] rescue ::InfluxDB::Error => ide raise unless /^Field #{attr_key.name} doesn't exist in series #{class_key}\/#{attr_key.id}$/ === ide. records = [] end value = (records && !records.empty?) ? records.first[attr_key.name.to_s] : nil memo[class_key] ||= {} memo[class_key][attr_key.id] ||= {} memo[class_key][attr_key.id][attr_key.name.to_s] = if value.nil? case attr_key.type when :list [] when :hash {} when :set Set.new else nil end else case attr_key.type when :string value.to_s when :integer value.to_i when :float value.to_f when :timestamp Time.at(value.to_f) when :boolean case value when TrueClass true when FalseClass false when String 'true'.eql?(value.downcase) else nil end when :list, :hash value when :set Set.new(value) end end memo end end |