Class: Docset::IndexDB

Inherits:
Object
  • Object
show all
Defined in:
lib/docset/index_db.rb

Instance Method Summary collapse

Constructor Details

#initialize(file) ⇒ IndexDB

Returns a new instance of IndexDB.



5
6
7
8
# File 'lib/docset/index_db.rb', line 5

def initialize(file)
  @db = SQLite3::Database.new(file)
  @db.busy_timeout(5000)
end

Instance Method Details

#add_index(name, type, path) ⇒ Object



18
19
20
21
22
# File 'lib/docset/index_db.rb', line 18

def add_index(name, type, path)
  @db.prepare("INSERT OR IGNORE INTO searchIndex(name, type, path) VALUES (?, ?, ?);") do |stmt|
    stmt.execute([name, type, path])
  end
end

#initObject



10
11
12
13
14
15
16
# File 'lib/docset/index_db.rb', line 10

def init
  @db.execute_batch(<<~SQL)
    DROP TABLE IF EXISTS searchIndex;
    CREATE TABLE searchIndex(id INTEGER PRIMARY KEY, name TEXT, type TEXT, path TEXT);
    CREATE UNIQUE INDEX anchor ON searchIndex (name, type, path);
  SQL
end