├── README.rst ├── gen-nodejs ├── Cassandra.js └── cassandra_types.js ├── lib └── cassandra.js ├── package.json └── test ├── test.ddl └── test.js /README.rst: -------------------------------------------------------------------------------- 1 | **THIS PACKAGE IS NOT MAINTAINED ANY MORE. PLEASE USE https://github.com/simplereach/helenus OR https://github.com/racker/node-cassandra-client INSTEAD.** 2 | 3 | 4 | About 5 | --------- 6 | 7 | node_cassandra is node.js addon for Apache Cassandra(http://cassandra.apache.org). 8 | node_cassandra originally used C++ thrift client, but thanks to node.js support in Thrift ver 0.6, current version uses only javascript. 9 | Currently, only cassandra 0.7.x is supported. 10 | 11 | Requirement 12 | ------------- 13 | 14 | node-thrift, but if you install node_cassandra with npm, it should be installed as well. 15 | 16 | Installation 17 | -------------- 18 | 19 | $ npm install cassandra 20 | 21 | of 22 | 23 | $ git clone https://github.com/yukim/node_cassandra.git 24 | 25 | $ npm install . 26 | 27 | Usage 28 | --------- 29 | 30 | Example usage:: 31 | 32 | var cassandra = require("cassandra"); 33 | var client = new cassandra.Client("host:port"); 34 | var CL = cassandra.ConsistencyLevel; 35 | 36 | client.consistencyLevel({ 37 | write: CL.ONE, 38 | read: CL.ONE 39 | }); 40 | 41 | client.connect("SomeKeySpace"); 42 | var cf = client.getColumnFamily("SomeColumnFamily"); 43 | 44 | var data = cf.get("key", function(err, data) { 45 | // play with data 46 | console.log(data.columnName); 47 | }); 48 | 49 | For more detailed example, see test/test.js. 50 | 51 | Test 52 | -------- 53 | 54 | If you have expresso installed, you can run test with:: 55 | 56 | $ expresso -I lib 57 | 58 | Limitation 59 | ------------ 60 | 61 | Following APIs are not yet supported. 62 | 63 | * get_range_slice 64 | * get_index_slice 65 | * system_* (schema modification APIs) 66 | 67 | License 68 | ----------- 69 | 70 | Apache 2.0 License 71 | -------------------------------------------------------------------------------- /gen-nodejs/cassandra_types.js: -------------------------------------------------------------------------------- 1 | // 2 | // Autogenerated by Thrift 3 | // 4 | // DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING 5 | // 6 | var Thrift = require('thrift').Thrift; 7 | var ttypes = module.exports = {}; 8 | ttypes.ConsistencyLevel = { 9 | 'ONE' : 1 10 | ,'QUORUM' : 2 11 | ,'LOCAL_QUORUM' : 3 12 | ,'EACH_QUORUM' : 4 13 | ,'ALL' : 5 14 | ,'ANY' : 6 15 | } 16 | ttypes.IndexOperator = { 17 | 'EQ' : 0 18 | ,'GTE' : 1 19 | ,'GT' : 2 20 | ,'LTE' : 3 21 | ,'LT' : 4 22 | } 23 | ttypes.IndexType = { 24 | 'KEYS' : 0 25 | } 26 | ttypes.VERSION = '19.4.0' 27 | var Column = module.exports.Column = function(args){ 28 | this.name = null 29 | this.value = null 30 | this.timestamp = null 31 | this.ttl = null 32 | if( args != null ){ if (null != args.name) 33 | this.name = args.name 34 | if (null != args.value) 35 | this.value = args.value 36 | if (null != args.timestamp) 37 | this.timestamp = args.timestamp 38 | if (null != args.ttl) 39 | this.ttl = args.ttl 40 | }} 41 | Column.prototype = {} 42 | Column.prototype.read = function(input){ 43 | var ret = input.readStructBegin() 44 | while (1) 45 | { 46 | var ret = input.readFieldBegin() 47 | var fname = ret.fname 48 | var ftype = ret.ftype 49 | var fid = ret.fid 50 | if (ftype == Thrift.Type.STOP) 51 | break 52 | switch(fid) 53 | { 54 | case 1: if (ftype == Thrift.Type.STRING) { 55 | this.name = input.readString() 56 | } else { 57 | input.skip(ftype) 58 | } 59 | break 60 | case 2: if (ftype == Thrift.Type.STRING) { 61 | this.value = input.readString() 62 | } else { 63 | input.skip(ftype) 64 | } 65 | break 66 | case 3: if (ftype == Thrift.Type.I64) { 67 | this.timestamp = input.readI64() 68 | } else { 69 | input.skip(ftype) 70 | } 71 | break 72 | case 4: if (ftype == Thrift.Type.I32) { 73 | this.ttl = input.readI32() 74 | } else { 75 | input.skip(ftype) 76 | } 77 | break 78 | default: 79 | input.skip(ftype) 80 | } 81 | input.readFieldEnd() 82 | } 83 | input.readStructEnd() 84 | return 85 | } 86 | 87 | Column.prototype.write = function(output){ 88 | output.writeStructBegin('Column') 89 | if (null != this.name) { 90 | output.writeFieldBegin('name', Thrift.Type.STRING, 1) 91 | output.writeString(this.name) 92 | output.writeFieldEnd() 93 | } 94 | if (null != this.value) { 95 | output.writeFieldBegin('value', Thrift.Type.STRING, 2) 96 | output.writeString(this.value) 97 | output.writeFieldEnd() 98 | } 99 | if (null != this.timestamp) { 100 | output.writeFieldBegin('timestamp', Thrift.Type.I64, 3) 101 | output.writeI64(this.timestamp) 102 | output.writeFieldEnd() 103 | } 104 | if (null != this.ttl) { 105 | output.writeFieldBegin('ttl', Thrift.Type.I32, 4) 106 | output.writeI32(this.ttl) 107 | output.writeFieldEnd() 108 | } 109 | output.writeFieldStop() 110 | output.writeStructEnd() 111 | return 112 | } 113 | 114 | var SuperColumn = module.exports.SuperColumn = function(args){ 115 | this.name = null 116 | this.columns = null 117 | if( args != null ){ if (null != args.name) 118 | this.name = args.name 119 | if (null != args.columns) 120 | this.columns = args.columns 121 | }} 122 | SuperColumn.prototype = {} 123 | SuperColumn.prototype.read = function(input){ 124 | var ret = input.readStructBegin() 125 | while (1) 126 | { 127 | var ret = input.readFieldBegin() 128 | var fname = ret.fname 129 | var ftype = ret.ftype 130 | var fid = ret.fid 131 | if (ftype == Thrift.Type.STOP) 132 | break 133 | switch(fid) 134 | { 135 | case 1: if (ftype == Thrift.Type.STRING) { 136 | this.name = input.readString() 137 | } else { 138 | input.skip(ftype) 139 | } 140 | break 141 | case 2: if (ftype == Thrift.Type.LIST) { 142 | { 143 | var _size0 = 0 144 | var rtmp3 145 | this.columns = [] 146 | var _etype3 = 0 147 | rtmp3 = input.readListBegin() 148 | _etype3 = rtmp3.etype 149 | _size0 = rtmp3.size 150 | for (var _i4 = 0; _i4 < _size0; ++_i4) 151 | { 152 | var elem5 = null 153 | elem5 = new ttypes.Column() 154 | elem5.read(input) 155 | this.columns.push(elem5) 156 | } 157 | input.readListEnd() 158 | } 159 | } else { 160 | input.skip(ftype) 161 | } 162 | break 163 | default: 164 | input.skip(ftype) 165 | } 166 | input.readFieldEnd() 167 | } 168 | input.readStructEnd() 169 | return 170 | } 171 | 172 | SuperColumn.prototype.write = function(output){ 173 | output.writeStructBegin('SuperColumn') 174 | if (null != this.name) { 175 | output.writeFieldBegin('name', Thrift.Type.STRING, 1) 176 | output.writeString(this.name) 177 | output.writeFieldEnd() 178 | } 179 | if (null != this.columns) { 180 | output.writeFieldBegin('columns', Thrift.Type.LIST, 2) 181 | { 182 | output.writeListBegin(Thrift.Type.STRUCT, this.columns.length) 183 | { 184 | for(var iter6 in this.columns) 185 | { 186 | if (this.columns.hasOwnProperty(iter6)) 187 | { 188 | iter6=this.columns[iter6] 189 | iter6.write(output) 190 | } 191 | } 192 | } 193 | output.writeListEnd() 194 | } 195 | output.writeFieldEnd() 196 | } 197 | output.writeFieldStop() 198 | output.writeStructEnd() 199 | return 200 | } 201 | 202 | var ColumnOrSuperColumn = module.exports.ColumnOrSuperColumn = function(args){ 203 | this.column = null 204 | this.super_column = null 205 | if( args != null ){ if (null != args.column) 206 | this.column = args.column 207 | if (null != args.super_column) 208 | this.super_column = args.super_column 209 | }} 210 | ColumnOrSuperColumn.prototype = {} 211 | ColumnOrSuperColumn.prototype.read = function(input){ 212 | var ret = input.readStructBegin() 213 | while (1) 214 | { 215 | var ret = input.readFieldBegin() 216 | var fname = ret.fname 217 | var ftype = ret.ftype 218 | var fid = ret.fid 219 | if (ftype == Thrift.Type.STOP) 220 | break 221 | switch(fid) 222 | { 223 | case 1: if (ftype == Thrift.Type.STRUCT) { 224 | this.column = new ttypes.Column() 225 | this.column.read(input) 226 | } else { 227 | input.skip(ftype) 228 | } 229 | break 230 | case 2: if (ftype == Thrift.Type.STRUCT) { 231 | this.super_column = new ttypes.SuperColumn() 232 | this.super_column.read(input) 233 | } else { 234 | input.skip(ftype) 235 | } 236 | break 237 | default: 238 | input.skip(ftype) 239 | } 240 | input.readFieldEnd() 241 | } 242 | input.readStructEnd() 243 | return 244 | } 245 | 246 | ColumnOrSuperColumn.prototype.write = function(output){ 247 | output.writeStructBegin('ColumnOrSuperColumn') 248 | if (null != this.column) { 249 | output.writeFieldBegin('column', Thrift.Type.STRUCT, 1) 250 | this.column.write(output) 251 | output.writeFieldEnd() 252 | } 253 | if (null != this.super_column) { 254 | output.writeFieldBegin('super_column', Thrift.Type.STRUCT, 2) 255 | this.super_column.write(output) 256 | output.writeFieldEnd() 257 | } 258 | output.writeFieldStop() 259 | output.writeStructEnd() 260 | return 261 | } 262 | 263 | var NotFoundException = module.exports.NotFoundException = function(args){ 264 | Thrift.TException.call(this, "NotFoundException") 265 | this.name = "NotFoundException" 266 | } 267 | Thrift.inherits(NotFoundException, Thrift.TException) 268 | NotFoundException.prototype.read = function(input){ 269 | var ret = input.readStructBegin() 270 | while (1) 271 | { 272 | var ret = input.readFieldBegin() 273 | var fname = ret.fname 274 | var ftype = ret.ftype 275 | var fid = ret.fid 276 | if (ftype == Thrift.Type.STOP) 277 | break 278 | switch(fid) 279 | { 280 | default: 281 | input.skip(ftype) 282 | } 283 | input.readFieldEnd() 284 | } 285 | input.readStructEnd() 286 | return 287 | } 288 | 289 | NotFoundException.prototype.write = function(output){ 290 | output.writeStructBegin('NotFoundException') 291 | output.writeFieldStop() 292 | output.writeStructEnd() 293 | return 294 | } 295 | 296 | var InvalidRequestException = module.exports.InvalidRequestException = function(args){ 297 | Thrift.TException.call(this, "InvalidRequestException") 298 | this.name = "InvalidRequestException" 299 | this.why = null 300 | if( args != null ){ if (null != args.why) 301 | this.why = args.why 302 | }} 303 | Thrift.inherits(InvalidRequestException, Thrift.TException) 304 | InvalidRequestException.prototype.read = function(input){ 305 | var ret = input.readStructBegin() 306 | while (1) 307 | { 308 | var ret = input.readFieldBegin() 309 | var fname = ret.fname 310 | var ftype = ret.ftype 311 | var fid = ret.fid 312 | if (ftype == Thrift.Type.STOP) 313 | break 314 | switch(fid) 315 | { 316 | case 1: if (ftype == Thrift.Type.STRING) { 317 | this.why = input.readString() 318 | } else { 319 | input.skip(ftype) 320 | } 321 | break 322 | default: 323 | input.skip(ftype) 324 | } 325 | input.readFieldEnd() 326 | } 327 | input.readStructEnd() 328 | return 329 | } 330 | 331 | InvalidRequestException.prototype.write = function(output){ 332 | output.writeStructBegin('InvalidRequestException') 333 | if (null != this.why) { 334 | output.writeFieldBegin('why', Thrift.Type.STRING, 1) 335 | output.writeString(this.why) 336 | output.writeFieldEnd() 337 | } 338 | output.writeFieldStop() 339 | output.writeStructEnd() 340 | return 341 | } 342 | 343 | var UnavailableException = module.exports.UnavailableException = function(args){ 344 | Thrift.TException.call(this, "UnavailableException") 345 | this.name = "UnavailableException" 346 | } 347 | Thrift.inherits(UnavailableException, Thrift.TException) 348 | UnavailableException.prototype.read = function(input){ 349 | var ret = input.readStructBegin() 350 | while (1) 351 | { 352 | var ret = input.readFieldBegin() 353 | var fname = ret.fname 354 | var ftype = ret.ftype 355 | var fid = ret.fid 356 | if (ftype == Thrift.Type.STOP) 357 | break 358 | switch(fid) 359 | { 360 | default: 361 | input.skip(ftype) 362 | } 363 | input.readFieldEnd() 364 | } 365 | input.readStructEnd() 366 | return 367 | } 368 | 369 | UnavailableException.prototype.write = function(output){ 370 | output.writeStructBegin('UnavailableException') 371 | output.writeFieldStop() 372 | output.writeStructEnd() 373 | return 374 | } 375 | 376 | var TimedOutException = module.exports.TimedOutException = function(args){ 377 | Thrift.TException.call(this, "TimedOutException") 378 | this.name = "TimedOutException" 379 | } 380 | Thrift.inherits(TimedOutException, Thrift.TException) 381 | TimedOutException.prototype.read = function(input){ 382 | var ret = input.readStructBegin() 383 | while (1) 384 | { 385 | var ret = input.readFieldBegin() 386 | var fname = ret.fname 387 | var ftype = ret.ftype 388 | var fid = ret.fid 389 | if (ftype == Thrift.Type.STOP) 390 | break 391 | switch(fid) 392 | { 393 | default: 394 | input.skip(ftype) 395 | } 396 | input.readFieldEnd() 397 | } 398 | input.readStructEnd() 399 | return 400 | } 401 | 402 | TimedOutException.prototype.write = function(output){ 403 | output.writeStructBegin('TimedOutException') 404 | output.writeFieldStop() 405 | output.writeStructEnd() 406 | return 407 | } 408 | 409 | var AuthenticationException = module.exports.AuthenticationException = function(args){ 410 | Thrift.TException.call(this, "AuthenticationException") 411 | this.name = "AuthenticationException" 412 | this.why = null 413 | if( args != null ){ if (null != args.why) 414 | this.why = args.why 415 | }} 416 | Thrift.inherits(AuthenticationException, Thrift.TException) 417 | AuthenticationException.prototype.read = function(input){ 418 | var ret = input.readStructBegin() 419 | while (1) 420 | { 421 | var ret = input.readFieldBegin() 422 | var fname = ret.fname 423 | var ftype = ret.ftype 424 | var fid = ret.fid 425 | if (ftype == Thrift.Type.STOP) 426 | break 427 | switch(fid) 428 | { 429 | case 1: if (ftype == Thrift.Type.STRING) { 430 | this.why = input.readString() 431 | } else { 432 | input.skip(ftype) 433 | } 434 | break 435 | default: 436 | input.skip(ftype) 437 | } 438 | input.readFieldEnd() 439 | } 440 | input.readStructEnd() 441 | return 442 | } 443 | 444 | AuthenticationException.prototype.write = function(output){ 445 | output.writeStructBegin('AuthenticationException') 446 | if (null != this.why) { 447 | output.writeFieldBegin('why', Thrift.Type.STRING, 1) 448 | output.writeString(this.why) 449 | output.writeFieldEnd() 450 | } 451 | output.writeFieldStop() 452 | output.writeStructEnd() 453 | return 454 | } 455 | 456 | var AuthorizationException = module.exports.AuthorizationException = function(args){ 457 | Thrift.TException.call(this, "AuthorizationException") 458 | this.name = "AuthorizationException" 459 | this.why = null 460 | if( args != null ){ if (null != args.why) 461 | this.why = args.why 462 | }} 463 | Thrift.inherits(AuthorizationException, Thrift.TException) 464 | AuthorizationException.prototype.read = function(input){ 465 | var ret = input.readStructBegin() 466 | while (1) 467 | { 468 | var ret = input.readFieldBegin() 469 | var fname = ret.fname 470 | var ftype = ret.ftype 471 | var fid = ret.fid 472 | if (ftype == Thrift.Type.STOP) 473 | break 474 | switch(fid) 475 | { 476 | case 1: if (ftype == Thrift.Type.STRING) { 477 | this.why = input.readString() 478 | } else { 479 | input.skip(ftype) 480 | } 481 | break 482 | default: 483 | input.skip(ftype) 484 | } 485 | input.readFieldEnd() 486 | } 487 | input.readStructEnd() 488 | return 489 | } 490 | 491 | AuthorizationException.prototype.write = function(output){ 492 | output.writeStructBegin('AuthorizationException') 493 | if (null != this.why) { 494 | output.writeFieldBegin('why', Thrift.Type.STRING, 1) 495 | output.writeString(this.why) 496 | output.writeFieldEnd() 497 | } 498 | output.writeFieldStop() 499 | output.writeStructEnd() 500 | return 501 | } 502 | 503 | var ColumnParent = module.exports.ColumnParent = function(args){ 504 | this.column_family = null 505 | this.super_column = null 506 | if( args != null ){ if (null != args.column_family) 507 | this.column_family = args.column_family 508 | if (null != args.super_column) 509 | this.super_column = args.super_column 510 | }} 511 | ColumnParent.prototype = {} 512 | ColumnParent.prototype.read = function(input){ 513 | var ret = input.readStructBegin() 514 | while (1) 515 | { 516 | var ret = input.readFieldBegin() 517 | var fname = ret.fname 518 | var ftype = ret.ftype 519 | var fid = ret.fid 520 | if (ftype == Thrift.Type.STOP) 521 | break 522 | switch(fid) 523 | { 524 | case 3: if (ftype == Thrift.Type.STRING) { 525 | this.column_family = input.readString() 526 | } else { 527 | input.skip(ftype) 528 | } 529 | break 530 | case 4: if (ftype == Thrift.Type.STRING) { 531 | this.super_column = input.readString() 532 | } else { 533 | input.skip(ftype) 534 | } 535 | break 536 | default: 537 | input.skip(ftype) 538 | } 539 | input.readFieldEnd() 540 | } 541 | input.readStructEnd() 542 | return 543 | } 544 | 545 | ColumnParent.prototype.write = function(output){ 546 | output.writeStructBegin('ColumnParent') 547 | if (null != this.column_family) { 548 | output.writeFieldBegin('column_family', Thrift.Type.STRING, 3) 549 | output.writeString(this.column_family) 550 | output.writeFieldEnd() 551 | } 552 | if (null != this.super_column) { 553 | output.writeFieldBegin('super_column', Thrift.Type.STRING, 4) 554 | output.writeString(this.super_column) 555 | output.writeFieldEnd() 556 | } 557 | output.writeFieldStop() 558 | output.writeStructEnd() 559 | return 560 | } 561 | 562 | var ColumnPath = module.exports.ColumnPath = function(args){ 563 | this.column_family = null 564 | this.super_column = null 565 | this.column = null 566 | if( args != null ){ if (null != args.column_family) 567 | this.column_family = args.column_family 568 | if (null != args.super_column) 569 | this.super_column = args.super_column 570 | if (null != args.column) 571 | this.column = args.column 572 | }} 573 | ColumnPath.prototype = {} 574 | ColumnPath.prototype.read = function(input){ 575 | var ret = input.readStructBegin() 576 | while (1) 577 | { 578 | var ret = input.readFieldBegin() 579 | var fname = ret.fname 580 | var ftype = ret.ftype 581 | var fid = ret.fid 582 | if (ftype == Thrift.Type.STOP) 583 | break 584 | switch(fid) 585 | { 586 | case 3: if (ftype == Thrift.Type.STRING) { 587 | this.column_family = input.readString() 588 | } else { 589 | input.skip(ftype) 590 | } 591 | break 592 | case 4: if (ftype == Thrift.Type.STRING) { 593 | this.super_column = input.readString() 594 | } else { 595 | input.skip(ftype) 596 | } 597 | break 598 | case 5: if (ftype == Thrift.Type.STRING) { 599 | this.column = input.readString() 600 | } else { 601 | input.skip(ftype) 602 | } 603 | break 604 | default: 605 | input.skip(ftype) 606 | } 607 | input.readFieldEnd() 608 | } 609 | input.readStructEnd() 610 | return 611 | } 612 | 613 | ColumnPath.prototype.write = function(output){ 614 | output.writeStructBegin('ColumnPath') 615 | if (null != this.column_family) { 616 | output.writeFieldBegin('column_family', Thrift.Type.STRING, 3) 617 | output.writeString(this.column_family) 618 | output.writeFieldEnd() 619 | } 620 | if (null != this.super_column) { 621 | output.writeFieldBegin('super_column', Thrift.Type.STRING, 4) 622 | output.writeString(this.super_column) 623 | output.writeFieldEnd() 624 | } 625 | if (null != this.column) { 626 | output.writeFieldBegin('column', Thrift.Type.STRING, 5) 627 | output.writeString(this.column) 628 | output.writeFieldEnd() 629 | } 630 | output.writeFieldStop() 631 | output.writeStructEnd() 632 | return 633 | } 634 | 635 | var SliceRange = module.exports.SliceRange = function(args){ 636 | this.start = null 637 | this.finish = null 638 | this.reversed = false 639 | this.count = 100 640 | if( args != null ){ if (null != args.start) 641 | this.start = args.start 642 | if (null != args.finish) 643 | this.finish = args.finish 644 | if (null != args.reversed) 645 | this.reversed = args.reversed 646 | if (null != args.count) 647 | this.count = args.count 648 | }} 649 | SliceRange.prototype = {} 650 | SliceRange.prototype.read = function(input){ 651 | var ret = input.readStructBegin() 652 | while (1) 653 | { 654 | var ret = input.readFieldBegin() 655 | var fname = ret.fname 656 | var ftype = ret.ftype 657 | var fid = ret.fid 658 | if (ftype == Thrift.Type.STOP) 659 | break 660 | switch(fid) 661 | { 662 | case 1: if (ftype == Thrift.Type.STRING) { 663 | this.start = input.readString() 664 | } else { 665 | input.skip(ftype) 666 | } 667 | break 668 | case 2: if (ftype == Thrift.Type.STRING) { 669 | this.finish = input.readString() 670 | } else { 671 | input.skip(ftype) 672 | } 673 | break 674 | case 3: if (ftype == Thrift.Type.BOOL) { 675 | this.reversed = input.readBool() 676 | } else { 677 | input.skip(ftype) 678 | } 679 | break 680 | case 4: if (ftype == Thrift.Type.I32) { 681 | this.count = input.readI32() 682 | } else { 683 | input.skip(ftype) 684 | } 685 | break 686 | default: 687 | input.skip(ftype) 688 | } 689 | input.readFieldEnd() 690 | } 691 | input.readStructEnd() 692 | return 693 | } 694 | 695 | SliceRange.prototype.write = function(output){ 696 | output.writeStructBegin('SliceRange') 697 | if (null != this.start) { 698 | output.writeFieldBegin('start', Thrift.Type.STRING, 1) 699 | output.writeString(this.start) 700 | output.writeFieldEnd() 701 | } 702 | if (null != this.finish) { 703 | output.writeFieldBegin('finish', Thrift.Type.STRING, 2) 704 | output.writeString(this.finish) 705 | output.writeFieldEnd() 706 | } 707 | if (null != this.reversed) { 708 | output.writeFieldBegin('reversed', Thrift.Type.BOOL, 3) 709 | output.writeBool(this.reversed) 710 | output.writeFieldEnd() 711 | } 712 | if (null != this.count) { 713 | output.writeFieldBegin('count', Thrift.Type.I32, 4) 714 | output.writeI32(this.count) 715 | output.writeFieldEnd() 716 | } 717 | output.writeFieldStop() 718 | output.writeStructEnd() 719 | return 720 | } 721 | 722 | var SlicePredicate = module.exports.SlicePredicate = function(args){ 723 | this.column_names = null 724 | this.slice_range = null 725 | if( args != null ){ if (null != args.column_names) 726 | this.column_names = args.column_names 727 | if (null != args.slice_range) 728 | this.slice_range = args.slice_range 729 | }} 730 | SlicePredicate.prototype = {} 731 | SlicePredicate.prototype.read = function(input){ 732 | var ret = input.readStructBegin() 733 | while (1) 734 | { 735 | var ret = input.readFieldBegin() 736 | var fname = ret.fname 737 | var ftype = ret.ftype 738 | var fid = ret.fid 739 | if (ftype == Thrift.Type.STOP) 740 | break 741 | switch(fid) 742 | { 743 | case 1: if (ftype == Thrift.Type.LIST) { 744 | { 745 | var _size7 = 0 746 | var rtmp3 747 | this.column_names = [] 748 | var _etype10 = 0 749 | rtmp3 = input.readListBegin() 750 | _etype10 = rtmp3.etype 751 | _size7 = rtmp3.size 752 | for (var _i11 = 0; _i11 < _size7; ++_i11) 753 | { 754 | var elem12 = null 755 | elem12 = input.readString() 756 | this.column_names.push(elem12) 757 | } 758 | input.readListEnd() 759 | } 760 | } else { 761 | input.skip(ftype) 762 | } 763 | break 764 | case 2: if (ftype == Thrift.Type.STRUCT) { 765 | this.slice_range = new ttypes.SliceRange() 766 | this.slice_range.read(input) 767 | } else { 768 | input.skip(ftype) 769 | } 770 | break 771 | default: 772 | input.skip(ftype) 773 | } 774 | input.readFieldEnd() 775 | } 776 | input.readStructEnd() 777 | return 778 | } 779 | 780 | SlicePredicate.prototype.write = function(output){ 781 | output.writeStructBegin('SlicePredicate') 782 | if (null != this.column_names) { 783 | output.writeFieldBegin('column_names', Thrift.Type.LIST, 1) 784 | { 785 | output.writeListBegin(Thrift.Type.STRING, this.column_names.length) 786 | { 787 | for(var iter13 in this.column_names) 788 | { 789 | if (this.column_names.hasOwnProperty(iter13)) 790 | { 791 | iter13=this.column_names[iter13] 792 | output.writeString(iter13) 793 | } 794 | } 795 | } 796 | output.writeListEnd() 797 | } 798 | output.writeFieldEnd() 799 | } 800 | if (null != this.slice_range) { 801 | output.writeFieldBegin('slice_range', Thrift.Type.STRUCT, 2) 802 | this.slice_range.write(output) 803 | output.writeFieldEnd() 804 | } 805 | output.writeFieldStop() 806 | output.writeStructEnd() 807 | return 808 | } 809 | 810 | var IndexExpression = module.exports.IndexExpression = function(args){ 811 | this.column_name = null 812 | this.op = null 813 | this.value = null 814 | if( args != null ){ if (null != args.column_name) 815 | this.column_name = args.column_name 816 | if (null != args.op) 817 | this.op = args.op 818 | if (null != args.value) 819 | this.value = args.value 820 | }} 821 | IndexExpression.prototype = {} 822 | IndexExpression.prototype.read = function(input){ 823 | var ret = input.readStructBegin() 824 | while (1) 825 | { 826 | var ret = input.readFieldBegin() 827 | var fname = ret.fname 828 | var ftype = ret.ftype 829 | var fid = ret.fid 830 | if (ftype == Thrift.Type.STOP) 831 | break 832 | switch(fid) 833 | { 834 | case 1: if (ftype == Thrift.Type.STRING) { 835 | this.column_name = input.readString() 836 | } else { 837 | input.skip(ftype) 838 | } 839 | break 840 | case 2: if (ftype == Thrift.Type.I32) { 841 | this.op = input.readI32() 842 | } else { 843 | input.skip(ftype) 844 | } 845 | break 846 | case 3: if (ftype == Thrift.Type.STRING) { 847 | this.value = input.readString() 848 | } else { 849 | input.skip(ftype) 850 | } 851 | break 852 | default: 853 | input.skip(ftype) 854 | } 855 | input.readFieldEnd() 856 | } 857 | input.readStructEnd() 858 | return 859 | } 860 | 861 | IndexExpression.prototype.write = function(output){ 862 | output.writeStructBegin('IndexExpression') 863 | if (null != this.column_name) { 864 | output.writeFieldBegin('column_name', Thrift.Type.STRING, 1) 865 | output.writeString(this.column_name) 866 | output.writeFieldEnd() 867 | } 868 | if (null != this.op) { 869 | output.writeFieldBegin('op', Thrift.Type.I32, 2) 870 | output.writeI32(this.op) 871 | output.writeFieldEnd() 872 | } 873 | if (null != this.value) { 874 | output.writeFieldBegin('value', Thrift.Type.STRING, 3) 875 | output.writeString(this.value) 876 | output.writeFieldEnd() 877 | } 878 | output.writeFieldStop() 879 | output.writeStructEnd() 880 | return 881 | } 882 | 883 | var IndexClause = module.exports.IndexClause = function(args){ 884 | this.expressions = null 885 | this.start_key = null 886 | this.count = 100 887 | if( args != null ){ if (null != args.expressions) 888 | this.expressions = args.expressions 889 | if (null != args.start_key) 890 | this.start_key = args.start_key 891 | if (null != args.count) 892 | this.count = args.count 893 | }} 894 | IndexClause.prototype = {} 895 | IndexClause.prototype.read = function(input){ 896 | var ret = input.readStructBegin() 897 | while (1) 898 | { 899 | var ret = input.readFieldBegin() 900 | var fname = ret.fname 901 | var ftype = ret.ftype 902 | var fid = ret.fid 903 | if (ftype == Thrift.Type.STOP) 904 | break 905 | switch(fid) 906 | { 907 | case 1: if (ftype == Thrift.Type.LIST) { 908 | { 909 | var _size14 = 0 910 | var rtmp3 911 | this.expressions = [] 912 | var _etype17 = 0 913 | rtmp3 = input.readListBegin() 914 | _etype17 = rtmp3.etype 915 | _size14 = rtmp3.size 916 | for (var _i18 = 0; _i18 < _size14; ++_i18) 917 | { 918 | var elem19 = null 919 | elem19 = new ttypes.IndexExpression() 920 | elem19.read(input) 921 | this.expressions.push(elem19) 922 | } 923 | input.readListEnd() 924 | } 925 | } else { 926 | input.skip(ftype) 927 | } 928 | break 929 | case 2: if (ftype == Thrift.Type.STRING) { 930 | this.start_key = input.readString() 931 | } else { 932 | input.skip(ftype) 933 | } 934 | break 935 | case 3: if (ftype == Thrift.Type.I32) { 936 | this.count = input.readI32() 937 | } else { 938 | input.skip(ftype) 939 | } 940 | break 941 | default: 942 | input.skip(ftype) 943 | } 944 | input.readFieldEnd() 945 | } 946 | input.readStructEnd() 947 | return 948 | } 949 | 950 | IndexClause.prototype.write = function(output){ 951 | output.writeStructBegin('IndexClause') 952 | if (null != this.expressions) { 953 | output.writeFieldBegin('expressions', Thrift.Type.LIST, 1) 954 | { 955 | output.writeListBegin(Thrift.Type.STRUCT, this.expressions.length) 956 | { 957 | for(var iter20 in this.expressions) 958 | { 959 | if (this.expressions.hasOwnProperty(iter20)) 960 | { 961 | iter20=this.expressions[iter20] 962 | iter20.write(output) 963 | } 964 | } 965 | } 966 | output.writeListEnd() 967 | } 968 | output.writeFieldEnd() 969 | } 970 | if (null != this.start_key) { 971 | output.writeFieldBegin('start_key', Thrift.Type.STRING, 2) 972 | output.writeString(this.start_key) 973 | output.writeFieldEnd() 974 | } 975 | if (null != this.count) { 976 | output.writeFieldBegin('count', Thrift.Type.I32, 3) 977 | output.writeI32(this.count) 978 | output.writeFieldEnd() 979 | } 980 | output.writeFieldStop() 981 | output.writeStructEnd() 982 | return 983 | } 984 | 985 | var KeyRange = module.exports.KeyRange = function(args){ 986 | this.start_key = null 987 | this.end_key = null 988 | this.start_token = null 989 | this.end_token = null 990 | this.count = 100 991 | if( args != null ){ if (null != args.start_key) 992 | this.start_key = args.start_key 993 | if (null != args.end_key) 994 | this.end_key = args.end_key 995 | if (null != args.start_token) 996 | this.start_token = args.start_token 997 | if (null != args.end_token) 998 | this.end_token = args.end_token 999 | if (null != args.count) 1000 | this.count = args.count 1001 | }} 1002 | KeyRange.prototype = {} 1003 | KeyRange.prototype.read = function(input){ 1004 | var ret = input.readStructBegin() 1005 | while (1) 1006 | { 1007 | var ret = input.readFieldBegin() 1008 | var fname = ret.fname 1009 | var ftype = ret.ftype 1010 | var fid = ret.fid 1011 | if (ftype == Thrift.Type.STOP) 1012 | break 1013 | switch(fid) 1014 | { 1015 | case 1: if (ftype == Thrift.Type.STRING) { 1016 | this.start_key = input.readString() 1017 | } else { 1018 | input.skip(ftype) 1019 | } 1020 | break 1021 | case 2: if (ftype == Thrift.Type.STRING) { 1022 | this.end_key = input.readString() 1023 | } else { 1024 | input.skip(ftype) 1025 | } 1026 | break 1027 | case 3: if (ftype == Thrift.Type.STRING) { 1028 | this.start_token = input.readString() 1029 | } else { 1030 | input.skip(ftype) 1031 | } 1032 | break 1033 | case 4: if (ftype == Thrift.Type.STRING) { 1034 | this.end_token = input.readString() 1035 | } else { 1036 | input.skip(ftype) 1037 | } 1038 | break 1039 | case 5: if (ftype == Thrift.Type.I32) { 1040 | this.count = input.readI32() 1041 | } else { 1042 | input.skip(ftype) 1043 | } 1044 | break 1045 | default: 1046 | input.skip(ftype) 1047 | } 1048 | input.readFieldEnd() 1049 | } 1050 | input.readStructEnd() 1051 | return 1052 | } 1053 | 1054 | KeyRange.prototype.write = function(output){ 1055 | output.writeStructBegin('KeyRange') 1056 | if (null != this.start_key) { 1057 | output.writeFieldBegin('start_key', Thrift.Type.STRING, 1) 1058 | output.writeString(this.start_key) 1059 | output.writeFieldEnd() 1060 | } 1061 | if (null != this.end_key) { 1062 | output.writeFieldBegin('end_key', Thrift.Type.STRING, 2) 1063 | output.writeString(this.end_key) 1064 | output.writeFieldEnd() 1065 | } 1066 | if (null != this.start_token) { 1067 | output.writeFieldBegin('start_token', Thrift.Type.STRING, 3) 1068 | output.writeString(this.start_token) 1069 | output.writeFieldEnd() 1070 | } 1071 | if (null != this.end_token) { 1072 | output.writeFieldBegin('end_token', Thrift.Type.STRING, 4) 1073 | output.writeString(this.end_token) 1074 | output.writeFieldEnd() 1075 | } 1076 | if (null != this.count) { 1077 | output.writeFieldBegin('count', Thrift.Type.I32, 5) 1078 | output.writeI32(this.count) 1079 | output.writeFieldEnd() 1080 | } 1081 | output.writeFieldStop() 1082 | output.writeStructEnd() 1083 | return 1084 | } 1085 | 1086 | var KeySlice = module.exports.KeySlice = function(args){ 1087 | this.key = null 1088 | this.columns = null 1089 | if( args != null ){ if (null != args.key) 1090 | this.key = args.key 1091 | if (null != args.columns) 1092 | this.columns = args.columns 1093 | }} 1094 | KeySlice.prototype = {} 1095 | KeySlice.prototype.read = function(input){ 1096 | var ret = input.readStructBegin() 1097 | while (1) 1098 | { 1099 | var ret = input.readFieldBegin() 1100 | var fname = ret.fname 1101 | var ftype = ret.ftype 1102 | var fid = ret.fid 1103 | if (ftype == Thrift.Type.STOP) 1104 | break 1105 | switch(fid) 1106 | { 1107 | case 1: if (ftype == Thrift.Type.STRING) { 1108 | this.key = input.readString() 1109 | } else { 1110 | input.skip(ftype) 1111 | } 1112 | break 1113 | case 2: if (ftype == Thrift.Type.LIST) { 1114 | { 1115 | var _size21 = 0 1116 | var rtmp3 1117 | this.columns = [] 1118 | var _etype24 = 0 1119 | rtmp3 = input.readListBegin() 1120 | _etype24 = rtmp3.etype 1121 | _size21 = rtmp3.size 1122 | for (var _i25 = 0; _i25 < _size21; ++_i25) 1123 | { 1124 | var elem26 = null 1125 | elem26 = new ttypes.ColumnOrSuperColumn() 1126 | elem26.read(input) 1127 | this.columns.push(elem26) 1128 | } 1129 | input.readListEnd() 1130 | } 1131 | } else { 1132 | input.skip(ftype) 1133 | } 1134 | break 1135 | default: 1136 | input.skip(ftype) 1137 | } 1138 | input.readFieldEnd() 1139 | } 1140 | input.readStructEnd() 1141 | return 1142 | } 1143 | 1144 | KeySlice.prototype.write = function(output){ 1145 | output.writeStructBegin('KeySlice') 1146 | if (null != this.key) { 1147 | output.writeFieldBegin('key', Thrift.Type.STRING, 1) 1148 | output.writeString(this.key) 1149 | output.writeFieldEnd() 1150 | } 1151 | if (null != this.columns) { 1152 | output.writeFieldBegin('columns', Thrift.Type.LIST, 2) 1153 | { 1154 | output.writeListBegin(Thrift.Type.STRUCT, this.columns.length) 1155 | { 1156 | for(var iter27 in this.columns) 1157 | { 1158 | if (this.columns.hasOwnProperty(iter27)) 1159 | { 1160 | iter27=this.columns[iter27] 1161 | iter27.write(output) 1162 | } 1163 | } 1164 | } 1165 | output.writeListEnd() 1166 | } 1167 | output.writeFieldEnd() 1168 | } 1169 | output.writeFieldStop() 1170 | output.writeStructEnd() 1171 | return 1172 | } 1173 | 1174 | var KeyCount = module.exports.KeyCount = function(args){ 1175 | this.key = null 1176 | this.count = null 1177 | if( args != null ){ if (null != args.key) 1178 | this.key = args.key 1179 | if (null != args.count) 1180 | this.count = args.count 1181 | }} 1182 | KeyCount.prototype = {} 1183 | KeyCount.prototype.read = function(input){ 1184 | var ret = input.readStructBegin() 1185 | while (1) 1186 | { 1187 | var ret = input.readFieldBegin() 1188 | var fname = ret.fname 1189 | var ftype = ret.ftype 1190 | var fid = ret.fid 1191 | if (ftype == Thrift.Type.STOP) 1192 | break 1193 | switch(fid) 1194 | { 1195 | case 1: if (ftype == Thrift.Type.STRING) { 1196 | this.key = input.readString() 1197 | } else { 1198 | input.skip(ftype) 1199 | } 1200 | break 1201 | case 2: if (ftype == Thrift.Type.I32) { 1202 | this.count = input.readI32() 1203 | } else { 1204 | input.skip(ftype) 1205 | } 1206 | break 1207 | default: 1208 | input.skip(ftype) 1209 | } 1210 | input.readFieldEnd() 1211 | } 1212 | input.readStructEnd() 1213 | return 1214 | } 1215 | 1216 | KeyCount.prototype.write = function(output){ 1217 | output.writeStructBegin('KeyCount') 1218 | if (null != this.key) { 1219 | output.writeFieldBegin('key', Thrift.Type.STRING, 1) 1220 | output.writeString(this.key) 1221 | output.writeFieldEnd() 1222 | } 1223 | if (null != this.count) { 1224 | output.writeFieldBegin('count', Thrift.Type.I32, 2) 1225 | output.writeI32(this.count) 1226 | output.writeFieldEnd() 1227 | } 1228 | output.writeFieldStop() 1229 | output.writeStructEnd() 1230 | return 1231 | } 1232 | 1233 | var Deletion = module.exports.Deletion = function(args){ 1234 | this.timestamp = null 1235 | this.super_column = null 1236 | this.predicate = null 1237 | if( args != null ){ if (null != args.timestamp) 1238 | this.timestamp = args.timestamp 1239 | if (null != args.super_column) 1240 | this.super_column = args.super_column 1241 | if (null != args.predicate) 1242 | this.predicate = args.predicate 1243 | }} 1244 | Deletion.prototype = {} 1245 | Deletion.prototype.read = function(input){ 1246 | var ret = input.readStructBegin() 1247 | while (1) 1248 | { 1249 | var ret = input.readFieldBegin() 1250 | var fname = ret.fname 1251 | var ftype = ret.ftype 1252 | var fid = ret.fid 1253 | if (ftype == Thrift.Type.STOP) 1254 | break 1255 | switch(fid) 1256 | { 1257 | case 1: if (ftype == Thrift.Type.I64) { 1258 | this.timestamp = input.readI64() 1259 | } else { 1260 | input.skip(ftype) 1261 | } 1262 | break 1263 | case 2: if (ftype == Thrift.Type.STRING) { 1264 | this.super_column = input.readString() 1265 | } else { 1266 | input.skip(ftype) 1267 | } 1268 | break 1269 | case 3: if (ftype == Thrift.Type.STRUCT) { 1270 | this.predicate = new ttypes.SlicePredicate() 1271 | this.predicate.read(input) 1272 | } else { 1273 | input.skip(ftype) 1274 | } 1275 | break 1276 | default: 1277 | input.skip(ftype) 1278 | } 1279 | input.readFieldEnd() 1280 | } 1281 | input.readStructEnd() 1282 | return 1283 | } 1284 | 1285 | Deletion.prototype.write = function(output){ 1286 | output.writeStructBegin('Deletion') 1287 | if (null != this.timestamp) { 1288 | output.writeFieldBegin('timestamp', Thrift.Type.I64, 1) 1289 | output.writeI64(this.timestamp) 1290 | output.writeFieldEnd() 1291 | } 1292 | if (null != this.super_column) { 1293 | output.writeFieldBegin('super_column', Thrift.Type.STRING, 2) 1294 | output.writeString(this.super_column) 1295 | output.writeFieldEnd() 1296 | } 1297 | if (null != this.predicate) { 1298 | output.writeFieldBegin('predicate', Thrift.Type.STRUCT, 3) 1299 | this.predicate.write(output) 1300 | output.writeFieldEnd() 1301 | } 1302 | output.writeFieldStop() 1303 | output.writeStructEnd() 1304 | return 1305 | } 1306 | 1307 | var Mutation = module.exports.Mutation = function(args){ 1308 | this.column_or_supercolumn = null 1309 | this.deletion = null 1310 | if( args != null ){ if (null != args.column_or_supercolumn) 1311 | this.column_or_supercolumn = args.column_or_supercolumn 1312 | if (null != args.deletion) 1313 | this.deletion = args.deletion 1314 | }} 1315 | Mutation.prototype = {} 1316 | Mutation.prototype.read = function(input){ 1317 | var ret = input.readStructBegin() 1318 | while (1) 1319 | { 1320 | var ret = input.readFieldBegin() 1321 | var fname = ret.fname 1322 | var ftype = ret.ftype 1323 | var fid = ret.fid 1324 | if (ftype == Thrift.Type.STOP) 1325 | break 1326 | switch(fid) 1327 | { 1328 | case 1: if (ftype == Thrift.Type.STRUCT) { 1329 | this.column_or_supercolumn = new ttypes.ColumnOrSuperColumn() 1330 | this.column_or_supercolumn.read(input) 1331 | } else { 1332 | input.skip(ftype) 1333 | } 1334 | break 1335 | case 2: if (ftype == Thrift.Type.STRUCT) { 1336 | this.deletion = new ttypes.Deletion() 1337 | this.deletion.read(input) 1338 | } else { 1339 | input.skip(ftype) 1340 | } 1341 | break 1342 | default: 1343 | input.skip(ftype) 1344 | } 1345 | input.readFieldEnd() 1346 | } 1347 | input.readStructEnd() 1348 | return 1349 | } 1350 | 1351 | Mutation.prototype.write = function(output){ 1352 | output.writeStructBegin('Mutation') 1353 | if (null != this.column_or_supercolumn) { 1354 | output.writeFieldBegin('column_or_supercolumn', Thrift.Type.STRUCT, 1) 1355 | this.column_or_supercolumn.write(output) 1356 | output.writeFieldEnd() 1357 | } 1358 | if (null != this.deletion) { 1359 | output.writeFieldBegin('deletion', Thrift.Type.STRUCT, 2) 1360 | this.deletion.write(output) 1361 | output.writeFieldEnd() 1362 | } 1363 | output.writeFieldStop() 1364 | output.writeStructEnd() 1365 | return 1366 | } 1367 | 1368 | var TokenRange = module.exports.TokenRange = function(args){ 1369 | this.start_token = null 1370 | this.end_token = null 1371 | this.endpoints = null 1372 | if( args != null ){ if (null != args.start_token) 1373 | this.start_token = args.start_token 1374 | if (null != args.end_token) 1375 | this.end_token = args.end_token 1376 | if (null != args.endpoints) 1377 | this.endpoints = args.endpoints 1378 | }} 1379 | TokenRange.prototype = {} 1380 | TokenRange.prototype.read = function(input){ 1381 | var ret = input.readStructBegin() 1382 | while (1) 1383 | { 1384 | var ret = input.readFieldBegin() 1385 | var fname = ret.fname 1386 | var ftype = ret.ftype 1387 | var fid = ret.fid 1388 | if (ftype == Thrift.Type.STOP) 1389 | break 1390 | switch(fid) 1391 | { 1392 | case 1: if (ftype == Thrift.Type.STRING) { 1393 | this.start_token = input.readString() 1394 | } else { 1395 | input.skip(ftype) 1396 | } 1397 | break 1398 | case 2: if (ftype == Thrift.Type.STRING) { 1399 | this.end_token = input.readString() 1400 | } else { 1401 | input.skip(ftype) 1402 | } 1403 | break 1404 | case 3: if (ftype == Thrift.Type.LIST) { 1405 | { 1406 | var _size28 = 0 1407 | var rtmp3 1408 | this.endpoints = [] 1409 | var _etype31 = 0 1410 | rtmp3 = input.readListBegin() 1411 | _etype31 = rtmp3.etype 1412 | _size28 = rtmp3.size 1413 | for (var _i32 = 0; _i32 < _size28; ++_i32) 1414 | { 1415 | var elem33 = null 1416 | elem33 = input.readString() 1417 | this.endpoints.push(elem33) 1418 | } 1419 | input.readListEnd() 1420 | } 1421 | } else { 1422 | input.skip(ftype) 1423 | } 1424 | break 1425 | default: 1426 | input.skip(ftype) 1427 | } 1428 | input.readFieldEnd() 1429 | } 1430 | input.readStructEnd() 1431 | return 1432 | } 1433 | 1434 | TokenRange.prototype.write = function(output){ 1435 | output.writeStructBegin('TokenRange') 1436 | if (null != this.start_token) { 1437 | output.writeFieldBegin('start_token', Thrift.Type.STRING, 1) 1438 | output.writeString(this.start_token) 1439 | output.writeFieldEnd() 1440 | } 1441 | if (null != this.end_token) { 1442 | output.writeFieldBegin('end_token', Thrift.Type.STRING, 2) 1443 | output.writeString(this.end_token) 1444 | output.writeFieldEnd() 1445 | } 1446 | if (null != this.endpoints) { 1447 | output.writeFieldBegin('endpoints', Thrift.Type.LIST, 3) 1448 | { 1449 | output.writeListBegin(Thrift.Type.STRING, this.endpoints.length) 1450 | { 1451 | for(var iter34 in this.endpoints) 1452 | { 1453 | if (this.endpoints.hasOwnProperty(iter34)) 1454 | { 1455 | iter34=this.endpoints[iter34] 1456 | output.writeString(iter34) 1457 | } 1458 | } 1459 | } 1460 | output.writeListEnd() 1461 | } 1462 | output.writeFieldEnd() 1463 | } 1464 | output.writeFieldStop() 1465 | output.writeStructEnd() 1466 | return 1467 | } 1468 | 1469 | var AuthenticationRequest = module.exports.AuthenticationRequest = function(args){ 1470 | this.credentials = null 1471 | if( args != null ){ if (null != args.credentials) 1472 | this.credentials = args.credentials 1473 | }} 1474 | AuthenticationRequest.prototype = {} 1475 | AuthenticationRequest.prototype.read = function(input){ 1476 | var ret = input.readStructBegin() 1477 | while (1) 1478 | { 1479 | var ret = input.readFieldBegin() 1480 | var fname = ret.fname 1481 | var ftype = ret.ftype 1482 | var fid = ret.fid 1483 | if (ftype == Thrift.Type.STOP) 1484 | break 1485 | switch(fid) 1486 | { 1487 | case 1: if (ftype == Thrift.Type.MAP) { 1488 | { 1489 | var _size35 = 0 1490 | var rtmp3 1491 | this.credentials = {} 1492 | var _ktype36 = 0 1493 | var _vtype37 = 0 1494 | rtmp3 = input.readMapBegin() 1495 | _ktype36= rtmp3.ktype 1496 | _vtype37= rtmp3.vtype 1497 | _size35= rtmp3.size 1498 | for (var _i39 = 0; _i39 < _size35; ++_i39) 1499 | { 1500 | key40 = null 1501 | val41 = null 1502 | key40 = input.readString() 1503 | val41 = input.readString() 1504 | this.credentials[key40] = val41 1505 | } 1506 | input.readMapEnd() 1507 | } 1508 | } else { 1509 | input.skip(ftype) 1510 | } 1511 | break 1512 | default: 1513 | input.skip(ftype) 1514 | } 1515 | input.readFieldEnd() 1516 | } 1517 | input.readStructEnd() 1518 | return 1519 | } 1520 | 1521 | AuthenticationRequest.prototype.write = function(output){ 1522 | output.writeStructBegin('AuthenticationRequest') 1523 | if (null != this.credentials) { 1524 | output.writeFieldBegin('credentials', Thrift.Type.MAP, 1) 1525 | { 1526 | output.writeMapBegin(Thrift.Type.STRING, Thrift.Type.STRING, Thrift.objectLength(this.credentials)) 1527 | { 1528 | for(var kiter42 in this.credentials) { 1529 | if (this.credentials.hasOwnProperty(kiter42)) 1530 | { 1531 | var viter43 = this.credentials[kiter42] 1532 | output.writeString(kiter42) 1533 | output.writeString(viter43) 1534 | } 1535 | } 1536 | } 1537 | output.writeMapEnd() 1538 | } 1539 | output.writeFieldEnd() 1540 | } 1541 | output.writeFieldStop() 1542 | output.writeStructEnd() 1543 | return 1544 | } 1545 | 1546 | var ColumnDef = module.exports.ColumnDef = function(args){ 1547 | this.name = null 1548 | this.validation_class = null 1549 | this.index_type = null 1550 | this.index_name = null 1551 | if( args != null ){ if (null != args.name) 1552 | this.name = args.name 1553 | if (null != args.validation_class) 1554 | this.validation_class = args.validation_class 1555 | if (null != args.index_type) 1556 | this.index_type = args.index_type 1557 | if (null != args.index_name) 1558 | this.index_name = args.index_name 1559 | }} 1560 | ColumnDef.prototype = {} 1561 | ColumnDef.prototype.read = function(input){ 1562 | var ret = input.readStructBegin() 1563 | while (1) 1564 | { 1565 | var ret = input.readFieldBegin() 1566 | var fname = ret.fname 1567 | var ftype = ret.ftype 1568 | var fid = ret.fid 1569 | if (ftype == Thrift.Type.STOP) 1570 | break 1571 | switch(fid) 1572 | { 1573 | case 1: if (ftype == Thrift.Type.STRING) { 1574 | this.name = input.readString() 1575 | } else { 1576 | input.skip(ftype) 1577 | } 1578 | break 1579 | case 2: if (ftype == Thrift.Type.STRING) { 1580 | this.validation_class = input.readString() 1581 | } else { 1582 | input.skip(ftype) 1583 | } 1584 | break 1585 | case 3: if (ftype == Thrift.Type.I32) { 1586 | this.index_type = input.readI32() 1587 | } else { 1588 | input.skip(ftype) 1589 | } 1590 | break 1591 | case 4: if (ftype == Thrift.Type.STRING) { 1592 | this.index_name = input.readString() 1593 | } else { 1594 | input.skip(ftype) 1595 | } 1596 | break 1597 | default: 1598 | input.skip(ftype) 1599 | } 1600 | input.readFieldEnd() 1601 | } 1602 | input.readStructEnd() 1603 | return 1604 | } 1605 | 1606 | ColumnDef.prototype.write = function(output){ 1607 | output.writeStructBegin('ColumnDef') 1608 | if (null != this.name) { 1609 | output.writeFieldBegin('name', Thrift.Type.STRING, 1) 1610 | output.writeString(this.name) 1611 | output.writeFieldEnd() 1612 | } 1613 | if (null != this.validation_class) { 1614 | output.writeFieldBegin('validation_class', Thrift.Type.STRING, 2) 1615 | output.writeString(this.validation_class) 1616 | output.writeFieldEnd() 1617 | } 1618 | if (null != this.index_type) { 1619 | output.writeFieldBegin('index_type', Thrift.Type.I32, 3) 1620 | output.writeI32(this.index_type) 1621 | output.writeFieldEnd() 1622 | } 1623 | if (null != this.index_name) { 1624 | output.writeFieldBegin('index_name', Thrift.Type.STRING, 4) 1625 | output.writeString(this.index_name) 1626 | output.writeFieldEnd() 1627 | } 1628 | output.writeFieldStop() 1629 | output.writeStructEnd() 1630 | return 1631 | } 1632 | 1633 | var CfDef = module.exports.CfDef = function(args){ 1634 | this.keyspace = null 1635 | this.name = null 1636 | this.column_type = 'Standard' 1637 | this.comparator_type = 'BytesType' 1638 | this.subcomparator_type = null 1639 | this.comment = null 1640 | this.row_cache_size = 0 1641 | this.key_cache_size = 200000 1642 | this.read_repair_chance = 1 1643 | this.column_metadata = null 1644 | this.gc_grace_seconds = null 1645 | this.default_validation_class = null 1646 | this.id = null 1647 | this.min_compaction_threshold = null 1648 | this.max_compaction_threshold = null 1649 | this.row_cache_save_period_in_seconds = null 1650 | this.key_cache_save_period_in_seconds = null 1651 | this.memtable_flush_after_mins = null 1652 | this.memtable_throughput_in_mb = null 1653 | this.memtable_operations_in_millions = null 1654 | if( args != null ){ if (null != args.keyspace) 1655 | this.keyspace = args.keyspace 1656 | if (null != args.name) 1657 | this.name = args.name 1658 | if (null != args.column_type) 1659 | this.column_type = args.column_type 1660 | if (null != args.comparator_type) 1661 | this.comparator_type = args.comparator_type 1662 | if (null != args.subcomparator_type) 1663 | this.subcomparator_type = args.subcomparator_type 1664 | if (null != args.comment) 1665 | this.comment = args.comment 1666 | if (null != args.row_cache_size) 1667 | this.row_cache_size = args.row_cache_size 1668 | if (null != args.key_cache_size) 1669 | this.key_cache_size = args.key_cache_size 1670 | if (null != args.read_repair_chance) 1671 | this.read_repair_chance = args.read_repair_chance 1672 | if (null != args.column_metadata) 1673 | this.column_metadata = args.column_metadata 1674 | if (null != args.gc_grace_seconds) 1675 | this.gc_grace_seconds = args.gc_grace_seconds 1676 | if (null != args.default_validation_class) 1677 | this.default_validation_class = args.default_validation_class 1678 | if (null != args.id) 1679 | this.id = args.id 1680 | if (null != args.min_compaction_threshold) 1681 | this.min_compaction_threshold = args.min_compaction_threshold 1682 | if (null != args.max_compaction_threshold) 1683 | this.max_compaction_threshold = args.max_compaction_threshold 1684 | if (null != args.row_cache_save_period_in_seconds) 1685 | this.row_cache_save_period_in_seconds = args.row_cache_save_period_in_seconds 1686 | if (null != args.key_cache_save_period_in_seconds) 1687 | this.key_cache_save_period_in_seconds = args.key_cache_save_period_in_seconds 1688 | if (null != args.memtable_flush_after_mins) 1689 | this.memtable_flush_after_mins = args.memtable_flush_after_mins 1690 | if (null != args.memtable_throughput_in_mb) 1691 | this.memtable_throughput_in_mb = args.memtable_throughput_in_mb 1692 | if (null != args.memtable_operations_in_millions) 1693 | this.memtable_operations_in_millions = args.memtable_operations_in_millions 1694 | }} 1695 | CfDef.prototype = {} 1696 | CfDef.prototype.read = function(input){ 1697 | var ret = input.readStructBegin() 1698 | while (1) 1699 | { 1700 | var ret = input.readFieldBegin() 1701 | var fname = ret.fname 1702 | var ftype = ret.ftype 1703 | var fid = ret.fid 1704 | if (ftype == Thrift.Type.STOP) 1705 | break 1706 | switch(fid) 1707 | { 1708 | case 1: if (ftype == Thrift.Type.STRING) { 1709 | this.keyspace = input.readString() 1710 | } else { 1711 | input.skip(ftype) 1712 | } 1713 | break 1714 | case 2: if (ftype == Thrift.Type.STRING) { 1715 | this.name = input.readString() 1716 | } else { 1717 | input.skip(ftype) 1718 | } 1719 | break 1720 | case 3: if (ftype == Thrift.Type.STRING) { 1721 | this.column_type = input.readString() 1722 | } else { 1723 | input.skip(ftype) 1724 | } 1725 | break 1726 | case 5: if (ftype == Thrift.Type.STRING) { 1727 | this.comparator_type = input.readString() 1728 | } else { 1729 | input.skip(ftype) 1730 | } 1731 | break 1732 | case 6: if (ftype == Thrift.Type.STRING) { 1733 | this.subcomparator_type = input.readString() 1734 | } else { 1735 | input.skip(ftype) 1736 | } 1737 | break 1738 | case 8: if (ftype == Thrift.Type.STRING) { 1739 | this.comment = input.readString() 1740 | } else { 1741 | input.skip(ftype) 1742 | } 1743 | break 1744 | case 9: if (ftype == Thrift.Type.DOUBLE) { 1745 | this.row_cache_size = input.readDouble() 1746 | } else { 1747 | input.skip(ftype) 1748 | } 1749 | break 1750 | case 11: if (ftype == Thrift.Type.DOUBLE) { 1751 | this.key_cache_size = input.readDouble() 1752 | } else { 1753 | input.skip(ftype) 1754 | } 1755 | break 1756 | case 12: if (ftype == Thrift.Type.DOUBLE) { 1757 | this.read_repair_chance = input.readDouble() 1758 | } else { 1759 | input.skip(ftype) 1760 | } 1761 | break 1762 | case 13: if (ftype == Thrift.Type.LIST) { 1763 | { 1764 | var _size44 = 0 1765 | var rtmp3 1766 | this.column_metadata = [] 1767 | var _etype47 = 0 1768 | rtmp3 = input.readListBegin() 1769 | _etype47 = rtmp3.etype 1770 | _size44 = rtmp3.size 1771 | for (var _i48 = 0; _i48 < _size44; ++_i48) 1772 | { 1773 | var elem49 = null 1774 | elem49 = new ttypes.ColumnDef() 1775 | elem49.read(input) 1776 | this.column_metadata.push(elem49) 1777 | } 1778 | input.readListEnd() 1779 | } 1780 | } else { 1781 | input.skip(ftype) 1782 | } 1783 | break 1784 | case 14: if (ftype == Thrift.Type.I32) { 1785 | this.gc_grace_seconds = input.readI32() 1786 | } else { 1787 | input.skip(ftype) 1788 | } 1789 | break 1790 | case 15: if (ftype == Thrift.Type.STRING) { 1791 | this.default_validation_class = input.readString() 1792 | } else { 1793 | input.skip(ftype) 1794 | } 1795 | break 1796 | case 16: if (ftype == Thrift.Type.I32) { 1797 | this.id = input.readI32() 1798 | } else { 1799 | input.skip(ftype) 1800 | } 1801 | break 1802 | case 17: if (ftype == Thrift.Type.I32) { 1803 | this.min_compaction_threshold = input.readI32() 1804 | } else { 1805 | input.skip(ftype) 1806 | } 1807 | break 1808 | case 18: if (ftype == Thrift.Type.I32) { 1809 | this.max_compaction_threshold = input.readI32() 1810 | } else { 1811 | input.skip(ftype) 1812 | } 1813 | break 1814 | case 19: if (ftype == Thrift.Type.I32) { 1815 | this.row_cache_save_period_in_seconds = input.readI32() 1816 | } else { 1817 | input.skip(ftype) 1818 | } 1819 | break 1820 | case 20: if (ftype == Thrift.Type.I32) { 1821 | this.key_cache_save_period_in_seconds = input.readI32() 1822 | } else { 1823 | input.skip(ftype) 1824 | } 1825 | break 1826 | case 21: if (ftype == Thrift.Type.I32) { 1827 | this.memtable_flush_after_mins = input.readI32() 1828 | } else { 1829 | input.skip(ftype) 1830 | } 1831 | break 1832 | case 22: if (ftype == Thrift.Type.I32) { 1833 | this.memtable_throughput_in_mb = input.readI32() 1834 | } else { 1835 | input.skip(ftype) 1836 | } 1837 | break 1838 | case 23: if (ftype == Thrift.Type.DOUBLE) { 1839 | this.memtable_operations_in_millions = input.readDouble() 1840 | } else { 1841 | input.skip(ftype) 1842 | } 1843 | break 1844 | default: 1845 | input.skip(ftype) 1846 | } 1847 | input.readFieldEnd() 1848 | } 1849 | input.readStructEnd() 1850 | return 1851 | } 1852 | 1853 | CfDef.prototype.write = function(output){ 1854 | output.writeStructBegin('CfDef') 1855 | if (null != this.keyspace) { 1856 | output.writeFieldBegin('keyspace', Thrift.Type.STRING, 1) 1857 | output.writeString(this.keyspace) 1858 | output.writeFieldEnd() 1859 | } 1860 | if (null != this.name) { 1861 | output.writeFieldBegin('name', Thrift.Type.STRING, 2) 1862 | output.writeString(this.name) 1863 | output.writeFieldEnd() 1864 | } 1865 | if (null != this.column_type) { 1866 | output.writeFieldBegin('column_type', Thrift.Type.STRING, 3) 1867 | output.writeString(this.column_type) 1868 | output.writeFieldEnd() 1869 | } 1870 | if (null != this.comparator_type) { 1871 | output.writeFieldBegin('comparator_type', Thrift.Type.STRING, 5) 1872 | output.writeString(this.comparator_type) 1873 | output.writeFieldEnd() 1874 | } 1875 | if (null != this.subcomparator_type) { 1876 | output.writeFieldBegin('subcomparator_type', Thrift.Type.STRING, 6) 1877 | output.writeString(this.subcomparator_type) 1878 | output.writeFieldEnd() 1879 | } 1880 | if (null != this.comment) { 1881 | output.writeFieldBegin('comment', Thrift.Type.STRING, 8) 1882 | output.writeString(this.comment) 1883 | output.writeFieldEnd() 1884 | } 1885 | if (null != this.row_cache_size) { 1886 | output.writeFieldBegin('row_cache_size', Thrift.Type.DOUBLE, 9) 1887 | output.writeDouble(this.row_cache_size) 1888 | output.writeFieldEnd() 1889 | } 1890 | if (null != this.key_cache_size) { 1891 | output.writeFieldBegin('key_cache_size', Thrift.Type.DOUBLE, 11) 1892 | output.writeDouble(this.key_cache_size) 1893 | output.writeFieldEnd() 1894 | } 1895 | if (null != this.read_repair_chance) { 1896 | output.writeFieldBegin('read_repair_chance', Thrift.Type.DOUBLE, 12) 1897 | output.writeDouble(this.read_repair_chance) 1898 | output.writeFieldEnd() 1899 | } 1900 | if (null != this.column_metadata) { 1901 | output.writeFieldBegin('column_metadata', Thrift.Type.LIST, 13) 1902 | { 1903 | output.writeListBegin(Thrift.Type.STRUCT, this.column_metadata.length) 1904 | { 1905 | for(var iter50 in this.column_metadata) 1906 | { 1907 | if (this.column_metadata.hasOwnProperty(iter50)) 1908 | { 1909 | iter50=this.column_metadata[iter50] 1910 | iter50.write(output) 1911 | } 1912 | } 1913 | } 1914 | output.writeListEnd() 1915 | } 1916 | output.writeFieldEnd() 1917 | } 1918 | if (null != this.gc_grace_seconds) { 1919 | output.writeFieldBegin('gc_grace_seconds', Thrift.Type.I32, 14) 1920 | output.writeI32(this.gc_grace_seconds) 1921 | output.writeFieldEnd() 1922 | } 1923 | if (null != this.default_validation_class) { 1924 | output.writeFieldBegin('default_validation_class', Thrift.Type.STRING, 15) 1925 | output.writeString(this.default_validation_class) 1926 | output.writeFieldEnd() 1927 | } 1928 | if (null != this.id) { 1929 | output.writeFieldBegin('id', Thrift.Type.I32, 16) 1930 | output.writeI32(this.id) 1931 | output.writeFieldEnd() 1932 | } 1933 | if (null != this.min_compaction_threshold) { 1934 | output.writeFieldBegin('min_compaction_threshold', Thrift.Type.I32, 17) 1935 | output.writeI32(this.min_compaction_threshold) 1936 | output.writeFieldEnd() 1937 | } 1938 | if (null != this.max_compaction_threshold) { 1939 | output.writeFieldBegin('max_compaction_threshold', Thrift.Type.I32, 18) 1940 | output.writeI32(this.max_compaction_threshold) 1941 | output.writeFieldEnd() 1942 | } 1943 | if (null != this.row_cache_save_period_in_seconds) { 1944 | output.writeFieldBegin('row_cache_save_period_in_seconds', Thrift.Type.I32, 19) 1945 | output.writeI32(this.row_cache_save_period_in_seconds) 1946 | output.writeFieldEnd() 1947 | } 1948 | if (null != this.key_cache_save_period_in_seconds) { 1949 | output.writeFieldBegin('key_cache_save_period_in_seconds', Thrift.Type.I32, 20) 1950 | output.writeI32(this.key_cache_save_period_in_seconds) 1951 | output.writeFieldEnd() 1952 | } 1953 | if (null != this.memtable_flush_after_mins) { 1954 | output.writeFieldBegin('memtable_flush_after_mins', Thrift.Type.I32, 21) 1955 | output.writeI32(this.memtable_flush_after_mins) 1956 | output.writeFieldEnd() 1957 | } 1958 | if (null != this.memtable_throughput_in_mb) { 1959 | output.writeFieldBegin('memtable_throughput_in_mb', Thrift.Type.I32, 22) 1960 | output.writeI32(this.memtable_throughput_in_mb) 1961 | output.writeFieldEnd() 1962 | } 1963 | if (null != this.memtable_operations_in_millions) { 1964 | output.writeFieldBegin('memtable_operations_in_millions', Thrift.Type.DOUBLE, 23) 1965 | output.writeDouble(this.memtable_operations_in_millions) 1966 | output.writeFieldEnd() 1967 | } 1968 | output.writeFieldStop() 1969 | output.writeStructEnd() 1970 | return 1971 | } 1972 | 1973 | var KsDef = module.exports.KsDef = function(args){ 1974 | this.name = null 1975 | this.strategy_class = null 1976 | this.strategy_options = null 1977 | this.replication_factor = null 1978 | this.cf_defs = null 1979 | if( args != null ){ if (null != args.name) 1980 | this.name = args.name 1981 | if (null != args.strategy_class) 1982 | this.strategy_class = args.strategy_class 1983 | if (null != args.strategy_options) 1984 | this.strategy_options = args.strategy_options 1985 | if (null != args.replication_factor) 1986 | this.replication_factor = args.replication_factor 1987 | if (null != args.cf_defs) 1988 | this.cf_defs = args.cf_defs 1989 | }} 1990 | KsDef.prototype = {} 1991 | KsDef.prototype.read = function(input){ 1992 | var ret = input.readStructBegin() 1993 | while (1) 1994 | { 1995 | var ret = input.readFieldBegin() 1996 | var fname = ret.fname 1997 | var ftype = ret.ftype 1998 | var fid = ret.fid 1999 | if (ftype == Thrift.Type.STOP) 2000 | break 2001 | switch(fid) 2002 | { 2003 | case 1: if (ftype == Thrift.Type.STRING) { 2004 | this.name = input.readString() 2005 | } else { 2006 | input.skip(ftype) 2007 | } 2008 | break 2009 | case 2: if (ftype == Thrift.Type.STRING) { 2010 | this.strategy_class = input.readString() 2011 | } else { 2012 | input.skip(ftype) 2013 | } 2014 | break 2015 | case 3: if (ftype == Thrift.Type.MAP) { 2016 | { 2017 | var _size51 = 0 2018 | var rtmp3 2019 | this.strategy_options = {} 2020 | var _ktype52 = 0 2021 | var _vtype53 = 0 2022 | rtmp3 = input.readMapBegin() 2023 | _ktype52= rtmp3.ktype 2024 | _vtype53= rtmp3.vtype 2025 | _size51= rtmp3.size 2026 | for (var _i55 = 0; _i55 < _size51; ++_i55) 2027 | { 2028 | key56 = null 2029 | val57 = null 2030 | key56 = input.readString() 2031 | val57 = input.readString() 2032 | this.strategy_options[key56] = val57 2033 | } 2034 | input.readMapEnd() 2035 | } 2036 | } else { 2037 | input.skip(ftype) 2038 | } 2039 | break 2040 | case 4: if (ftype == Thrift.Type.I32) { 2041 | this.replication_factor = input.readI32() 2042 | } else { 2043 | input.skip(ftype) 2044 | } 2045 | break 2046 | case 5: if (ftype == Thrift.Type.LIST) { 2047 | { 2048 | var _size58 = 0 2049 | var rtmp3 2050 | this.cf_defs = [] 2051 | var _etype61 = 0 2052 | rtmp3 = input.readListBegin() 2053 | _etype61 = rtmp3.etype 2054 | _size58 = rtmp3.size 2055 | for (var _i62 = 0; _i62 < _size58; ++_i62) 2056 | { 2057 | var elem63 = null 2058 | elem63 = new ttypes.CfDef() 2059 | elem63.read(input) 2060 | this.cf_defs.push(elem63) 2061 | } 2062 | input.readListEnd() 2063 | } 2064 | } else { 2065 | input.skip(ftype) 2066 | } 2067 | break 2068 | default: 2069 | input.skip(ftype) 2070 | } 2071 | input.readFieldEnd() 2072 | } 2073 | input.readStructEnd() 2074 | return 2075 | } 2076 | 2077 | KsDef.prototype.write = function(output){ 2078 | output.writeStructBegin('KsDef') 2079 | if (null != this.name) { 2080 | output.writeFieldBegin('name', Thrift.Type.STRING, 1) 2081 | output.writeString(this.name) 2082 | output.writeFieldEnd() 2083 | } 2084 | if (null != this.strategy_class) { 2085 | output.writeFieldBegin('strategy_class', Thrift.Type.STRING, 2) 2086 | output.writeString(this.strategy_class) 2087 | output.writeFieldEnd() 2088 | } 2089 | if (null != this.strategy_options) { 2090 | output.writeFieldBegin('strategy_options', Thrift.Type.MAP, 3) 2091 | { 2092 | output.writeMapBegin(Thrift.Type.STRING, Thrift.Type.STRING, Thrift.objectLength(this.strategy_options)) 2093 | { 2094 | for(var kiter64 in this.strategy_options) { 2095 | if (this.strategy_options.hasOwnProperty(kiter64)) 2096 | { 2097 | var viter65 = this.strategy_options[kiter64] 2098 | output.writeString(kiter64) 2099 | output.writeString(viter65) 2100 | } 2101 | } 2102 | } 2103 | output.writeMapEnd() 2104 | } 2105 | output.writeFieldEnd() 2106 | } 2107 | if (null != this.replication_factor) { 2108 | output.writeFieldBegin('replication_factor', Thrift.Type.I32, 4) 2109 | output.writeI32(this.replication_factor) 2110 | output.writeFieldEnd() 2111 | } 2112 | if (null != this.cf_defs) { 2113 | output.writeFieldBegin('cf_defs', Thrift.Type.LIST, 5) 2114 | { 2115 | output.writeListBegin(Thrift.Type.STRUCT, this.cf_defs.length) 2116 | { 2117 | for(var iter66 in this.cf_defs) 2118 | { 2119 | if (this.cf_defs.hasOwnProperty(iter66)) 2120 | { 2121 | iter66=this.cf_defs[iter66] 2122 | iter66.write(output) 2123 | } 2124 | } 2125 | } 2126 | output.writeListEnd() 2127 | } 2128 | output.writeFieldEnd() 2129 | } 2130 | output.writeFieldStop() 2131 | output.writeStructEnd() 2132 | return 2133 | } 2134 | 2135 | -------------------------------------------------------------------------------- /lib/cassandra.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright 2011 Yuki Morishita 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | *:WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | var sys = require('sys'), 17 | thrift = require('thrift'), 18 | Cassandra = require('../gen-nodejs/Cassandra'), 19 | ttype = require('../gen-nodejs/cassandra_types'); 20 | 21 | /** 22 | * node_cassandra, Apache Cassandra Client for node.js 23 | * 24 | * @constructor 25 | * @api public 26 | */ 27 | var Client = function(host) { 28 | var pair = host.split(/:/); 29 | this.host = pair[0]; 30 | this.port = pair[1]; 31 | // default consistency level 32 | this.defaultCL = { 33 | read: ttype.ConsistencyLevel.QUORUM, 34 | write: ttype.ConsistencyLevel.QUORUM 35 | }; 36 | } 37 | sys.inherits(Client, process.EventEmitter); 38 | 39 | /** 40 | * Connect to Cassandra cluster 41 | * 42 | * @param keyspace keyspace name to use 43 | * @param credential if given, try login into cassandra 44 | * @api public 45 | */ 46 | Client.prototype.connect = function() { 47 | var args = Array.prototype.slice.call(arguments); 48 | 49 | var keyspace_or_credential = args.shift(); 50 | var credential = args.shift(); 51 | if (keyspace_or_credential instanceof String || 52 | typeof keyspace_or_credential === 'string') { 53 | // if first argument is string, then it is keyspace name 54 | this.keyspace = keyspace_or_credential; 55 | } else { 56 | credential = keyspace_or_credential; 57 | } 58 | 59 | this.ready = false; 60 | this.queue = []; 61 | 62 | this.connection = thrift.createConnection(this.host, this.port); 63 | this.connection.on('error', function(err) { 64 | this.emit('error', err); 65 | }); 66 | this.thrift_client = thrift.createClient(Cassandra, this.connection); 67 | 68 | var self = this; 69 | this.connection.on('connect', function(err) { 70 | if (err) { 71 | self.emit('error', err); 72 | return; 73 | } 74 | 75 | // if credential is given, then call login 76 | if (credential) { 77 | self.thrift_client.login( 78 | new ttype.AuthenticationRequest(credential), function(err) { 79 | 80 | if (err) { 81 | self.emit('error', err); 82 | return; 83 | } 84 | 85 | // only when login is success, emit connected event 86 | self.ready = true; 87 | self.dispatch(); 88 | }); 89 | } else { 90 | self.ready = true; 91 | self.dispatch(); 92 | } 93 | }); 94 | 95 | // if keyspace is specified, use that ks 96 | if (this.keyspace) { 97 | this.use(this.keyspace, function(err) { 98 | if (err) { 99 | self.emit('error', err); 100 | } 101 | }); 102 | } 103 | }; 104 | 105 | /** 106 | * set which keyspace to use 107 | * 108 | * @param keyspace Keyspace to use 109 | * @param callback 110 | */ 111 | Client.prototype.use = function(keyspace, callback) { 112 | var args = Array.prototype.slice.call(arguments); 113 | if (!this.ready) { 114 | this.queue.push([arguments.callee, args]); 115 | return; 116 | } 117 | 118 | this.keyspace = keyspace; 119 | 120 | var self = this; 121 | this.thrift_client.describe_keyspace(this.keyspace, function(err, ksdef) { 122 | if (err) { 123 | self.emit('error', err); 124 | return; 125 | } 126 | self.definition_ = ksdef; 127 | self.column_families_ = {}; 128 | 129 | var i = ksdef.cf_defs.length; 130 | var cf; 131 | while (i--) { 132 | cf = ksdef.cf_defs[i]; 133 | self.column_families_[cf.name] = cf; 134 | } 135 | 136 | self.thrift_client.set_keyspace(self.keyspace, function(err) { 137 | if (err) { 138 | selt.emit('error', err); 139 | return; 140 | } 141 | self.emit('keyspaceSet', self.column_families_); 142 | }); 143 | }); 144 | }; 145 | 146 | /** 147 | * Set or get default consistency level 148 | * 149 | * @param consistencyLevel An object which has write and read consistency level. 150 | * If given, sets default consistency level. 151 | * 152 | */ 153 | Client.prototype.consistencyLevel = function() { 154 | if (arguments.length == 0) { 155 | return this.defaultCL; 156 | } else { 157 | var newCL = arguments[0]; 158 | this.defaultCL.read = newCL.read || ttype.ConsistencyLevel.QUORUM; 159 | this.defaultCL.write = newCL.write || ttype.ConsistencyLevel.QUORUM; 160 | } 161 | }; 162 | 163 | /** 164 | * add keyspace 165 | * 166 | * TODO work in progress 167 | */ 168 | Client.prototype.addKeySpace = function(ksdef, callback) { 169 | var args = Array.prototype.slice.call(arguments); 170 | if (!this.ready) { 171 | this.queue.push([arguments.callee, args]); 172 | return; 173 | } 174 | 175 | this.thrift_client.system_add_keyspace(new ttype.KsDef(ksdef), callback); 176 | }; 177 | 178 | /** 179 | * drop keyspace 180 | * 181 | * TODO work in progress 182 | */ 183 | Client.prototype.dropKeySpace = function(keyspace, callback) { 184 | var args = Array.prototype.slice.call(arguments); 185 | if (!this.ready) { 186 | this.queue.push([arguments.callee, args]); 187 | return; 188 | } 189 | 190 | this.thrift_client.system_drop_keyspace(keyspace, callback); 191 | }; 192 | 193 | /** 194 | * Get column family to perform query or mutation 195 | * 196 | * @param name ColumnFamily name to get 197 | * @return An instance of ColumnFamily 198 | */ 199 | Client.prototype.getColumnFamily = function(name) { 200 | return new ColumnFamily(this, name); 201 | }; 202 | 203 | /** 204 | * Close connection 205 | */ 206 | Client.prototype.close = function() { 207 | this.connection.end(); 208 | }; 209 | 210 | /** 211 | * @api {private} 212 | */ 213 | Client.prototype.dispatch = function() { 214 | if (this.ready) { 215 | if (this.queue.length > 0) { 216 | var next = this.queue.shift(); 217 | next[0].apply(this, next[1]); 218 | this.dispatch(); 219 | } 220 | } 221 | }; 222 | 223 | /** 224 | * 225 | * @param client Client 226 | * @param name name of this Column Family 227 | * @constructor 228 | */ 229 | var ColumnFamily = function(client, name) { 230 | this.name = name; 231 | this.queue = []; 232 | this.ready = false; 233 | this.client_ = client; 234 | 235 | var self = this; 236 | this.client_.on('keyspaceSet', function(cfdef) { 237 | // check to see if column name is valid 238 | var cf = cfdef[self.name]; 239 | if (!cf) { 240 | // column family does not exist 241 | self.client_.emit('error', new Error('Column Family ' + self.name + ' does not exist.')); 242 | } 243 | 244 | // copy all cfdef properties 245 | for (var prop in cf) { 246 | if (cf.hasOwnProperty(prop)) { 247 | self[prop] = cf[prop]; 248 | } 249 | } 250 | self.isSuper = self.column_type === 'Super'; 251 | self.ready = true; 252 | 253 | self.dispatch(); 254 | }); 255 | }; 256 | 257 | /** 258 | * Get data from cassandra 259 | * 260 | * @param keys row keys to fetch 261 | * @param columns optional. which columns to retrieve 262 | * @param options optional. valid params are start, finish, reversed, count 263 | * @param callback callback function which called after data retrieval. 264 | */ 265 | ColumnFamily.prototype.get = function() { 266 | var args = Array.prototype.slice.call(arguments); 267 | if (!this.ready) { 268 | this.queue.push([arguments.callee, args]); 269 | return; 270 | } 271 | 272 | // last argument may be callback 273 | var callback; 274 | if (typeof args[args.length - 1] === 'function') { 275 | callback = args.pop(); 276 | } 277 | // keys to get 278 | var keys = args.shift(); 279 | // if only one key specified, turn it to array 280 | if (!(keys instanceof Array)) { 281 | keys = [keys]; 282 | } 283 | 284 | var method_args = this.isSuper ? this.parseArgumentsForSuperCF_(args) : this.parseArgumentsForStandardCF_(args); 285 | var column_parent = method_args[0]; 286 | var predicate = method_args[1]; 287 | var cl = method_args[2] || this.client_.defaultCL.read; 288 | 289 | var self = this; 290 | this.client_.thrift_client.multiget_slice( 291 | keys, column_parent, predicate, cl, 292 | function(err, res) { 293 | if (err) { 294 | callback(err, obj); 295 | } 296 | 297 | // array -> obj 298 | var obj = {}; 299 | var key, col, sub_col; 300 | for (key in res) { 301 | if (res.hasOwnProperty(key)) { 302 | obj[key] = {}; 303 | var i = res[key].length; 304 | while (i--) { 305 | col = res[key][i].super_column; 306 | if (col) { 307 | // super 308 | obj[key][col.name] = {}; 309 | var j = col.columns.length; 310 | while (j--) { 311 | sub_col = col.columns[j]; 312 | obj[key][col.name][sub_col.name] = sub_col.value; 313 | } 314 | } else { 315 | // standard 316 | col = res[key][i].column; 317 | obj[key][col.name] = col.value; 318 | } 319 | } 320 | } 321 | } 322 | if (keys.length == 1) { 323 | obj = obj[keys[0]]; 324 | } 325 | callback(err, obj); 326 | }); 327 | }; 328 | 329 | /** 330 | * Get column count from cassandra 331 | * 332 | * @param keys row keys to fetch 333 | * @param columns optional. which columns to retrieve 334 | * @param options optional. valid params are start, finish, reversed, count 335 | * @param callback callback function which called after data retrieval. 336 | */ 337 | ColumnFamily.prototype.count = function() { 338 | var args = Array.prototype.slice.call(arguments); 339 | if (!this.ready) { 340 | this.queue.push([arguments.callee, args]); 341 | return; 342 | } 343 | 344 | // last argument may be callback 345 | var callback; 346 | if (typeof args[args.length - 1] === 'function') { 347 | callback = args.pop(); 348 | } 349 | // keys to get 350 | var keys = args.shift(); 351 | // if only one key specified, turn it to array 352 | if (!(keys instanceof Array)) { 353 | keys = [keys]; 354 | } 355 | 356 | var method_args = this.isSuper ? this.parseArgumentsForSuperCF_(args) : this.parseArgumentsForStandardCF_(args); 357 | var column_parent = method_args[0]; 358 | var predicate = method_args[1]; 359 | var cl = method_args[2] || this.client_.defaultCL.read; 360 | 361 | this.client_.thrift_client.multiget_count( 362 | keys, column_parent, predicate, cl, 363 | function(err, res) { 364 | if (err) { 365 | callback(err, obj); 366 | } 367 | 368 | var obj = {}; 369 | var key, count; 370 | for (key in res) { 371 | if (res.hasOwnProperty(key)) { 372 | obj[key] = res[key]; 373 | } 374 | } 375 | if (keys.length == 1) { 376 | obj = obj[keys[0]]; 377 | } 378 | callback(err, obj); 379 | }); 380 | }; 381 | 382 | /** 383 | * slice data 384 | */ 385 | ColumnFamily.prototype.slice = function() { 386 | this.client_.emit('error', new Error('slice(get_range_slices, get_indexed_slices) not supported.')); 387 | }; 388 | 389 | /** 390 | * set (insert or update) data 391 | */ 392 | ColumnFamily.prototype.set = function() { 393 | var args = Array.prototype.slice.call(arguments); 394 | if (!this.ready) { 395 | this.queue.push([arguments.callee, args]); 396 | return; 397 | } 398 | 399 | var callback; 400 | if (typeof args[args.length - 1] === 'function') { 401 | callback = args.pop(); 402 | } 403 | 404 | var key = args.shift(); 405 | var values = args.shift() || {}; 406 | var options = args.shift() || {}; 407 | var cl = options.consistencyLevel || this.client_.defaultCL.write; 408 | var ts = new Date().getTime(); 409 | 410 | var prop, value; 411 | var mutations = [], columns; 412 | if (this.isSuper) { 413 | // super 414 | for (prop in values) { 415 | if (values.hasOwnProperty(prop)) { 416 | columns = []; 417 | value = values[prop]; 418 | for (var col in value) { 419 | columns.push(new ttype.Column({ 420 | name: col, 421 | value: '' + value[col], 422 | timestamp: ts, 423 | ttl: null 424 | })); 425 | } 426 | // prop is super column name 427 | mutations.push(new ttype.Mutation({ 428 | column_or_supercolumn: new ttype.ColumnOrSuperColumn({ 429 | super_column: new ttype.SuperColumn({ 430 | name: prop, 431 | columns: columns 432 | }) 433 | }) 434 | })); 435 | } 436 | } 437 | } else { 438 | // standard 439 | for (prop in values) { 440 | mutations.push(new ttype.Mutation({ 441 | column_or_supercolumn: new ttype.ColumnOrSuperColumn({ 442 | column: new ttype.Column({ 443 | name: prop, 444 | value: '' + values[prop], 445 | timestamp: ts, 446 | ttl: null 447 | }) 448 | }) 449 | })); 450 | } 451 | } 452 | 453 | var mutation_map = {}; 454 | mutation_map[key] = {}; 455 | mutation_map[key][this.name] = mutations; 456 | 457 | this.client_.thrift_client.batch_mutate(mutation_map, cl, callback); 458 | }; 459 | 460 | /** 461 | * remove data 462 | */ 463 | ColumnFamily.prototype.remove = function() { 464 | var args = Array.prototype.slice.call(arguments); 465 | if (!this.ready) { 466 | this.queue.push([arguments.callee, args]); 467 | return; 468 | } 469 | 470 | var callback; 471 | if (typeof args[args.length - 1] === 'function') { 472 | callback = args.pop(); 473 | } 474 | 475 | var key = args.shift(); 476 | 477 | var method_args = this.isSuper ? this.parseArgumentsForSuperCF_(args) : this.parseArgumentsForStandardCF_(args); 478 | var column_parent = method_args[0]; 479 | var predicate = method_args[1]; 480 | var cl = method_args[2] || this.client_.defaultCL.write; 481 | 482 | var ts = new Date().getTime(); 483 | 484 | var mutations = []; 485 | mutations.push(new ttype.Mutation({ 486 | deletion: new ttype.Deletion({ 487 | timestamp: ts, 488 | super_column: column_parent.super_column, 489 | predicate: predicate.column_names ? predicate : null 490 | }) 491 | })); 492 | 493 | var mutation_map = {}; 494 | mutation_map[key] = {}; 495 | mutation_map[key][this.name] = mutations; 496 | 497 | this.client_.thrift_client.batch_mutate(mutation_map, cl, callback); 498 | }; 499 | 500 | /** 501 | * truncate this column family 502 | **/ 503 | ColumnFamily.prototype.truncate = function() { 504 | var args = Array.prototype.slice.call(arguments); 505 | if (!this.ready) { 506 | this.queue.push([arguments.callee, args]); 507 | return; 508 | } 509 | 510 | var callback = args.shift(); 511 | this.client_.thrift_client.truncate(this.name, callback); 512 | } 513 | 514 | /** 515 | * dispatch queries when client is ready 516 | * @api private 517 | **/ 518 | ColumnFamily.prototype.dispatch = function() { 519 | if (this.ready) { 520 | if (this.queue.length > 0) { 521 | var next = this.queue.shift(); 522 | next[0].apply(this, next[1]); 523 | this.dispatch(); 524 | } 525 | } 526 | }; 527 | 528 | /** 529 | * 530 | * @api private 531 | * @param args 532 | * @return [ColumnParent, SlicePredicate, ConsistencyLevel] 533 | */ 534 | ColumnFamily.prototype.parseArgumentsForSuperCF_ = function(args) { 535 | var default_options = { 536 | start: '', 537 | finish: '', 538 | reversed: false, 539 | count: 100, 540 | consistencyLevel: null 541 | }; 542 | var column_parent = { 543 | column_family: this.name 544 | }; 545 | var predicate = {}; 546 | 547 | var super_column_or_options = args.shift(); 548 | var options = default_options; 549 | 550 | if (super_column_or_options) { 551 | // first argumet may be super column name 552 | if (super_column_or_options instanceof String || 553 | typeof super_column_or_options === 'string') { 554 | column_parent.super_column = super_column_or_options; 555 | var columns_or_options = args.shift(); 556 | if (columns_or_options) { 557 | var columns, options, option_name; 558 | if (typeof columns_or_options.slice === 'function') { 559 | // first argument is column name(s) 560 | columns = columns_or_options.slice(); 561 | if (!(columns instanceof Array)) { 562 | columns = [columns]; 563 | } 564 | predicate.column_names = columns; 565 | options = args.shift() || default_options; 566 | } else { 567 | // update default option with given value 568 | for (option_name in columns_or_options) { 569 | if (columns_or_options.hasOwnProperty(option_name)) { 570 | options[option_name] = columns_or_options[option_name]; 571 | } 572 | } 573 | predicate.slice_range = new ttype.SliceRange(options); 574 | } 575 | } else { 576 | predicate.slice_range = new ttype.SliceRange(options); 577 | } 578 | } else { 579 | // update default option with given value 580 | for (option_name in super_column_or_options) { 581 | if (super_column_or_options.hasOwnProperty(option_name)) { 582 | options[option_name] = super_column_or_options[option_name]; 583 | } 584 | } 585 | predicate.slice_range = new ttype.SliceRange(options); 586 | } 587 | } else { 588 | predicate.slice_range = new ttype.SliceRange(options); 589 | } 590 | 591 | return [new ttype.ColumnParent(column_parent), 592 | new ttype.SlicePredicate(predicate), 593 | options.consistencyLevel]; 594 | } 595 | 596 | /** 597 | * 598 | * @api private 599 | * @param args 600 | * @return [ColumnParent, SlicePredicate, ConsistencyLevel] 601 | */ 602 | ColumnFamily.prototype.parseArgumentsForStandardCF_ = function(args) { 603 | var default_options = { 604 | start: '', 605 | finish: '', 606 | reversed: false, 607 | count: 100, 608 | consistencyLevel: null 609 | }; 610 | var column_parent = { 611 | column_family: this.name 612 | }; 613 | var predicate = {}; 614 | 615 | var columns_or_options = args.shift(); 616 | var options = default_options; 617 | 618 | if (columns_or_options) { 619 | var columns, options, option_name; 620 | if (typeof columns_or_options.slice === 'function') { 621 | // first argument is column name(s) 622 | columns = columns_or_options.slice(); 623 | if (!(columns instanceof Array)) { 624 | columns = [columns]; 625 | } 626 | predicate.column_names = columns; 627 | options = args.shift() || default_options; 628 | } else { 629 | // update default option with given value 630 | for (option_name in columns_or_options) { 631 | if (columns_or_options.hasOwnProperty(option_name)) { 632 | options[option_name] = columns_or_options[option_name]; 633 | } 634 | } 635 | predicate.slice_range = new ttype.SliceRange(options); 636 | } 637 | } else { 638 | predicate.slice_range = new ttype.SliceRange(options); 639 | } 640 | 641 | return [new ttype.ColumnParent(column_parent), 642 | new ttype.SlicePredicate(predicate), 643 | options.consistencyLevel]; 644 | } 645 | 646 | /** module exports */ 647 | 648 | exports.Client = Client; 649 | exports.ConsistencyLevel = ttype.ConsistencyLevel; 650 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "cassandra", 3 | "description": "cassandra client for node.js", 4 | "version": "0.1.0", 5 | "author": "Yuki Morishita ", 6 | "main": "./lib/cassandra", 7 | "lib" : "gen-nodejs", 8 | "dependencies" : { 9 | "thrift": "*" 10 | }, 11 | "engines": { "node": ">= 0.3" } 12 | } 13 | -------------------------------------------------------------------------------- /test/test.ddl: -------------------------------------------------------------------------------- 1 | 2 | drop keyspace node_cassandra_test; 3 | 4 | create keyspace node_cassandra_test with replication_factor = 1 and placement_strategy = 'org.apache.cassandra.locator.SimpleStrategy'; 5 | 6 | use node_cassandra_test; 7 | 8 | create column family Standard with column_type = 'Standard' and comparator = 'UTF8Type'; 9 | create column family Super with column_type = 'Super' and comparator = 'UTF8Type' and subcomparator = 'UTF8Type'; 10 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | /** 2 | * This test assumes that your cassandra cluster is located at localhost/9160. 3 | * 4 | * In order to run this test, first create keyspace and cf with 5 | * DDL included with this test script. 6 | * 7 | * cassandra-cli --host localhost --batch < test.ddl 8 | */ 9 | var assert = require('assert'), 10 | cassandra = require('cassandra'); 11 | 12 | // number of tests 13 | 14 | module.exports = { 15 | 16 | 'test if ConsistencyLevel is exported properly': function() { 17 | // connect to cassandra 18 | var client = new cassandra.Client('127.0.0.1:9160'); 19 | 20 | // make sure all consistency levels are exported 21 | var CL = cassandra.ConsistencyLevel; 22 | assert.deepEqual({ 23 | ONE: 1, 24 | QUORUM: 2, 25 | LOCAL_QUORUM: 3, 26 | EACH_QUORUM: 4, 27 | ALL: 5, 28 | ANY: 6 29 | }, CL); 30 | 31 | // client configuration 32 | // consistency level 33 | // default is CL.QUORUM for both reads and writes 34 | assert.deepEqual({ 35 | write: CL.QUORUM, 36 | read: CL.QUORUM 37 | }, client.consistencyLevel()); 38 | // let's change default 39 | client.consistencyLevel({ 40 | write: CL.ONE, 41 | read: CL.ONE 42 | }); 43 | // and check 44 | assert.deepEqual({ 45 | write: CL.ONE, 46 | read: CL.ONE 47 | }, client.consistencyLevel()); 48 | }, 49 | 50 | 'test connecting keyspace that does not exist throws error': function() { 51 | // connect to cassandra 52 | var client = new cassandra.Client('127.0.0.1:9160'); 53 | client.on('error', function(err) { 54 | assert.isNotNull(err); 55 | client.close(); 56 | }); 57 | client.connect('NonExistKeySpace'); 58 | }, 59 | 60 | 'test if accessing ColumnFamily that does not exist throws error': function() { 61 | // connect to cassandra 62 | var client = new cassandra.Client('127.0.0.1:9160'); 63 | client.on('error', function(err) { 64 | assert.isNotNull(err); 65 | assert.equal(err.message, 'Column Family NotExistCF does not exist.'); 66 | client.close(); 67 | }); 68 | client.connect('node_cassandra_test'); 69 | client.getColumnFamily('NotExistCF'); 70 | }, 71 | 72 | /* 73 | 'test if truncate works': function() { 74 | // connect to cassandra 75 | var client = new cassandra.Client('127.0.0.1:9160'); 76 | client.on('error', function(err) { 77 | assert.fail(err.message); 78 | }); 79 | client.connect('node_cassandra_test'); 80 | var standard = client.getColumnFamily('Standard'); 81 | standard.set('test', { foo: 123 }, function(err) { 82 | assert.isNull(err); 83 | standard.truncate(function(err) { 84 | assert.isNull(err); 85 | standard.get('test', function(err, res) { 86 | assert.isNull(err); 87 | client.close(); 88 | }); 89 | }); 90 | }); 91 | }, 92 | */ 93 | 94 | 'test if operations on client works properly': function(beforeExit) { 95 | // connect to cassandra 96 | var client = new cassandra.Client('127.0.0.1:9160'); 97 | client.connect('node_cassandra_test'); 98 | // or login if needed 99 | //client.connect('node_cassandra_test', {username: 'foo', password: 'bar'}); 100 | 101 | var standard = client.getColumnFamily('Standard'); 102 | var superCF = client.getColumnFamily('Super'); 103 | 104 | //------------------------------------- 105 | // set 106 | // set one record to standard column family. 107 | standard.set('todd', { 108 | id: 1, 109 | first_name: 'Todd', 110 | last_name: 'Dahl', 111 | age: 24 112 | }, function(err) { 113 | assert.isNull(err); 114 | }); 115 | 116 | // make sure it is seted. 117 | standard.get('todd', function(err, res) { 118 | assert.isNull(err); 119 | assert.deepEqual({ 120 | id: 1, 121 | first_name: 'Todd', 122 | last_name: 'Dahl', 123 | age: 24, 124 | }, res); 125 | }); 126 | 127 | // if you query for the key that doesn't exist, you will get empty object. 128 | standard.get('notexist', function(err, res) { 129 | assert.isNull(err); 130 | assert.deepEqual({}, res); 131 | }); 132 | // see if multiget works as expected. 133 | standard.set('jesse', { 134 | id: 2, 135 | first_name: 'Jesse', 136 | last_name: 'Pitman' 137 | }); 138 | 139 | standard.get(['todd', 'jesse'], function(err, res) { 140 | assert.isNull(err); 141 | assert.deepEqual({ 142 | todd: { 143 | id: '1', 144 | first_name: 'Todd', 145 | last_name: 'Dahl', 146 | age: '24', 147 | }, 148 | jesse: { 149 | id: '2', 150 | first_name: 'Jesse', 151 | last_name: 'Pitman' 152 | } 153 | }, res); 154 | }); 155 | 156 | // read operation with options. 157 | // valid options are: 158 | // start: SliceRange start 159 | // finish: SliceRange finish 160 | // reversed: SliceRange reversed 161 | // count: SliceRange count 162 | // 163 | // ttl: column ttl (not yet) 164 | // consistency_level: read consisteny level (not yet) 165 | // 166 | // specifying column names 167 | standard.get('todd', ['id', 'age'], function(err, res) { 168 | assert.isNull(err); 169 | assert.deepEqual({ 170 | id: '1', 171 | age: '24', 172 | }, res); 173 | }); 174 | // count scan 175 | standard.get('todd', {count: 1}, function(err, res) { 176 | assert.isNull(err); 177 | assert.deepEqual({ 178 | age: '24', 179 | }, res); 180 | }); 181 | // range scan 182 | standard.get('todd', {start: '', finish: 'age'}, function(err, res) { 183 | assert.isNull(err); 184 | assert.deepEqual({ 185 | age: '24', 186 | }, res); 187 | }); 188 | 189 | // counting 190 | // let's count number of cols 191 | standard.count('todd', function(err, res) { 192 | assert.isNull(err); 193 | assert.equal(4, res); 194 | }); 195 | 196 | // you can count colmns of multiple keys 197 | standard.count(['todd', 'jesse'], function(err, res){ 198 | assert.isNull(err); 199 | assert.deepEqual({ 200 | todd: 4, 201 | jesse: 3 202 | }, res); 203 | }); 204 | 205 | // super column 206 | superCF.set('edgar', { 207 | name: { 208 | first_name: 'Edgar', 209 | last_name: 'Sawyers' 210 | }, 211 | address: { 212 | city: 'Madison', 213 | state: 'WI' 214 | } 215 | }, function(err) { 216 | assert.isNull(err); 217 | }); 218 | 219 | superCF.get('edgar', function(err, res) { 220 | assert.isNull(err); 221 | assert.deepEqual({ 222 | name: { 223 | first_name: 'Edgar', 224 | last_name: 'Sawyers' 225 | }, 226 | address: { 227 | city: 'Madison', 228 | state: 'WI' 229 | } 230 | }, res); 231 | }); 232 | 233 | superCF.get('edgar', {count: 1}, function(err, res) { 234 | assert.isNull(err); 235 | assert.deepEqual({ 236 | address: { 237 | city: 'Madison', 238 | state: 'WI' 239 | } 240 | }, res); 241 | }); 242 | 243 | superCF.get('edgar', 'address', function(err, res) { 244 | assert.isNull(err); 245 | assert.deepEqual({ 246 | city: 'Madison', 247 | state: 'WI' 248 | }, res); 249 | }); 250 | 251 | // get only one column for certain key 252 | superCF.get('edgar', 'address', ['city'], function(err, res) { 253 | assert.isNull(err); 254 | assert.deepEqual({ 255 | city: 'Madison' 256 | }, res); 257 | }); 258 | // get only one column for certain key 259 | superCF.get('edgar', 'address', 'state', function(err, res) { 260 | assert.isNull(err); 261 | assert.deepEqual({ 262 | state: 'WI' 263 | }, res); 264 | }); 265 | 266 | superCF.get('edgar', 'address', {start: '', finish: 'city'}, function(err, res) { 267 | assert.isNull(err); 268 | assert.deepEqual({ 269 | city: 'Madison' 270 | }, res); 271 | }); 272 | 273 | // remove 274 | standard.remove('todd', 'id', function(err) { 275 | assert.isNull(err); 276 | }); 277 | 278 | standard.get('todd', function(err, res) { 279 | assert.isNull(err); 280 | assert.deepEqual({ 281 | first_name: 'Todd', 282 | last_name: 'Dahl', 283 | age: '24', 284 | }, res); 285 | }); 286 | standard.remove('todd', ['first_name', 'last_name']); 287 | standard.get('todd', function(err, res) { 288 | assert.isNull(err); 289 | assert.deepEqual({ 290 | age: '24', 291 | }, res); 292 | }); 293 | 294 | standard.remove('todd'); 295 | standard.get('todd', function(err, res) { 296 | assert.isNull(err); 297 | assert.deepEqual({}, res); 298 | }); 299 | 300 | standard.remove('jesse'); 301 | standard.get('jesse', function(err, res) { 302 | assert.isNull(err); 303 | assert.deepEqual({}, res); 304 | }); 305 | 306 | superCF.remove('edgar'); 307 | superCF.get('edgar', function(err, res) { 308 | assert.isNull(err); 309 | assert.deepEqual({}, res); 310 | 311 | client.close(); 312 | }); 313 | } 314 | }; 315 | --------------------------------------------------------------------------------