Class: OracleDB::Soda::Coll

Inherits:
Object
  • Object
show all
Defined in:
ext/oracledb/rboradb_soda.c

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ Object



121
122
123
124
# File 'ext/oracledb/rboradb.c', line 121

VALUE rboradb_notimplement(int argc, VALUE *argv, VALUE self)
{
    rb_notimplement();
}

Instance Method Details

#create_index(index_spec) ⇒ Object



108
109
110
111
112
113
114
115
116
117
# File 'ext/oracledb/rboradb_soda.c', line 108

static VALUE soda_coll_create_index(VALUE self, VALUE index_spec)
{
    SodaColl_t *coll = To_SodaColl(self);

    ExportString(index_spec);
    if (dpiSodaColl_createIndex(coll->handle, RSTRING_PTR(index_spec), RSTRING_LEN(index_spec), 0) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    return Qnil;
}

#data_guideObject



217
218
219
220
221
222
223
224
225
226
# File 'ext/oracledb/rboradb_soda.c', line 217

static VALUE soda_coll_data_guide(VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    dpiSodaDoc *handle;

    if (dpiSodaColl_getDataGuide(coll->handle, 0, &handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    return handle ? soda_doc_new(handle, coll->dconn) : Qnil;
}

#doc_count(*args) ⇒ Object



228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
# File 'ext/oracledb/rboradb_soda.c', line 228

static VALUE soda_coll_doc_count(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE kwopts;
    dpiSodaOperOptions dpi_opts;
    VALUE gc_guard;
    uint64_t count;

    rb_scan_args(argc, argv, "00:", &kwopts);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    if (dpiSodaColl_getDocCount(coll->handle, &dpi_opts, 0, &count) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    return ULL2NUM(count);
}

#dropObject



119
120
121
122
123
124
125
126
127
128
# File 'ext/oracledb/rboradb_soda.c', line 119

static VALUE soda_coll_drop(VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    int is_dropped;

    if (dpiSodaColl_drop(coll->handle, 0, &is_dropped) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    return is_dropped ? Qtrue : Qfalse;
}

#drop_index(*args) ⇒ Object



130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'ext/oracledb/rboradb_soda.c', line 130

static VALUE soda_coll_drop_index(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE name, kwopts, force;
    int is_dropped;
    uint32_t flags;
    static ID keywords[1];

    if (!keywords[0]) {
        keywords[0] = rb_intern_const("force");
    }
    rb_scan_args(argc, argv, "10:", &name, &kwopts);
    rb_get_kwargs(kwopts, keywords, 0, 1, &force);

    ExportString(name);
    flags = ((force != Qundef) && RTEST(force)) ? DPI_SODA_FLAGS_INDEX_DROP_FORCE : 0;
    if (dpiSodaColl_dropIndex(coll->handle, RSTRING_PTR(name), RSTRING_LEN(name), flags, &is_dropped) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    return is_dropped ? Qtrue : Qfalse;
}

#find(*args) ⇒ Object



171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'ext/oracledb/rboradb_soda.c', line 171

static VALUE soda_coll_find(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE kwopts;
    dpiSodaOperOptions dpi_opts;
    SodaDocCursor_t cursor;
    VALUE gc_guard;
    int state;

    RETURN_ENUMERATOR(self, 0, 0);
    rb_scan_args(argc, argv, "00:", &kwopts);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    if (dpiSodaColl_find(coll->handle, &dpi_opts, 0, &cursor.handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    cursor.dconn = coll->dconn;
    cursor.proc = rb_block_proc();
    rb_protect(iter_doc_cursor, (VALUE)&cursor, &state);
    RB_GC_GUARD(cursor.proc);
    dpiSodaDocCursor_release(cursor.handle);
    if (state) {
        rb_jump_tag(state);
    }
    return Qnil;
}

#find_one(*args) ⇒ Object



199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'ext/oracledb/rboradb_soda.c', line 199

static VALUE soda_coll_find_one(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE kwopts;
    dpiSodaOperOptions dpi_opts;
    VALUE gc_guard;
    dpiSodaDoc *handle;

    rb_scan_args(argc, argv, "00:", &kwopts);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    if (dpiSodaColl_findOne(coll->handle, &dpi_opts, 0, &handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    return handle ? soda_doc_new(handle, coll->dconn) : Qnil;
}

#insert_many(*args) ⇒ Object



256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
# File 'ext/oracledb/rboradb_soda.c', line 256

static VALUE soda_coll_insert_many(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE kwopts, docs;
    dpiSodaDoc **handles;
    dpiSodaOperOptions dpi_opts;
    VALUE gc_guard;
    size_t i, size;
    VALUE tmp;
    VALUE ary;

    rb_scan_args(argc, argv, "10:", &docs, &kwopts);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    Check_Type(docs, T_ARRAY);
    size = RARRAY_LEN(docs);
    handles = ALLOCV_N(dpiSodaDoc *, tmp, size * 2);
    for (i = 0; i < size; i++) {
        handles[i] = To_SodaDoc(RARRAY_AREF(docs, i))->handle;
    }
    if (dpiSodaColl_insertManyWithOptions(coll->handle, size, handles, &dpi_opts, 0, handles + size) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    ary = rb_ary_new_capa(size);
    for (i = 0; i < size; i++) {
        rb_ary_push(ary, soda_doc_new(handles[size + i], coll->dconn));
    }
    return ary;
}

#insert_one(*args) ⇒ Object



287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'ext/oracledb/rboradb_soda.c', line 287

static VALUE soda_coll_insert_one(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE doc, kwopts, and_get;
    dpiSodaDoc *handle = NULL;
    dpiSodaOperOptions dpi_opts;
    VALUE gc_guard;
    static ID keywords[1];

    if (!keywords[0]) {
        keywords[0] = rb_intern_const("and_get");
    }
    rb_scan_args(argc, argv, "10:", &doc, &kwopts);
    rb_get_kwargs(kwopts, keywords, 0, -2, &and_get);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    if (dpiSodaColl_insertOneWithOptions(coll->handle, To_SodaDoc(doc)->handle, &dpi_opts, 0, (and_get != Qundef && RTEST(and_get)) ? &handle : NULL) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    return handle ? soda_doc_new(handle, coll->dconn) : Qnil;
}

#metadataObject



246
247
248
249
# File 'ext/oracledb/rboradb_soda.c', line 246

static VALUE soda_coll_metadata(VALUE self)
{
    GET_STR(SodaColl, Metadata);
}

#nameObject



251
252
253
254
# File 'ext/oracledb/rboradb_soda.c', line 251

static VALUE soda_coll_name(VALUE self)
{
    GET_STR(SodaColl, Name);
}

#remove(*args) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'ext/oracledb/rboradb_soda.c', line 310

static VALUE soda_coll_remove(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE kwopts;
    dpiSodaOperOptions dpi_opts;
    VALUE gc_guard;
    uint64_t count;

    rb_scan_args(argc, argv, "00:", &kwopts);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    if (dpiSodaColl_remove(coll->handle, &dpi_opts, 0, &count) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    return ULL2NUM(count);
}

#replace_one(*args) ⇒ Object



328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
# File 'ext/oracledb/rboradb_soda.c', line 328

static VALUE soda_coll_replace_one(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE doc, kwopts, and_get;
    dpiSodaOperOptions dpi_opts;
    VALUE gc_guard;
    int replaced;
    dpiSodaDoc *handle = NULL;
    static ID keywords[1];

    if (!keywords[0]) {
        keywords[0] = rb_intern_const("and_get");
    }
    rb_scan_args(argc, argv, "10:", &doc, &kwopts);
    rb_get_kwargs(kwopts, keywords, 0, -2, &and_get);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    if (dpiSodaColl_replaceOne(coll->handle, &dpi_opts, To_SodaDoc(doc)->handle, 0, &replaced, RTEST(and_get) ? &handle : NULL) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    if (and_get != Qundef && RTEST(and_get)) {
        return replaced ? soda_doc_new(handle, coll->dconn) : Qnil;
    } else {
        return replaced ? Qtrue : Qfalse;
    }
}

#save(*args) ⇒ Object



356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
# File 'ext/oracledb/rboradb_soda.c', line 356

static VALUE soda_coll_save(int argc, VALUE *argv, VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);
    VALUE doc, kwopts, and_get;
    dpiSodaOperOptions dpi_opts;
    VALUE gc_guard;
    dpiSodaDoc *handle = NULL;
    static ID keywords[1];

    if (!keywords[0]) {
        keywords[0] = rb_intern_const("and_get");
    }
    rb_scan_args(argc, argv, "10:", &doc, &kwopts);
    rb_get_kwargs(kwopts, keywords, 0, -2, &and_get);

    gc_guard = init_oper_options(&dpi_opts, kwopts, coll->dconn);
    if (dpiSodaColl_saveWithOptions(coll->handle, To_SodaDoc(doc)->handle, &dpi_opts, 0, (and_get != Qundef && RTEST(and_get)) ? &handle : NULL) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    RB_GC_GUARD(gc_guard);
    return handle ? soda_doc_new(handle, coll->dconn) : Qnil;
}

#truncateObject



379
380
381
382
383
384
385
386
387
# File 'ext/oracledb/rboradb_soda.c', line 379

static VALUE soda_coll_truncate(VALUE self)
{
    SodaColl_t *coll = To_SodaColl(self);

    if (dpiSodaColl_truncate(coll->handle) != DPI_SUCCESS) {
        RBORADB_RAISE_ERROR(coll);
    }
    return Qnil;
}