Class: OracleDB::Soda::Db
- Inherits:
-
Object
- Object
- OracleDB::Soda::Db
- Defined in:
- ext/oracledb/rboradb_soda.c
Instance Method Summary collapse
- #collection_names(*args) ⇒ Object
- #collections(*args) ⇒ Object
- #create_collection(*args) ⇒ Object
- #create_document(key, content, media_type) ⇒ Object
- #initialize(*args) ⇒ Object constructor
- #open_collection(name) ⇒ Object
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
#collection_names(*args) ⇒ Object
499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 |
# File 'ext/oracledb/rboradb_soda.c', line 499
static VALUE soda_db_collection_names(int argc, VALUE *argv, VALUE self)
{
SodaDb_t *db = To_SodaDb(self);
dpiSodaCollNames names;
VALUE start_name, kwopts, limit;
VALUE ary;
uint32_t idx;
static ID keywords[1];
if (!keywords[0]) {
keywords[0] = rb_intern_const("limit");
}
rb_scan_args(argc, argv, "01:", &start_name, &kwopts);
rb_get_kwargs(kwopts, keywords, 0, 1, &limit);
OptExportString(start_name);
if (limit == Qundef) {
limit = INT2FIX(0);
}
if (dpiSodaDb_getCollectionNames(db->handle, OPT_RSTRING_PTR(start_name), OPT_RSTRING_LEN(start_name), NUM2UINT(limit), 0, &names) != DPI_SUCCESS) {
RBORADB_RAISE_ERROR(db);
}
ary = rb_ary_new_capa(names.numNames);
for (idx = 0; idx < names.numNames; idx++) {
rb_ary_push(ary, rb_enc_str_new(names.names[idx], names.nameLengths[idx], rb_utf8_encoding()));
}
dpiSodaDb_freeCollectionNames(db->handle, &names);
return ary;
}
|
#collections(*args) ⇒ Object
475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 |
# File 'ext/oracledb/rboradb_soda.c', line 475
static VALUE soda_db_collections(int argc, VALUE *argv, VALUE self)
{
SodaDb_t *db = To_SodaDb(self);
VALUE start_name;
SodaCollCursor_t cursor;
int state;
rb_scan_args(argc, argv, "01", &start_name);
RETURN_ENUMERATOR(self, 0, 0);
OptExportString(start_name);
if (dpiSodaDb_getCollections(db->handle, OPT_RSTRING_PTR(start_name), OPT_RSTRING_LEN(start_name), 0, &cursor.handle) != DPI_SUCCESS) {
RBORADB_RAISE_ERROR(db);
}
cursor.dconn = db->dconn;
cursor.proc = rb_block_proc();
rb_protect(iter_coll_cursor, (VALUE)&cursor, &state);
dpiSodaCollCursor_release(cursor.handle);
if (state) {
rb_jump_tag(state);
}
return Qnil;
}
|
#create_collection(*args) ⇒ Object
412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 |
# File 'ext/oracledb/rboradb_soda.c', line 412
static VALUE soda_db_create_collection(int argc, VALUE *argv, VALUE self)
{
SodaDb_t *db = To_SodaDb(self);
VALUE name, kwopts, metadata, map;
uint32_t flags;
dpiSodaColl *handle;
static ID keywords[1];
if (!keywords[0]) {
keywords[0] = rb_intern_const("map");
}
rb_scan_args(argc, argv, "20:", &name, &metadata, &kwopts);
rb_get_kwargs(kwopts, keywords, 0, 1, &map);
ExportString(name);
ExportString(metadata);
flags = (map != Qundef && RTEST(map)) ? DPI_SODA_FLAGS_CREATE_COLL_MAP : 0;
if (dpiSodaDb_createCollection(db->handle, RSTRING_PTR(name), RSTRING_LEN(name),
RSTRING_PTR(metadata), RSTRING_LEN(metadata), flags, &handle) != DPI_SUCCESS) {
RBORADB_RAISE_ERROR(db);
}
return soda_coll_new(handle, db->dconn);
}
|
#create_document(key, content, media_type) ⇒ Object
436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 |
# File 'ext/oracledb/rboradb_soda.c', line 436
static VALUE soda_db_create_document(VALUE self, VALUE key, VALUE content, VALUE media_type)
{
SodaDb_t *db = To_SodaDb(self);
dpiSodaDoc *handle;
static const char *application_json = "application/json";
const size_t application_json_len = strlen(application_json);
OptExportString(key);
SafeStringValue(content);
OptExportString(media_type);
if (NIL_P(media_type) || (RSTRING_LEN(media_type) == application_json_len && memcmp(RSTRING_PTR(media_type), application_json, application_json_len) == 0)) {
content = rb_str_export_to_enc(content, rb_utf8_encoding());
}
if (dpiSodaDb_createDocument(db->handle, OPT_RSTRING_PTR(key), OPT_RSTRING_LEN(key),
RSTRING_PTR(content), RSTRING_LEN(content), OPT_RSTRING_PTR(media_type), OPT_RSTRING_LEN(media_type), 0, &handle) != DPI_SUCCESS) {
RBORADB_RAISE_ERROR(db);
}
return soda_doc_new(handle, db->dconn);
}
|
#open_collection(name) ⇒ Object
529 530 531 532 533 534 535 536 537 538 539 |
# File 'ext/oracledb/rboradb_soda.c', line 529
static VALUE soda_db_open_collection(VALUE self, VALUE name)
{
SodaDb_t *db = To_SodaDb(self);
dpiSodaColl *handle;
ExportString(name);
if (dpiSodaDb_openCollection(db->handle, RSTRING_PTR(name), RSTRING_LEN(name), 0, &handle) != DPI_SUCCESS) {
RBORADB_RAISE_ERROR(db);
}
return soda_coll_new(handle, db->dconn);
}
|