Class: Rubydex::Query

Inherits:
Object
  • Object
show all
Defined in:
ext/rubydex/query.c

Defined Under Namespace

Classes: Result

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse(query) ⇒ Object



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);
}

.schema(*args) ⇒ Object



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_obj) ⇒ Object



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;
}