Skip to content

feat(core): introduce GraphDB / QueryResult protocols for backend swap#17

Merged
joy-software merged 1 commit into
developfrom
feature/db-protocol
Jun 1, 2026
Merged

feat(core): introduce GraphDB / QueryResult protocols for backend swap#17
joy-software merged 1 commit into
developfrom
feature/db-protocol

Conversation

@joy-software
Copy link
Copy Markdown
Contributor

Summary

First PR in the Kuzu → DuckDB migration. Introduces `GraphDB` and `QueryResult` Protocols + a thin Kuzu adapter so future backends can slot in without touching call sites.

What lands

File Role
`core/protocol.py` The two runtime-checkable Protocols. `QueryResult.has_next/get_next/get_column_names` is the exact surface cgh callers use. `GraphDB.execute/close` is what `core/db.py` returns.
`core/db_kuzu.py` `KuzuGraphDB` + `KuzuQueryResult` adapters — thin passthroughs. `.raw` escape hatch for Kuzu-specific helpers during the migration window.
`core/db.py` `get_connection()` and `get_readonly_connection()` now return a `GraphDB` (concretely a KuzuGraphDB today). Singleton caching unchanged.
`tests/test_core/test_db_protocol.py` 7 new tests pinning the contract.

Zero behaviour change

  • 235 (was) + 7 (new) = 242 tests green
  • All MCP tools work
  • Indexer works
  • CLI smoke-tested

What this unblocks

  • `feature/duckdb-schema` — DuckDB DDL + DuckDBGraphDB behind a `CGH_DB=duckdb` env var
  • `feature/duckdb-queries` — port MCP tools one file at a time, both backends green via env var
  • `feature/duckdb-federation` — ATTACH-based federation
  • `release/0.5.0` — flip default to DuckDB, deprecate Kuzu
  • `release/0.6.0` — remove Kuzu code + dependency entirely

First step in the Kuzu -> DuckDB migration: a thin protocol layer
so future backends slot in without touching call sites.

What lands:

- codegraph/core/protocol.py: two runtime-checkable Protocols.
  - QueryResult: has_next(), get_next(), get_column_names() — the
    exact surface every caller in cgh uses today.
  - GraphDB: execute(query, params) -> QueryResult, close().
    Cypher today, SQL when DuckDB lands.

- codegraph/core/db_kuzu.py: KuzuGraphDB + KuzuQueryResult adapters.
  Thin passthroughs. KuzuGraphDB.raw exposes the inner Connection so
  Kuzu-specific helpers (federation, ...) keep working until the
  swap finishes.

- codegraph/core/db.py: get_connection() and get_readonly_connection()
  now return a GraphDB (concretely a KuzuGraphDB today). Singleton
  caching unchanged. The raw kuzu.Database refs stay so
  reset_connection() can still call close() explicitly — Kuzu's file
  lock outlives the GC otherwise.

- tests/test_core/test_db_protocol.py: 7 tests pinning the contract.
  Confirms KuzuGraphDB is a GraphDB at runtime, execute() returns a
  QueryResult, params are forwarded, and the .raw escape hatch is in
  place for the migration window.

Zero behaviour change: 235 (was) + 7 (new) = 242 tests green, all
MCP tools work, indexer works.

What this UNblocks (future PRs):

  feature/duckdb-schema   DuckDB DDL + DuckDBGraphDB behind CGH_DB env var
  feature/duckdb-queries  Port MCP tools one file at a time
  feature/duckdb-federation  ATTACH-based federation
  release/0.5.0           Flip default to DuckDB, deprecate Kuzu
  release/0.6.0           Remove Kuzu code + dependency entirely
@joy-software joy-software merged commit f7f4868 into develop Jun 1, 2026
1 check passed
@joy-software joy-software deleted the feature/db-protocol branch June 1, 2026 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant