Skip to content

Run Cypher queries from the rdx console#883

Open
paracycle wants to merge 1 commit into
uk_add_cypher_query_enginefrom
uk_rdx_console_query_mode
Open

Run Cypher queries from the rdx console#883
paracycle wants to merge 1 commit into
uk_add_cypher_query_enginefrom
uk_rdx_console_query_mode

Conversation

@paracycle

Copy link
Copy Markdown
Member

Goal

Let rdx console run Cypher directly, addressing the "query mode" idea from #868's review.

Stacked on #868 (base uk_add_cypher_query_engine).

What it does

On top of the normal IRB session (with graph in scope for Ruby, e.g. graph["Foo"]), it registers two commands:

rubydex> query MATCH (n:Class|Module) RETURN n.name ORDER BY n.name
rubydex> schema

The query command takes the rest of the line verbatim, so the Cypher doesn't need to be valid Ruby or quoted. Rather than swapping the REPL's evaluator for a modal toggle, Cypher lines are simply prefixed with query — the clean, idiomatic IRB realization of a query mode.

Notes

  • Console logic is extracted into lib/rubydex/console.rb; the query path lives in Console.run_query so it's testable without driving IRB.
  • IRB stays a soft dependency: it's a default gem, so it's not declared in the gemspec. The commands register only when the installed IRB exposes the command API (>= 1.13); on older IRB the console degrades to a plain Ruby session.
  • Currently uses Query#render (string output). Once an object-returning Query#run lands, query could return real handle objects instead of a printed table.

Verification

rake ruby_test TEST=test/console_test.rb (7 tests), rubocop clean, live console smoke test.

@paracycle paracycle requested a review from a team as a code owner June 25, 2026 20:25
@paracycle paracycle force-pushed the uk_add_cypher_query_engine branch from f6e2615 to 7e08a7b Compare June 25, 2026 20:31
@paracycle paracycle force-pushed the uk_rdx_console_query_mode branch from 3943846 to e8308d4 Compare June 25, 2026 20:32
Add `Rubydex::Console`, which backs `rdx console` with an IRB session that
keeps `graph` in scope (for Ruby, e.g. `graph["Foo"]`) and registers two
Cypher commands via IRB's modern command API:

  rubydex> query MATCH (n:Class|Module) RETURN n.name ORDER BY n.name
  rubydex> schema

The `query` command takes the rest of the line verbatim, so the Cypher
does not need to be valid Ruby or quoted. This is the clean, idiomatic
"query mode": rather than swapping the REPL's evaluator, Cypher lines are
prefixed with `query`.

- Extract the console out of exe/rdx into lib/rubydex/console.rb; the
  query-running logic lives in Console.run_query so it is testable without
  driving IRB.
- Treat IRB as a soft, runtime dependency rather than a gemspec one. IRB is
  a default gem, so it is not declared in the gemspec; the Cypher commands
  register only when the installed IRB exposes the command API (>= 1.13),
  and the console degrades to a plain Ruby session on older versions.
@paracycle paracycle force-pushed the uk_rdx_console_query_mode branch from e8308d4 to 9306fe5 Compare June 25, 2026 20:33
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