Class: Nostrb::Sequel::Writer

Inherits:
Storage show all
Defined in:
lib/nostrb/sequel.rb

Constant Summary

Constants inherited from Storage

Storage::FILENAME, Storage::TABLES

Constants inherited from Nostrb::SQLite::Storage

Nostrb::SQLite::Storage::CONFIG, Nostrb::SQLite::Storage::FILENAME, Nostrb::SQLite::Storage::GB, Nostrb::SQLite::Storage::KB, Nostrb::SQLite::Storage::MB, Nostrb::SQLite::Storage::PRAGMAS, Nostrb::SQLite::Storage::SQLITE_USAGE

Instance Attribute Summary

Attributes inherited from Nostrb::SQLite::Storage

#db, #filename, #pragma

Instance Method Summary collapse

Methods inherited from Storage

#initialize, #pragma_scalars, #reader, #report, #schema, schema_line, #set_pragmas, #setup, #writer

Methods inherited from Nostrb::SQLite::Storage

#all_index_names, #all_table_names, #compile_options, #database_files, #index_names, #initialize, #pragma_scalars, #reader, #report, #set_pragmas, #setup, #table_names, #writer

Constructor Details

This class inherits a constructor from Nostrb::Sequel::Storage

Instance Method Details

#add_event(valid) ⇒ Object



191
192
193
194
195
196
197
198
199
200
# File 'lib/nostrb/sequel.rb', line 191

def add_event(valid)
  @db[:events].insert(valid.merge('tags' => Nostrb.json(valid['tags'])))
  valid['tags'].each { |a|
    @db[:tags].insert(event_id: valid['id'],
                      created_at: valid['created_at'],
                      tag: a[0],
                      value: a[1],
                      json: Nostrb.json(a))
  }
end

#add_r_event(valid) ⇒ Object

use insert_conflict to replace latest event



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'lib/nostrb/sequel.rb', line 203

def add_r_event(valid)
  tags = valid.fetch('tags')
  d_tag = Event.d_tag(tags)
  hsh = {
    'tags' => Nostrb.json(tags),
    'd_tag' => d_tag,
  }
  @db[:r_events].insert_conflict.insert(valid.merge(hsh))
  valid['tags'].each { |a|
    @db[:r_tags].insert(r_event_id: valid['id'],
                        created_at: valid['created_at'],
                        tag: a[0],
                        value: a[1],
                        json: Nostrb.json(a))
  }
end