Note that there are some explanatory texts on larger screens.

plurals
  1. POasync + recursive + database-update operation with nodejs
    primarykey
    data
    text
    <p>Here is the algorithm which returns the position(in form of a callback) at which an item can be inserted and also update the position of the previous items.</p> <pre><code>Put the item into infinite length array (assumed), 0&lt;=index&lt;INFINITY, and for empty array largest_index_occupied = 0. ALSO largest_index_occupied is dynamically retrieved from database.(assumed). No two item can share same index. No item must be lost during any operation. indexes are in increasing order. 1. if index not provided OR index provided is greater than largest_index_occupied then put item at index : largest_index_occupied+5; 2. If index provided AND less than equals to largest_index_occupied, : a. if (No other item already exists at that index) : simply put the item at that index b. otherwise (means if a item already exists at that index) : increase the index of all items by one untill we get an empty index. and put the new item at the index actually passed by user(which must be empty now). </code></pre> <p>2.b example :</p> <p>say - shows empty index.</p> <p>previous state</p> <pre><code>0 - - - - 5 6 7 - - 10 a - - - - b c d - - e </code></pre> <p>input at index : <code>5,f</code></p> <p>new state :</p> <pre><code>0 - - - - 5 6 7 8 - 10 a - - - - f b c d - e </code></pre> <p>Noe f's new index is 5.</p> <p>My requirement is to write a code for the above in combination of async,recursion and IO operation (db update - of the index of items in case of 2.b) in nodejs.</p> <p>i am expecting <code>next(err,indexToBeInserted);</code> callback that has to called only after all the updation has taken place.</p> <p>My function block goes here :</p> <pre><code>toInsert(mongooseModel,next,indexToBeInserted) { // async code goes here. } </code></pre> <p>ps : if you have any better solution please share.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload