-| 21:58 - "Ответ: для разгулки времени."
![[Pasted image 20220615215046.png]]
![[module.js]]
const deleteTransaction = function(params){
const { collection, key } = params;
const node = db._query(`
FOR doc IN @@collection
FILTER doc._key == @key
RETURN doc`,
{ '@collection':collection, key }).toArray();
if(node.length === 0) throw new Error('Node not found');
const { left, right, catalog } = node[0];
const d = right - left + 1;
db._query(`
FOR doc IN @@collection
FILTER doc.catalog == @catalog AND doc.left >= @left AND doc.right <= @right
REMOVE doc IN @@collection`,
{ '@collection':collection, left, right, catalog });
db._query(`
FOR doc IN @@collection FILTER doc.catalog == @catalog AND doc.right > @right
UPDATE doc WITH { right: doc.right - @d } IN @@collection`,
{ '@collection':collection, d, right, catalog });
db._query(`
FOR doc IN @@collection FILTER doc.catalog == @catalog AND doc.left > @right
UPDATE doc WITH { left: doc.left - @d } IN @@collection`,
{ '@collection':collection, d, right, catalog });
return true;
}
-| 21:49 - "Вопрос: зачем существует существующее?"