mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-03-14 00:20:40 +01:00
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:
committed by
GitHub
parent
52a2e5d61d
commit
af1f7249a7
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
module.exports = function (module) {
|
||||
var helpers = require('../helpers');
|
||||
var utils = require('../../../utils');
|
||||
|
||||
@@ -19,10 +19,8 @@ module.exports = function (db, module) {
|
||||
score = parseFloat(score);
|
||||
|
||||
await module.transaction(async function (client) {
|
||||
var query = client.query.bind(client);
|
||||
|
||||
await helpers.ensureLegacyObjectType(client, key, 'zset');
|
||||
await query({
|
||||
await client.query({
|
||||
name: 'sortedSetAdd',
|
||||
text: `
|
||||
INSERT INTO "legacy_zset" ("_key", "value", "score")
|
||||
@@ -52,9 +50,8 @@ module.exports = function (db, module) {
|
||||
helpers.removeDuplicateValues(values, scores);
|
||||
|
||||
await module.transaction(async function (client) {
|
||||
var query = client.query.bind(client);
|
||||
await helpers.ensureLegacyObjectType(client, key, 'zset');
|
||||
await query({
|
||||
await client.query({
|
||||
name: 'sortedSetAddBulk',
|
||||
text: `
|
||||
INSERT INTO "legacy_zset" ("_key", "value", "score")
|
||||
@@ -84,9 +81,8 @@ DO UPDATE SET "score" = EXCLUDED."score"`,
|
||||
scores = isArrayOfScores ? scores.map(score => parseFloat(score)) : parseFloat(scores);
|
||||
|
||||
await module.transaction(async function (client) {
|
||||
var query = client.query.bind(client);
|
||||
await helpers.ensureLegacyObjectsType(client, keys, 'zset');
|
||||
await query({
|
||||
await client.query({
|
||||
name: isArrayOfScores ? 'sortedSetsAddScores' : 'sortedSetsAdd',
|
||||
text: isArrayOfScores ? `
|
||||
INSERT INTO "legacy_zset" ("_key", "value", "score")
|
||||
@@ -117,9 +113,8 @@ INSERT INTO "legacy_zset" ("_key", "value", "score")
|
||||
values.push(item[2]);
|
||||
});
|
||||
await module.transaction(async function (client) {
|
||||
var query = client.query.bind(client);
|
||||
await helpers.ensureLegacyObjectsType(client, keys, 'zset');
|
||||
await query({
|
||||
await client.query({
|
||||
name: 'sortedSetAddBulk2',
|
||||
text: `
|
||||
INSERT INTO "legacy_zset" ("_key", "value", "score")
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
module.exports = function (module) {
|
||||
module.sortedSetIntersectCard = async function (keys) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const res = await db.query({
|
||||
const res = await module.pool.query({
|
||||
name: 'sortedSetIntersectCard',
|
||||
text: `
|
||||
WITH A AS (SELECT z."value" v,
|
||||
@@ -55,7 +55,7 @@ SELECT COUNT(*) c
|
||||
limit = null;
|
||||
}
|
||||
|
||||
const res = await db.query({
|
||||
const res = await module.pool.query({
|
||||
name: 'getSortedSetIntersect' + aggregate + (params.sort > 0 ? 'Asc' : 'Desc') + 'WithScores',
|
||||
text: `
|
||||
WITH A AS (SELECT z."value",
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
module.exports = function (module) {
|
||||
var helpers = require('../helpers');
|
||||
|
||||
module.sortedSetRemove = async function (key, value) {
|
||||
@@ -20,7 +20,7 @@ module.exports = function (db, module) {
|
||||
value = [value];
|
||||
}
|
||||
value = value.map(helpers.valueToString);
|
||||
await db.query({
|
||||
await module.pool.query({
|
||||
name: 'sortedSetRemove',
|
||||
text: `
|
||||
DELETE FROM "legacy_zset"
|
||||
@@ -37,7 +37,7 @@ DELETE FROM "legacy_zset"
|
||||
|
||||
value = helpers.valueToString(value);
|
||||
|
||||
await db.query({
|
||||
await module.pool.query({
|
||||
name: 'sortedSetsRemove',
|
||||
text: `
|
||||
DELETE FROM "legacy_zset"
|
||||
@@ -59,7 +59,7 @@ DELETE FROM "legacy_zset"
|
||||
max = null;
|
||||
}
|
||||
|
||||
await db.query({
|
||||
await module.pool.query({
|
||||
name: 'sortedSetsRemoveRangeByScore',
|
||||
text: `
|
||||
DELETE FROM "legacy_zset"
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
'use strict';
|
||||
|
||||
module.exports = function (db, module) {
|
||||
module.exports = function (module) {
|
||||
module.sortedSetUnionCard = async function (keys) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
const res = await db.query({
|
||||
const res = await module.pool.query({
|
||||
name: 'sortedSetUnionCard',
|
||||
text: `
|
||||
SELECT COUNT(DISTINCT z."value") c
|
||||
@@ -49,7 +49,7 @@ SELECT COUNT(DISTINCT z."value") c
|
||||
limit = null;
|
||||
}
|
||||
|
||||
const res = await db.query({
|
||||
const res = await module.pool.query({
|
||||
name: 'getSortedSetUnion' + aggregate + (params.sort > 0 ? 'Asc' : 'Desc') + 'WithScores',
|
||||
text: `
|
||||
WITH A AS (SELECT z."value",
|
||||
|
||||
Reference in New Issue
Block a user