mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-02-23 07:01:12 +01:00
feat: allow optional fields argument on db.getObject(s) (#9385)
This commit is contained in:
committed by
GitHub
parent
754965b572
commit
4327a09d76
@@ -70,11 +70,13 @@ module.exports = function (module) {
|
||||
});
|
||||
};
|
||||
|
||||
module.getObject = async function (key) {
|
||||
module.getObject = async function (key, fields = []) {
|
||||
if (!key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (fields.length) {
|
||||
return await module.getObjectFields(key, fields);
|
||||
}
|
||||
const res = await module.pool.query({
|
||||
name: 'getObject',
|
||||
text: `
|
||||
@@ -91,11 +93,13 @@ SELECT h."data"
|
||||
return res.rows.length ? res.rows[0].data : null;
|
||||
};
|
||||
|
||||
module.getObjects = async function (keys) {
|
||||
module.getObjects = async function (keys, fields = []) {
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (fields.length) {
|
||||
return await module.getObjectsFields(keys, fields);
|
||||
}
|
||||
const res = await module.pool.query({
|
||||
name: 'getObjects',
|
||||
text: `
|
||||
@@ -170,7 +174,9 @@ SELECT (SELECT jsonb_object_agg(f, d."value")
|
||||
if (!Array.isArray(keys) || !keys.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!fields.length) {
|
||||
return await module.getObjects(keys);
|
||||
}
|
||||
const res = await module.pool.query({
|
||||
name: 'getObjectsFields',
|
||||
text: `
|
||||
|
||||
Reference in New Issue
Block a user