Skip to content

Commit

Permalink
add count functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
danielb2 committed Jan 28, 2013
1 parent 504d76a commit 43614b1
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
13 changes: 13 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,19 @@ exports.Adapter = function(settings) {
return that;
};

this.count = function(tableName, responseCallback) {
if (typeof tableName === 'string') {
var combinedQueryString = 'SELECT COUNT(*) as count FROM ' + escapeFieldName(tableName)
+ buildJoinString()
+ buildDataString(whereClause, ' AND ', 'WHERE');

connection.query(combinedQueryString, function(err, res) { responseCallback(null, res[0]['count'])});
resetQuery(combinedQueryString);
}

return that;
}

this.join = function(tableName, relation, direction) {
joinClause.push({
table: tableName,
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "mysql-activerecord",
"version": "0.7.2",
"version": "0.7.3",
"author": "Martin Tajur <martin@tajur.ee>",
"description": "MySQL ActiveRecord pattern implementation on top of the mysql module.",
"homepage": "https://github.com/martintajur/node-mysql-activerecord",
Expand Down

0 comments on commit 43614b1

Please sign in to comment.