feat: test psql without defineProperty (#7815)

* feat: test psql without defineProperty

* feat: refactor psql

remove .bind calls, use module.pool.query directly
move requires to top of file
move promisify to bottom so .init etc are promisified

* feat: mongodb

move requires to bottom

* feat: redis
This commit is contained in:
Barış Soner Uşaklı
2019-08-05 09:20:00 -04:00
committed by GitHub
parent 52a2e5d61d
commit af1f7249a7
33 changed files with 301 additions and 341 deletions

View File

@@ -1,6 +1,6 @@
'use strict';
module.exports = function (redisClient, module) {
module.exports = function (module) {
const helpers = require('../helpers');
const utils = require('../../../utils');
@@ -14,7 +14,7 @@ module.exports = function (redisClient, module) {
if (!utils.isNumber(score)) {
throw new Error('[[error:invalid-score, ' + score + ']]');
}
await redisClient.async.zadd(key, score, String(value));
await module.client.async.zadd(key, score, String(value));
};
async function sortedSetAddMulti(key, scores, values) {
@@ -34,7 +34,7 @@ module.exports = function (redisClient, module) {
for (var i = 0; i < scores.length; i += 1) {
args.push(scores[i], String(values[i]));
}
await redisClient.async.zadd(args);
await module.client.async.zadd(args);
}
module.sortedSetsAdd = async function (keys, scores, value) {
@@ -50,7 +50,7 @@ module.exports = function (redisClient, module) {
throw new Error('[[error:invalid-data]]');
}
var batch = redisClient.batch();
var batch = module.client.batch();
for (var i = 0; i < keys.length; i += 1) {
if (keys[i]) {
batch.zadd(keys[i], isArrayOfScores ? scores[i] : scores, String(value));
@@ -63,7 +63,7 @@ module.exports = function (redisClient, module) {
if (!Array.isArray(data) || !data.length) {
return;
}
var batch = redisClient.batch();
var batch = module.client.batch();
data.forEach(function (item) {
batch.zadd(item[0], item[1], item[2]);
});

View File

@@ -1,7 +1,7 @@
'use strict';
module.exports = function (redisClient, module) {
module.exports = function (module) {
const helpers = require('../helpers');
module.sortedSetIntersectCard = async function (keys) {
if (!Array.isArray(keys) || !keys.length) {
@@ -11,7 +11,7 @@ module.exports = function (redisClient, module) {
var interParams = [tempSetName, keys.length].concat(keys);
var multi = redisClient.multi();
var multi = module.client.multi();
multi.zinterstore(interParams);
multi.zcard(tempSetName);
multi.del(tempSetName);
@@ -51,7 +51,7 @@ module.exports = function (redisClient, module) {
rangeParams.push('WITHSCORES');
}
var multi = redisClient.multi();
var multi = module.client.multi();
multi.zinterstore(interParams);
multi[params.method](rangeParams);
multi.del(tempSetName);

View File

@@ -1,7 +1,7 @@
'use strict';
module.exports = function (redisClient, module) {
module.exports = function (module) {
var helpers = require('../helpers');
module.sortedSetRemove = async function (key, value) {
@@ -17,11 +17,11 @@ module.exports = function (redisClient, module) {
}
if (Array.isArray(key)) {
const batch = redisClient.batch();
const batch = module.client.batch();
key.forEach(k => batch.zrem(k, value));
await helpers.execBatch(batch);
} else {
await redisClient.async.zrem(key, value);
await module.client.async.zrem(key, value);
}
};
@@ -30,7 +30,7 @@ module.exports = function (redisClient, module) {
};
module.sortedSetsRemoveRangeByScore = async function (keys, min, max) {
var batch = redisClient.batch();
var batch = module.client.batch();
keys.forEach(k => batch.zremrangebyscore(k, min, max));
await helpers.execBatch(batch);
};
@@ -39,7 +39,7 @@ module.exports = function (redisClient, module) {
if (!Array.isArray(data) || !data.length) {
return;
}
const batch = redisClient.batch();
const batch = module.client.batch();
data.forEach(item => batch.zrem(item[0], item[1]));
await helpers.execBatch(batch);
};

View File

@@ -1,14 +1,14 @@
'use strict';
module.exports = function (redisClient, module) {
module.exports = function (module) {
const helpers = require('../helpers');
module.sortedSetUnionCard = async function (keys) {
var tempSetName = 'temp_' + Date.now();
if (!keys.length) {
return 0;
}
var multi = redisClient.multi();
var multi = module.client.multi();
multi.zunionstore([tempSetName, keys.length].concat(keys));
multi.zcard(tempSetName);
multi.del(tempSetName);
@@ -38,7 +38,7 @@ module.exports = function (redisClient, module) {
rangeParams.push('WITHSCORES');
}
var multi = redisClient.multi();
var multi = module.client.multi();
multi.zunionstore([tempSetName, params.sets.length].concat(params.sets));
multi[params.method](rangeParams);
multi.del(tempSetName);