Commit 096a49ea4b794545bb3f028e122baaaaca5784a7
1 parent
b98e2730ff
Exists in
master
avances
Showing
2 changed files
with
10 additions
and
5 deletions
Show diff stats
data/index.js
... | ... | @@ -3,9 +3,16 @@ module.exports = function(config) { |
3 | 3 | var knex = require('knex')(config); |
4 | 4 | |
5 | 5 | return { |
6 | - getEntity: function (table, where) { | |
6 | + getEntity: function (message) { | |
7 | 7 | |
8 | - return knex(table).where(where).select('*'); | |
8 | + return new Promise(function(resolve, reject) { | |
9 | + | |
10 | + knex(message.tableName).where(message.where).select('*').then(function (data) { | |
11 | + | |
12 | + message.data = data[0]; | |
13 | + resolve(message); | |
14 | + }); | |
15 | + }); | |
9 | 16 | } |
10 | 17 | } |
11 | 18 | } |
index.js
... | ... | @@ -22,9 +22,7 @@ client.on('open', function open() { |
22 | 22 | switch (message.action) { |
23 | 23 | case 'getEntity': |
24 | 24 | |
25 | - data.getEntity(message.tableName, message.where || {}).then(function(data) { | |
26 | - | |
27 | - message.data = data[0]; | |
25 | + data.getEntity(message).then(function(message) { | |
28 | 26 | |
29 | 27 | client.send(JSON.stringify(message)); |
30 | 28 | }); |