jenkins-bot has submitted this change and it was merged.
Change subject: Use the P helper module in the implementation of Db.
......................................................................
Use the P helper module in the implementation of Db.
Change-Id: Iaf71b0cf160ddb92a7c337c39ef09985474ebb8e
---
M lib/db.js
1 file changed, 19 insertions(+), 11 deletions(-)
Approvals:
Cscott: Looks good to me, approved
jenkins-bot: Verified
diff --git a/lib/db.js b/lib/db.js
index fc044b8..d331321 100644
--- a/lib/db.js
+++ b/lib/db.js
@@ -4,6 +4,8 @@
var when = require('when');
var nodefn = require("when/node/function");
+var P = require('./p');
+
var Db = module.exports = function(filename, options) {
/* jshint bitwise: false */
options = options || {};
@@ -17,9 +19,11 @@
// this.db is a promise for the database, once tables have been created
this.db = deferred.promise.then(function() {
if (!options.readonly) {
- return nodefn.call(db.run.bind(db),
- "CREATE TABLE IF NOT
EXISTS "+
- "kv_table (key TEXT
PRIMARY KEY, val TEXT);");
+ return P.call(
+ db.run, db,
+ "CREATE TABLE IF NOT EXISTS " +
+ "kv_table (key TEXT PRIMARY KEY, val TEXT);"
+ );
}
}).then(function() { return db; });
};
@@ -27,9 +31,11 @@
// Returns a promise for the value.
Db.prototype.get = function(key, nojson) {
return this.db.then(function(db) {
- return nodefn.call(db.get.bind(db),
- "SELECT val FROM kv_table
WHERE key = ?;",
- '' + key);
+ return P.call(
+ db.get, db,
+ "SELECT val FROM kv_table WHERE key = ?;",
+ '' + key
+ );
}).then(function(row) {
var val = row.val;
return nojson ? val : JSON.parse(val);
@@ -44,7 +50,7 @@
f(row.key, val);
};
return this.db.then(function(db) {
- return nodefn.call(db.each.bind(db), "SELECT * FROM kv_table;",
each);
+ return P.call(db.each, db, "SELECT * FROM kv_table;", each);
});
};
@@ -52,15 +58,17 @@
Db.prototype.put = function(key, value) {
if (typeof(value) !== 'string') { value = JSON.stringify(value); }
return this.db.then(function(db) {
- return nodefn.call(db.run.bind(db),
- "INSERT OR REPLACE INTO
kv_table (key, val) "+
- "VALUES (?,?);", '' + key,
value);
+ return P.call(
+ db.run, db,
+ "INSERT OR REPLACE INTO kv_table (key, val) VALUES
(?,?);",
+ '' + key, value
+ );
});
};
// Returns a promise to close and finalize the database.
Db.prototype.close = function() {
return this.db.then(function(db) {
- return nodefn.call(db.close.bind(db));
+ return P.call(db.close, db);
});
};
--
To view, visit https://gerrit.wikimedia.org/r/96830
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: merged
Gerrit-Change-Id: Iaf71b0cf160ddb92a7c337c39ef09985474ebb8e
Gerrit-PatchSet: 1
Gerrit-Project:
mediawiki/extensions/Collection/OfflineContentGenerator/latex_renderer
Gerrit-Branch: master
Gerrit-Owner: Cscott <[email protected]>
Gerrit-Reviewer: Cscott <[email protected]>
Gerrit-Reviewer: jenkins-bot
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits