/* DBIndex = { name : "" , // Index name; undefined for PK isPrimaryKey : true , // true for PK; otherwise undefined isUnique : true , // true or false isOrdered : true , // true or false; can scan if true columnNumbers : [] , // an ordered array of column numbers }; */ Handle<Object> GetTableCall::buildDBIndex_PK() { HandleScope scope; Local<Object> obj = Object::New(); obj->Set(String::NewSymbol("isPrimaryKey"), Boolean::New(true), ReadOnly); obj->Set(String::NewSymbol("isUnique"), Boolean::New(true), ReadOnly); obj->Set(String::NewSymbol("isOrdered"), Boolean::New(false), ReadOnly); /* Loop over the columns of the key. Build the "columnNumbers" array and the "record" object, then set both. */ int ncol = ndb_table->getNoOfPrimaryKeys(); DEBUG_PRINT("Creating Primary Key Record"); Record * pk_record = new Record(arg0->dict, ncol); Local<Array> idx_columns = Array::New(ncol); for(int i = 0 ; i < ncol ; i++) { const char * col_name = ndb_table->getPrimaryKey(i); const NdbDictionary::Column * col = ndb_table->getColumn(col_name); pk_record->addColumn(col); idx_columns->Set(i, v8::Int32::New(col->getColumnNo())); } pk_record->completeTableRecord(ndb_table); obj->Set(String::NewSymbol("columnNumbers"), idx_columns); obj->Set(String::NewSymbol("record"), Record_Wrapper(pk_record), ReadOnly); return scope.Close(obj); }
/* DBIndex = { name : "" , // Index name isPrimaryKey : true , // true for PK; otherwise undefined isUnique : true , // true or false isOrdered : true , // true or false; can scan if true columnNumbers : [] , // an ordered array of column numbers }; */ Handle<Object> GetTableCall::buildDBIndex_PK() { EscapableHandleScope scope(isolate); Local<Object> obj = Object::New(isolate); SET_RO_PROPERTY(obj, SYMBOL(isolate, "name"), String::NewFromUtf8(isolate, "PRIMARY_KEY")); SET_RO_PROPERTY(obj, SYMBOL(isolate, "isPrimaryKey"), Boolean::New(isolate, true)); SET_RO_PROPERTY(obj, SYMBOL(isolate, "isUnique"), Boolean::New(isolate, true)); SET_RO_PROPERTY(obj, SYMBOL(isolate, "isOrdered"), Boolean::New(isolate, false)); /* Loop over the columns of the key. Build the "columnNumbers" array and the "record" object, then set both. */ int ncol = ndb_table->getNoOfPrimaryKeys(); DEBUG_PRINT("Creating Primary Key Record"); Record * pk_record = new Record(dict, ncol); Local<Array> idx_columns = Array::New(isolate, ncol); for(int i = 0 ; i < ncol ; i++) { const char * col_name = ndb_table->getPrimaryKey(i); const NdbDictionary::Column * col = ndb_table->getColumn(col_name); pk_record->addColumn(col); idx_columns->Set(i, v8::Int32::New(isolate, col->getColumnNo())); } pk_record->completeTableRecord(ndb_table); obj->Set(SYMBOL(isolate, "columnNumbers"), idx_columns); SET_RO_PROPERTY(obj, SYMBOL(isolate, "record"), Record_Wrapper(pk_record)); return scope.Escape(obj); }