Browse files

add count functionality

  • Loading branch information...
1 parent 504d76a commit 43614b1f36e29df33e56a74a8125df83fc25a03a @danielb2 danielb2 committed Jan 28, 2013
Showing with 14 additions and 1 deletion.
  1. +13 −0 index.js
  2. +1 −1 package.json
View
13 index.js
@@ -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,
View
2 package.json
@@ -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",

0 comments on commit 43614b1

Please sign in to comment.