Class: Rubydex::Query
- Inherits:
-
Object
- Object
- Rubydex::Query
- Defined in:
- ext/rubydex/query.c
Defined Under Namespace
Classes: Result
Class Method Summary collapse
-
.Rubydex::Query.parse(query) ⇒ Rubydex::Query
Parses a Cypher query into an opaque, reusable object without needing a graph.
-
.Rubydex::Query.schema(format = :table) ⇒ String
Returns a description of the queryable Cypher schema.
Instance Method Summary collapse
-
#run(graph) ⇒ Rubydex::Query::Result
Runs this parsed query against
graphexactly once and returns the result set.
Class Method Details
.Rubydex::Query.parse(query) ⇒ Rubydex::Query
Parses a Cypher query into an opaque, reusable object without needing a graph. Raises Rubydex::QuerySyntaxError on a syntax error, so a query can be validated before building a graph.
88 89 90 91 92 93 94 95 96 97 |
# File 'ext/rubydex/query.c', line 88 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) { raise_query_error(result.error, result.error_kind); } return TypedData_Wrap_Struct(klass, &query_type, result.query); } |
.Rubydex::Query.schema(format = :table) ⇒ String
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.
48 49 50 51 52 53 54 55 56 57 58 59 |
# File 'ext/rubydex/query.c', line 48 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; } |
Instance Method Details
#run(graph) ⇒ Rubydex::Query::Result
Runs this parsed query against graph exactly once and returns the result set. Read it as Ruby
objects with Rubydex::Query::Result#rows, or format it with Rubydex::Query::Result#render. Raises
Rubydex::QueryExecutionError when the query fails against the graph.
159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
# File 'ext/rubydex/query.c', line 159 static VALUE rdxr_query_run(VALUE self, VALUE graph_obj) { void *query; TypedData_Get_Struct(self, void *, &query_type, query); // Wrap first, so the result set has an owner that frees it even if a later step raises. QueryResultData *data; VALUE result = TypedData_Make_Struct(cQueryResult, QueryResultData, &query_result_type, data); data->result_set = NULL; data->graph_obj = graph_obj; data->rows = Qnil; struct CExecuteResult executed = rdx_query_execute(query, rdxi_graph_from_object(graph_obj)); if (executed.error != NULL) { raise_query_error(executed.error, executed.error_kind); } data->result_set = executed.result_set; return result; } |