class Rubydex::Query
Public Class Methods
static VALUE rdxr_query_parse(VALUE klass, VALUE query) {
Check_Type(query, T_STRING);
struct CParseResult result = rdx_cypher_parse(StringValueCStr(query));
if (result.error != NULL) {
VALUE message = rb_utf8_str_new_cstr(result.error);
free_c_string(result.error);
rb_raise(rb_eArgError, "%s", StringValueCStr(message));
}
return TypedData_Wrap_Struct(klass, &query_type, result.query);
}
Parses a Cypher query into an opaque, reusable object without needing a graph. Raises ArgumentError on a syntax error, so a query can be validated before building a graph.
static VALUE rdxr_cypher_schema(int argc, VALUE *argv, VALUE self) {
VALUE format;
rb_scan_args(argc, argv, "01", &format);
const char *output = rdx_cypher_schema(rdxi_symbol_or_string_cstr(format, "table"));
VALUE result = output == NULL ? rb_utf8_str_new_cstr("") : rb_utf8_str_new_cstr(output);
if (output != NULL) {
free_c_string(output);
}
return result;
}
Returns a description of the queryable Cypher schema. format may be :table (default) or :json. The schema is static, so it does not require a graph.
Public Instance Methods
static VALUE rdxr_query_render(int argc, VALUE *argv, VALUE self) {
VALUE graph_obj, format;
rb_scan_args(argc, argv, "11", &graph_obj, &format);
void *query;
TypedData_Get_Struct(self, void *, &query_type, query);
void *graph = rdxi_graph_from_object(graph_obj);
struct CQueryResult result = rdx_query_run(query, graph, rdxi_symbol_or_string_cstr(format, "table"));
if (result.error != NULL) {
VALUE message = rb_utf8_str_new_cstr(result.error);
free_c_string(result.error);
rb_raise(rb_eArgError, "%s", StringValueCStr(message));
}
VALUE output = result.output == NULL ? rb_utf8_str_new_cstr("") : rb_utf8_str_new_cstr(result.output);
if (result.output != NULL) {
free_c_string(result.output);
}
return output;
}
Runs this parsed query against graph and returns the formatted output. format may be :table (default) or :json. Raises ArgumentError on an execution or format error.
static VALUE rdxr_query_run(VALUE self, VALUE graph_obj) {
void *query;
TypedData_Get_Struct(self, void *, &query_type, query);
void *graph = rdxi_graph_from_object(graph_obj);
struct CRunRows run = rdx_query_run_rows(query, graph);
if (run.error != NULL) {
VALUE message = rb_utf8_str_new_cstr(run.error);
free_c_string(run.error);
rb_raise(rb_eArgError, "%s", StringValueCStr(message));
}
VALUE args = rb_ary_new_from_args(2, graph_obj, ULL2NUM((uintptr_t)run.iter));
return rb_ensure(query_run_yield, args, query_run_ensure, args);
}
Runs this parsed query against graph and returns the rows as Ruby objects: each row is a Hash keyed by RETURN column name. Scalar cells become String/Integer/true/false/nil, lists become Arrays, and node cells become Declaration / Definition / Document handles. Raises ArgumentError on an execution error.