Class: Nostrb::Sequel::Setup

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

Constant Summary

Constants inherited from Storage

Nostrb::Sequel::Storage::FILENAME, Nostrb::Sequel::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, #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, #table_names, #writer

Constructor Details

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

Instance Method Details

#create_tablesObject



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/nostrb/sequel.rb', line 79

def create_tables
  @db.create_table :events, strict: true do
    text :content,    null: false
    int  :kind,       null: false
    text :tags,       null: false
    text :pubkey,     null: false
    int  :created_at, null: false, index: {
           name: :idx_events_created_at
         }
    text :id,         null: false, primary_key: true
    text :sig,        null: false
  end

  @db.create_table :tags, strict: true do
    foreign_key :event_id, :events,
                key: :id,
                type: :text,
                null: false,
                on_delete: :cascade,
                on_update: :cascade
    int  :created_at, null: false, index: { name: :idx_tags_created_at }
    text :tag,        null: false
    text :value,      null: false
    text :json,       null: false
  end

  @db.create_table :r_events, strict: true do
    text :content,    null: false
    int  :kind,       null: false
    text :tags,       null: false
    text :d_tag,      null: true, default: nil
    text :pubkey,     null: false
    int  :created_at, null: false, index: {
           name: :idx_r_events_created_at
         }
    text :id,         null: false, primary_key: true
    text :sig,        null: false
    index [:kind, :pubkey, :d_tag], {
            unique: true,
            name: :unq_r_events_kind_pubkey_d_tag,
          }
  end

  @db.create_table :r_tags, strict: true do
    foreign_key :r_event_id, :r_events,
                key: :id,
                type: :text,
                null: false,
                on_delete: :cascade,
                on_update: :cascade
    int  :created_at, null: false, index: {
           name: :idx_r_tags_created_at
         }
    text :tag,        null: false
    text :value,      null: false
    text :json,       null: false
  end
end

#drop_tablesObject



75
76
77
# File 'lib/nostrb/sequel.rb', line 75

def drop_tables
  @db.drop_table?(*TABLES)
end

#setupObject



69
70
71
72
73
# File 'lib/nostrb/sequel.rb', line 69

def setup
  drop_tables
  create_tables
  report
end