Class: Nostrb::SQLite::Writer
Constant Summary
Constants inherited from Storage
Storage::CONFIG, Storage::FILENAME, Storage::GB, Storage::KB, Storage::MB, Storage::PRAGMAS, Storage::SQLITE_USAGE
Instance Attribute Summary
Attributes inherited from Storage
Class Method Summary collapse
Instance Method Summary collapse
-
#add_event(valid) ⇒ Object
a valid hash, as returned from SignedEvent.validate!.
-
#add_r_event(valid) ⇒ Object
add replaceable event.
Methods inherited from 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::SQLite::Storage
Class Method Details
Instance Method Details
#add_event(valid) ⇒ Object
a valid hash, as returned from SignedEvent.validate!
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 |
# File 'lib/nostrb/sqlite.rb', line 402 def add_event(valid) @add_event ||= @db.prepare("INSERT INTO events VALUES (:content, :kind, :tags, :pubkey, :created_at, :id, :sig)") @add_tag ||= @db.prepare("INSERT INTO tags VALUES (:event_id, :created_at, :tag, :value, :json)") @add_event.execute(Writer.(valid)) # insert event valid["tags"].each { |a| # insert tags @add_tag.execute(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
add replaceable event
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
# File 'lib/nostrb/sqlite.rb', line 420 def add_r_event(valid) @add_r_event ||= @db.prepare("INSERT OR REPLACE INTO r_events VALUES (:content, :kind, :tags, :d_tag, :pubkey, :created_at, :id, :sig)") @add_rtag ||= @db.prepare("INSERT INTO r_tags VALUES (:r_event_id, :created_at, :tag, :value, :json)") = valid['tags'] record = Writer.(valid) record['d_tag'] = Event.d_tag() @add_r_event.execute(record) # upsert event .each { |a| # insert tags @add_rtag.execute(r_event_id: valid['id'], created_at: valid['created_at'], tag: a[0], value: a[1], json: Nostrb.json(a)) } end |