diff --git a/lib/client.js b/lib/client.js index 770670e..431c525 100644 --- a/lib/client.js +++ b/lib/client.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.7.0 // # Client: server information and object factory // ## Dependencies diff --git a/lib/connection.js b/lib/connection.js index ce7d60e..a17ba73 100644 --- a/lib/connection.js +++ b/lib/connection.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.7.0 // # Connection: HTTP REST requests for HBase // The connection object handles HTTP requests. You shouldn't have to call it diff --git a/lib/index.js b/lib/index.js index 00f8a75..d74af80 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.7.0 // # Node Hbase: getting started var hbase; diff --git a/lib/row.js b/lib/row.js index e5df293..e1aec0d 100644 --- a/lib/row.js +++ b/lib/row.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.7.0 // # Row operations: CRUD operation on rows and columns // Row objects provide access and manipulation on colunns and rows. Single and @@ -138,6 +138,7 @@ Row.prototype.put = function(columns, values, callback) { data.forEach((d) => { var key; key = d.key || this.key; + key = utils.base64.encode(key, this.client.options.encoding); if (!(key in cellsKeys)) { cellsKeys[key] = []; } @@ -146,7 +147,7 @@ Row.prototype.put = function(columns, values, callback) { for (k in cellsKeys) { cells = cellsKeys[k]; bodyRow = { - key: utils.base64.encode(k, this.client.options.encoding), + key: k, Cell: [] }; for (k1 in cells) { diff --git a/lib/scanner.js b/lib/scanner.js index a604366..86f926f 100644 --- a/lib/scanner.js +++ b/lib/scanner.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.7.0 // # Scanner operations // Scanner are the most efficient way to retrieve multiple @@ -18,7 +18,7 @@ Table = require('./table'); // ## Constructor Scanner = function(client, options = {}) { - var base; + var base, base1; this.options = options; this.options.objectMode = true; Readable.call(this, this.options); @@ -35,6 +35,9 @@ Scanner = function(client, options = {}) { if ((base = this.options).batch == null) { base.batch = 1000; } + if ((base1 = this.options).types == null) { + base1.types = {}; + } if (!this.options.table) { throw Error('Missing required option "table"'); } @@ -130,11 +133,23 @@ Scanner.prototype.get = function(callback) { data.Row.forEach((row) => { key = utils.base64.decode(row.key, this.client.options.encoding); return row.Cell.forEach((cell) => { + var type; data = {}; data.key = key; data.column = utils.base64.decode(cell.column, this.client.options.encoding); data.timestamp = cell.timestamp; - data.$ = utils.base64.decode(cell.$, this.client.options.encoding); + type = this.options.types[data.column]; + if (this.options.returnBuffer) { + data.$ = Buffer.from(cell.$, "base64"); + } else { + switch (type) { + case "long": + data.$ = parseInt(utils.base64.decode(cell.$, "hex"), 16); + break; + default: + data.$ = utils.base64.decode(cell.$, this.client.options.encoding); + } + } return cells.push(data); }); }); diff --git a/lib/table.js b/lib/table.js index b08785c..2e7739a 100644 --- a/lib/table.js +++ b/lib/table.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.7.0 // # Table operations: create, modify and delete HBase tables // ## Dependencies diff --git a/lib/utils.js b/lib/utils.js index 30cfec6..71131eb 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -1,4 +1,4 @@ -// Generated by CoffeeScript 2.5.1 +// Generated by CoffeeScript 2.7.0 var crypto, utils; crypto = require('crypto'); diff --git a/src/row.coffee.md b/src/row.coffee.md index b246cd2..80575f0 100644 --- a/src/row.coffee.md +++ b/src/row.coffee.md @@ -90,12 +90,13 @@ Insert and update a column value, insert and update multiple column values or in cellsKeys = {} data.forEach (d) => key = d.key or @key + key = utils.base64.encode key, @client.options.encoding cellsKeys[key] = [] unless key of cellsKeys cellsKeys[key].push d for k of cellsKeys cells = cellsKeys[k] bodyRow = - key: utils.base64.encode k, @client.options.encoding + key: k Cell: [] for k1 of cells cell = cells[k1] diff --git a/src/scanner.coffee.md b/src/scanner.coffee.md index 10d9fbe..da24997 100644 --- a/src/scanner.coffee.md +++ b/src/scanner.coffee.md @@ -24,6 +24,7 @@ rows and columns from HBase. Internally, it implements the native # @id = id or null @options = table: @options if typeof @options is 'string' @options.batch ?= 1000 + @options.types ?= {} throw Error 'Missing required option "table"' unless @options.table @options.id = null @callback = null @@ -82,7 +83,13 @@ Internal method to retrieve a batch of records. data.key = key data.column = utils.base64.decode cell.column, @client.options.encoding data.timestamp = cell.timestamp - data.$ = utils.base64.decode cell.$, @client.options.encoding + type = @options.types[data.column] + if @options.returnBuffer + data.$ = Buffer.from(cell.$, "base64") + else + switch type + when "long" then data.$ = parseInt(utils.base64.decode(cell.$, "hex"), 16); + else data.$ = utils.base64.decode cell.$, @client.options.encoding cells.push data callback null, cells