2020-01-21 18:12:14 +00:00
|
|
|
// Copyright IBM Corp. 2016,2019. All Rights Reserved.
|
2019-05-08 15:45:37 +00:00
|
|
|
// Node module: loopback-datasource-juggler
|
|
|
|
// This file is licensed under the MIT License.
|
|
|
|
// License text available at https://opensource.org/licenses/MIT
|
|
|
|
|
2016-08-08 08:15:22 +00:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-07 14:54:29 +00:00
|
|
|
const assert = require('assert');
|
|
|
|
const utils = require('../utils');
|
2016-08-08 08:15:22 +00:00
|
|
|
|
|
|
|
/**
|
2016-09-17 00:03:33 +00:00
|
|
|
* Return the value associated with a given key.
|
2016-08-08 08:15:22 +00:00
|
|
|
*
|
2016-09-17 00:03:33 +00:00
|
|
|
* @param {String} key Key to use when searching the database.
|
|
|
|
* @options {Object} options
|
|
|
|
* @callback {Function} callback
|
|
|
|
* @param {Error} err Error object.
|
|
|
|
* @param {*} result Value associated with the given key.
|
|
|
|
* @promise
|
2016-08-08 08:15:22 +00:00
|
|
|
*
|
|
|
|
* @header KVAO.get(key, cb)
|
|
|
|
*/
|
|
|
|
module.exports = function keyValueGet(key, options, callback) {
|
|
|
|
if (callback == undefined && typeof options === 'function') {
|
|
|
|
callback = options;
|
|
|
|
options = {};
|
|
|
|
} else if (!options) {
|
|
|
|
options = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
assert(typeof key === 'string' && key, 'key must be a non-empty string');
|
|
|
|
|
|
|
|
callback = callback || utils.createPromiseCallback();
|
|
|
|
this.getConnector().get(this.modelName, key, options, function(err, result) {
|
|
|
|
// TODO convert raw result to Model instance (?)
|
|
|
|
callback(err, result);
|
|
|
|
});
|
|
|
|
return callback.promise;
|
|
|
|
};
|