Permalink
Browse files

Add user methods to the store and MySQL adapter

  • Loading branch information...
1 parent 7228ddb commit 8b90176308c1356c55f0672ef0ab4e726988e28f @aron aron committed May 5, 2012
Showing with 25 additions and 1 deletion.
  1. +22 −0 lib/db/mysql.js
  2. +3 −1 lib/store.js
View
@@ -93,5 +93,27 @@ MySQL.prototype = {
} else {
fn("too-many-tries"); // Need error objects.
}
+ },
+ getUser: function (id, fn) {
+ this.connection.query(templates.getUser, [id], function (err, results) {
+ if (err || !results.length) {
+ return fn(!err && !results.length ? 'not-found' : err);
+ }
+ fn(null, results[0]);
+ });
+ },
+ setUser: function (params, fn) {
+ var values = [
+ params.name,
+ params.key,
+ params.email
+ ], sql = templates.setUser;
+
+ this.connection.query(sql, values, function (err, result) {
+ if (err || !result.affectedRows) {
+ return fn(err);
+ }
+ fn(null, result.insertId);
+ });
}
};
View
@@ -12,7 +12,9 @@ var methods = [
'getBin',
'getLatestBin',
'getBinsByOwner',
- 'generateBinId'
+ 'generateBinId',
+ 'getUser',
+ 'setUser'
];
// Proxy the methods through the store.

0 comments on commit 8b90176

Please sign in to comment.