Class: Nostrb::SQLite::Setup
Constant Summary
Constants inherited from 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 Storage
Instance Method Summary collapse
Methods inherited from Storage
#all_index_names, #all_table_names, #compile_options, #database_files, #index_names, #initialize, #pragma_scalars, #reader, #report, #set_pragmas, #table_names, #writer
Constructor Details
This class inherits a constructor from Nostrb::SQLite::Storage
Instance Method Details
#create_indices ⇒ Object
277 278 279 280 281 282 283 284 285 286 287 288 289 |
# File 'lib/nostrb/sqlite.rb', line 277 def create_indices @db.execute "CREATE INDEX idx_events_created_at ON events (created_at)" @db.execute "CREATE INDEX idx_tags_created_at ON tags (created_at)" @db.execute "CREATE INDEX idx_r_events_created_at ON r_events (created_at)" @db.execute "CREATE INDEX idx_r_tags_created_at ON r_tags (created_at)" @db.execute "CREATE UNIQUE INDEX unq_r_events_kind_pubkey_d_tag ON r_events (kind, pubkey, d_tag)" end |
#create_tables ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 |
# File 'lib/nostrb/sqlite.rb', line 236 def create_tables @db.execute <<SQL CREATE TABLE events (content TEXT NOT NULL, kind INT NOT NULL, tags TEXT NOT NULL, pubkey TEXT NOT NULL, created_at INT NOT NULL, id TEXT PRIMARY KEY NOT NULL, sig TEXT NOT NULL) STRICT SQL @db.execute <<SQL CREATE TABLE tags (event_id TEXT NOT NULL REFERENCES events (id) ON DELETE CASCADE ON UPDATE CASCADE, created_at INT NOT NULL, tag TEXT NOT NULL, value TEXT NOT NULL, json TEXT NOT NULL) STRICT SQL @db.execute <<SQL CREATE TABLE r_events (content TEXT NOT NULL, kind INT NOT NULL, tags TEXT NOT NULL, d_tag TEXT DEFAULT NULL, pubkey TEXT NOT NULL, created_at INT NOT NULL, id TEXT PRIMARY KEY NOT NULL, sig TEXT NOT NULL) STRICT SQL @db.execute <<SQL CREATE TABLE r_tags (r_event_id TEXT NOT NULL REFERENCES r_events (id) ON DELETE CASCADE ON UPDATE CASCADE, created_at INT NOT NULL, tag TEXT NOT NULL, value TEXT NOT NULL, json TEXT NOT NULL) STRICT SQL end |
#drop_tables ⇒ Object
230 231 232 233 234 |
# File 'lib/nostrb/sqlite.rb', line 230 def drop_tables %w[events tags r_events r_tags].each { |tbl| @db.execute "DROP TABLE IF EXISTS #{tbl}" } end |
#setup ⇒ Object
223 224 225 226 227 228 |
# File 'lib/nostrb/sqlite.rb', line 223 def setup drop_tables create_tables create_indices report end |