Class: Msnav::Store
- Inherits:
-
Object
- Object
- Msnav::Store
- Defined in:
- lib/msnav/store.rb
Overview
Read-only access to the shared coderag SQLite index.
coderag (Python) owns the index; since its schema v5 the DB is a pure
reader contract (meta key read_contract, currently 1.x) and holds no
mutable daemon state — msnav therefore opens it strictly read-only and
never writes to it. The window registry lives elsewhere (WindowsStore).
One connection guarded by a Mutex: navigation runs on the in-memory graph, so the DB sees only generation polls and graph reloads.
Constant Summary collapse
- SCHEMA_VERSION =
oldest index schema msnav understands
4- READ_CONTRACT_MAJOR =
newest reader contract msnav is written against
1
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #close ⇒ Object
- #get_meta(key) ⇒ Object
- #has_table?(name) ⇒ Boolean
-
#index_generation ⇒ Object
The shared DB's index generation — bumped by whichever coderag daemon (or host
coderag index) last completed a build. -
#initialize(path) ⇒ Store
constructor
A new instance of Store.
-
#services ⇒ Object
Canonical [name, dirname, root] service rows as indexed on the host.
-
#with_conn ⇒ Object
All DB access funnels through here.
Constructor Details
#initialize(path) ⇒ Store
Returns a new instance of Store.
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/msnav/store.rb', line 22 def initialize(path) @path = Pathname.new(path.to_s) unless @path.file? raise IndexStaleError, "no index at #{@path} — build it on the host with `coderag index` " \ "and mount the coderag data dir into this container" end @mutex = Mutex.new @conn = connect check_version end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
20 21 22 |
# File 'lib/msnav/store.rb', line 20 def path @path end |
Instance Method Details
#close ⇒ Object
40 41 42 43 44 |
# File 'lib/msnav/store.rb', line 40 def close @mutex.synchronize do @conn.close unless @conn.closed? end end |
#get_meta(key) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/msnav/store.rb', line 46 def (key) with_conn do |db| row = db.get_first_row("SELECT value FROM meta WHERE key = ?", [key]) row && row[0] end end |
#has_table?(name) ⇒ Boolean
66 67 68 69 70 71 72 |
# File 'lib/msnav/store.rb', line 66 def has_table?(name) with_conn do |db| !db.get_first_row( "SELECT 1 FROM sqlite_master WHERE type='table' AND name = ?", [name]).nil? end end |
#index_generation ⇒ Object
The shared DB's index generation — bumped by whichever coderag daemon
(or host coderag index) last completed a build. 0 when unset.
55 56 57 |
# File 'lib/msnav/store.rb', line 55 def index_generation (("index_generation") || 0).to_i end |
#services ⇒ Object
Canonical [name, dirname, root] service rows as indexed on the host.
60 61 62 63 64 |
# File 'lib/msnav/store.rb', line 60 def services with_conn do |db| db.execute("SELECT name, dirname, root FROM services ORDER BY name") end end |
#with_conn ⇒ Object
All DB access funnels through here. Reentrant per call site by design: never call with_conn inside with_conn.
36 37 38 |
# File 'lib/msnav/store.rb', line 36 def with_conn @mutex.synchronize { yield @conn } end |