Class: Nostrb::Sequel::Reader
Constant Summary
Constants inherited
from Storage
Storage::FILENAME, Storage::TABLES
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
#db, #filename, #pragma
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Storage
#initialize, #pragma_scalars, #reader, #report, #schema, schema_line, #set_pragmas, #setup, #writer
#all_index_names, #all_table_names, #compile_options, #database_files, #index_names, #initialize, #pragma_scalars, #reader, #report, #set_pragmas, #setup, #table_names, #writer
Class Method Details
.event_clauses(filter) ⇒ Object
150
151
152
153
154
155
156
157
158
159
|
# File 'lib/nostrb/sequel.rb', line 150
def self.event_clauses(filter)
hsh = {}
hsh[:id] = filter.ids unless filter.ids.empty?
hsh[:pubkey] = filter.authors unless filter.authors.empty?
hsh[:kind] = filter.kinds unless filter.kinds.empty?
a = filter.since || Filter.ago(years: 10)
b = filter.until || Time.now.to_i
hsh[:created_at] = a..b
hsh
end
|
.hydrate(event_row) ⇒ Object
140
141
142
143
144
145
146
147
148
|
# File 'lib/nostrb/sequel.rb', line 140
def self.hydrate(event_row)
Hash[ 'content' => event_row.fetch(:content),
'kind' => event_row.fetch(:kind),
'tags' => Nostrb.parse(event_row.fetch(:tags)),
'pubkey' => event_row.fetch(:pubkey),
'created_at' => event_row.fetch(:created_at),
'id' => event_row.fetch(:id),
'sig' => event_row.fetch(:sig), ].freeze
end
|
Instance Method Details
#process_events(filter = nil) ⇒ Object
173
174
175
176
177
|
# File 'lib/nostrb/sequel.rb', line 173
def process_events(filter = nil)
a = []
select_events(filter).each { |row| a << Reader.hydrate(row) }
a
end
|
#process_r_events(filter = nil) ⇒ Object
183
184
185
186
187
|
# File 'lib/nostrb/sequel.rb', line 183
def process_r_events(filter = nil)
a = []
select_r_events(filter).each { |row| a << Reader.hydrate(row) }
a
end
|
#select_events(filter = nil) ⇒ Object
169
170
171
|
# File 'lib/nostrb/sequel.rb', line 169
def select_events(filter = nil)
select_events_table(:events, filter)
end
|
#select_events_table(table = :events, filter = nil) ⇒ Object
161
162
163
164
165
166
167
|
# File 'lib/nostrb/sequel.rb', line 161
def select_events_table(table = :events, filter = nil)
if !filter.nil?
@db[table].where(self.class.event_clauses(filter))
else
@db[table]
end
end
|
#select_r_events(filter = nil) ⇒ Object
179
180
181
|
# File 'lib/nostrb/sequel.rb', line 179
def select_r_events(filter = nil)
select_events_table(:r_events, filter)
end
|