Comparing version 0.1.5 to 0.1.6
@@ -0,1 +1,5 @@ | ||
#0.1.6 | ||
* Added count method | ||
#0.1.5 | ||
@@ -2,0 +6,0 @@ |
@@ -46,2 +46,8 @@ import 'reflect-metadata'; | ||
delete(wheres: any): Promise<any>; | ||
/** | ||
* Count items by where clause | ||
* @param wheres | ||
* @return promised returned query | ||
*/ | ||
count(wheres: any): Promise<any>; | ||
} |
@@ -112,4 +112,19 @@ "use strict"; | ||
} | ||
/** | ||
* Count items by where clause | ||
* @param wheres | ||
* @return promised returned query | ||
*/ | ||
count(wheres) { | ||
return __awaiter(this, void 0, void 0, function* () { | ||
if (!wheres) | ||
throw new Error(exports.errors.where); | ||
let statement = 'SELECT COUNT(*) AS count FROM ' + this.table; | ||
statement = helpers_1.mapWhereClause(statement, wheres); | ||
const data = yield this.db.query(statement); | ||
return data.count; | ||
}); | ||
} | ||
} | ||
exports.Query = Query; | ||
//# sourceMappingURL=on.js.map |
{ | ||
"name": "classql", | ||
"version": "0.1.5", | ||
"version": "0.1.6", | ||
"main": "dist/index.js", | ||
@@ -5,0 +5,0 @@ "bugs": "https://github.com/sorakthunly/classql/issues", |
@@ -98,2 +98,7 @@ # classql | ||
/** COUNT */ | ||
// Returns the number of result counted e.g. 12 | ||
await db.on(UserAccount).count({ name: 'John' }); | ||
``` |
@@ -115,2 +115,16 @@ const mysql = require('promise-mysql'); | ||
} | ||
/** | ||
* Count items by where clause | ||
* @param wheres | ||
* @return promised returned query | ||
*/ | ||
public async count(wheres: any): Promise<any> { | ||
if (!wheres) throw new Error(errors.where); | ||
let statement = 'SELECT COUNT(*) AS count FROM ' + this.table; | ||
statement = mapWhereClause(statement, wheres); | ||
const data = await this.db.query(statement); | ||
return data.count; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
48862
1022
104