Comparing version 0.0.1-alpha.6 to 0.0.1-alpha.7
const Bluebird = require('bluebird') | ||
// const debug = require('debug')('hequelize:Model') | ||
const _ = require('lodash') | ||
@@ -33,12 +32,6 @@ const HBase = require('hbase-rpc-client') | ||
* | ||
* e.g. | ||
* ```javascript | ||
* db.File.get('row key', { | ||
* columns: ['cf1:col1', 'cf2:cf2'] | ||
* }) | ||
*``` | ||
* @static | ||
* @param {string} rowKey the row key | ||
* @param {object} [options = {}] | ||
* @param {object} [options.columns = all_columns] | ||
* | ||
* @returns {object} return object | ||
@@ -51,10 +44,3 @@ */ | ||
if (this.defaultFamily) { | ||
options.columns = options.columns.map(col => { | ||
if (col.indexOf(':') === -1) { | ||
return this.defaultFamily + ':' + col | ||
} | ||
return col | ||
}) | ||
} | ||
options.columns = this.conformColumns(options.columns) | ||
@@ -72,3 +58,38 @@ const get = new HBase.Get(rowKey) | ||
static async put (rowKey, values, options) { | ||
/** | ||
* mget | ||
* | ||
* @param {Array<string>} rowKeys the row key array | ||
* @param {object} [options] | ||
* @param {Array<string>} [options.columns = all_columns] columns | ||
* | ||
* @return {Array<object>} object array | ||
*/ | ||
static async mget (rowKeys, options) { | ||
options = _.defaults(options, { | ||
columns: this.columnNames | ||
}) | ||
options.columns = this.conformColumns(options.columns) | ||
const gets = rowKeys.map(key => { | ||
const get = new HBase.Get(key) | ||
options.columns.forEach(col => { | ||
const [cf, q] = split(col) | ||
get.addColumn(cf, q) | ||
}) | ||
return get | ||
}) | ||
const results = await this.client.mgetAsync(this.tableName, gets) | ||
return results.map(result => this.formatAfterGet(result, options)) | ||
} | ||
/** | ||
* put | ||
* | ||
* @param {string} rowKey the row key | ||
* @param {object} values if values is null and row key exists, the cell will be deleted | ||
*/ | ||
static async put (rowKey, values) { | ||
const columns = [] | ||
@@ -119,6 +140,6 @@ const deleteColumns = [] | ||
* @param {object} options | ||
* @param {string} options.startRow the start row key | ||
* @param {object} [options.stopRow] the stop row key | ||
* @param {string} options.startRow the start row key, will be included in the result | ||
* @param {object} [options.stopRow] the stop row key, will be included in the result | ||
* @param {object} [options.limit] the number limit | ||
* @returns {Array<Model>} | ||
* @returns {Array<object>} | ||
*/ | ||
@@ -159,4 +180,9 @@ static async scan (options) { | ||
const rawObject = processRaw(raw) | ||
if (!rawObject) { | ||
return null | ||
} | ||
const df = this.defaultFamily | ||
const rawObject = processRaw(raw) | ||
const ret = {} | ||
@@ -216,2 +242,15 @@ | ||
} | ||
static conformColumns (columns) { | ||
if (this.defaultFamily) { | ||
columns = columns.map(col => { | ||
if (col.indexOf(':') === -1) { | ||
return this.defaultFamily + ':' + col | ||
} | ||
return col | ||
}) | ||
return columns | ||
} | ||
return columns | ||
} | ||
} | ||
@@ -223,2 +262,8 @@ | ||
} | ||
// mget resutl this if key not exists | ||
if (raw.associatedCellCount === 0 && raw.exists === null) { | ||
return null | ||
} | ||
return raw.columns.reduce((acc, col) => { | ||
@@ -225,0 +270,0 @@ acc[`${col.family}:${col.qualifier}`] = col.value |
{ | ||
"name": "hequelize", | ||
"version": "0.0.1-alpha.6", | ||
"version": "0.0.1-alpha.7", | ||
"description": "Simple HBase ORM based on hbase-rpc-client", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
17042
12
556