Run Cypher queries from the rdx console#883
Open
paracycle wants to merge 1 commit into
Open
Conversation
f6e2615 to
7e08a7b
Compare
3943846 to
e8308d4
Compare
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.
e8308d4 to
9306fe5
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
Let
rdx consolerun 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
graphin scope for Ruby, e.g.graph["Foo"]), it registers two commands:The
querycommand 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 withquery— the clean, idiomatic IRB realization of a query mode.Notes
lib/rubydex/console.rb; the query path lives inConsole.run_queryso it's testable without driving IRB.Query#render(string output). Once an object-returningQuery#runlands,querycould 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.