Class: Docset::IndexDB
- Inherits:
-
Object
- Object
- Docset::IndexDB
- Defined in:
- lib/docset/index_db.rb
Instance Method Summary collapse
- #add_index(name, type, path) ⇒ Object
- #init ⇒ Object
-
#initialize(file) ⇒ IndexDB
constructor
A new instance of IndexDB.
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 |
#init ⇒ Object
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 |