diff --git a/src/clientdb.js b/src/clientdb.js index be866e8dd..ef3c7f9d5 100644 --- a/src/clientdb.js +++ b/src/clientdb.js @@ -5,6 +5,7 @@ exports = module.exports = { get: get, getAll: getAll, + getAllWithTokenCount: getAllWithTokenCount, getAllWithTokenCountByIdentifier: getAllWithTokenCountByIdentifier, add: add, del: del, @@ -46,6 +47,16 @@ function getAll(callback) { }); } +function getAllWithTokenCount(callback) { + assert.strictEqual(typeof callback, 'function'); + + database.query('SELECT ' + CLIENTS_FIELDS_PREFIXED + ',COUNT(tokens.clientId) AS tokenCount FROM clients LEFT OUTER JOIN tokens ON clients.id=tokens.clientId GROUP BY clients.id', [], function (error, results) { + if (error) return callback(new DatabaseError(DatabaseError.INTERNAL_ERROR, error)); + + callback(null, results); + }); +} + function getAllWithTokenCountByIdentifier(identifier, callback) { assert.strictEqual(typeof identifier, 'string'); assert.strictEqual(typeof callback, 'function');