|
|
@ -9,16 +9,28 @@ module.exports = function (module) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await module.transaction(async (client) => {
|
|
|
|
await module.transaction(async (client) => {
|
|
|
|
await helpers.ensureLegacyObjectType(client, key, 'list');
|
|
|
|
async function doPrepend(value) {
|
|
|
|
await client.query({
|
|
|
|
await client.query({
|
|
|
|
name: 'listPrepend',
|
|
|
|
name: 'listPrepend',
|
|
|
|
text: `
|
|
|
|
text: `
|
|
|
|
INSERT INTO "legacy_list" ("_key", "array")
|
|
|
|
INSERT INTO "legacy_list" ("_key", "array")
|
|
|
|
VALUES ($1::TEXT, ARRAY[$2::TEXT])
|
|
|
|
VALUES ($1::TEXT, ARRAY[$2::TEXT])
|
|
|
|
ON CONFLICT ("_key")
|
|
|
|
ON CONFLICT ("_key")
|
|
|
|
DO UPDATE SET "array" = ARRAY[$2::TEXT] || "legacy_list"."array"`,
|
|
|
|
DO UPDATE SET "array" = ARRAY[$2::TEXT] || "legacy_list"."array"`,
|
|
|
|
values: [key, value],
|
|
|
|
values: [key, value],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await helpers.ensureLegacyObjectType(client, key, 'list');
|
|
|
|
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
|
|
|
|
// TODO: perf make single query
|
|
|
|
|
|
|
|
for (const v of value) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
|
|
|
await doPrepend(v);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await doPrepend(value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
@ -26,18 +38,28 @@ DO UPDATE SET "array" = ARRAY[$2::TEXT] || "legacy_list"."array"`,
|
|
|
|
if (!key) {
|
|
|
|
if (!key) {
|
|
|
|
return;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
await module.transaction(async (client) => {
|
|
|
|
await module.transaction(async (client) => {
|
|
|
|
await helpers.ensureLegacyObjectType(client, key, 'list');
|
|
|
|
async function doAppend(value) {
|
|
|
|
await client.query({
|
|
|
|
await client.query({
|
|
|
|
name: 'listAppend',
|
|
|
|
name: 'listAppend',
|
|
|
|
text: `
|
|
|
|
text: `
|
|
|
|
INSERT INTO "legacy_list" ("_key", "array")
|
|
|
|
INSERT INTO "legacy_list" ("_key", "array")
|
|
|
|
VALUES ($1::TEXT, ARRAY[$2::TEXT])
|
|
|
|
VALUES ($1::TEXT, ARRAY[$2::TEXT])
|
|
|
|
ON CONFLICT ("_key")
|
|
|
|
ON CONFLICT ("_key")
|
|
|
|
DO UPDATE SET "array" = "legacy_list"."array" || ARRAY[$2::TEXT]`,
|
|
|
|
DO UPDATE SET "array" = "legacy_list"."array" || ARRAY[$2::TEXT]`,
|
|
|
|
values: [key, value],
|
|
|
|
values: [key, value],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await helpers.ensureLegacyObjectType(client, key, 'list');
|
|
|
|
|
|
|
|
if (Array.isArray(value)) {
|
|
|
|
|
|
|
|
// TODO: perf make single query
|
|
|
|
|
|
|
|
for (const v of value) {
|
|
|
|
|
|
|
|
// eslint-disable-next-line
|
|
|
|
|
|
|
|
await doAppend(v);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
await doAppend(value);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|