私はnodejs mysqlを使用して、開発用にローカルに稼働しているデータベースにアクセスしようとしています。すべて正常に実行されており、サーバーへの照会を成功させてデータを戻すことができます。コールバック後にnodejs Mysqlを使用して関数にデータを取得するには
私は以下のように私がmodule.exportsであるため、呼び出されたサーバ内からアクセスでき、loadExp()
メソッドが呼び出されます。今
var dataStore = function (connection) {
this.con = connection;
this.clientArr = new Map();
/**
* Loads all of the user experiences into the array.
*/
this.loadExp = function() {
var output = 'err';
loadData(this.con, function (err, result) {
console.log(err || result);
output = result.uuid;
});
console.log(output);
};
function loadData(con, callback) {
con.query('SELECT * FROM exp', function (err, rows, fields) {
if (err) throw err;
callback(null, rows);
});
}
/**
* Returns the value of a client from within the hash map.
* @param id
* @returns {*|String}
*/
this.getClient = function (id) {
var value = this.clients.get(id);
if (value != null) {
return value;
} else {
return 'err';
}
};
/**
* Returns a full list of clients.
* @returns {Map}
*/
this.getClientList = function() {
return this.clientArr;
};
/**
* Creates a new instance of a client within the database and also within our datastore.
* @param id
* @param client
*/
this.addClient = function (id, client) {
this.clientArr.set(id, client);
};
};
module.exports = dataStore;
私は、この関数の一番下に概説私this.addClient
機能を利用したいと思いますが、私はこれを可能にする範囲で自分のデータを取得することはできないと私は、このデータを取得する方法を用こだわっていますそれが使用可能であるようにスコープ内にある。
'this.addClient'機能を利用しようと試みたコードを貼り付けます。または、あなたができると思うものをいくつかの疑似コードで記述します。現時点では、あなたが望む最終結果を理解することは難しいです。 –