html5 - IndexedDB: When to close a connection -


i know correct place close connection database is.

let's have following piece of code:

function additem(dbname, versionnumber, storename, element, callback){     var requestopendb = indexeddb.open(dbname, versionnumber); //idbrequest    requestopendb.onsuccess = function(event){          //console.log ("requestopendb.onsuccess ");         var db = event.target.result;          var trans = db.transaction(storename, "readwrite");         var store = trans.objectstore(storename);             var requestadd = store.add(element);          requestadd.onsuccess = function(event) {                      callback("success");          };         requestadd.onerror = function(event) {                      callback("error");                };            };     requestopendb.onerror = function(event) {           console.log ("error:" +  event.srcelement.error.message);/* handle error */          callback("error");     };          } 

additem adds new element database. per understanding, when requestadd event triggered doesn't mean transaction has finished. therefore wondering best place call db.close() is. closing connection inside of requestadd.onsucess, if error happens , requestadd.onerror triggered instead, connection might still opened. thinking adding trans.oncomplete under request.onerror , close db connection here might better option. inputs more welcome. thank you.

you never need close connection. not creating memory leaks or that. leaving connection open not result in material performance hit.

i suggest not worrying it.

also, whether add trans.oncomplete before or after request.onerror not important. understand how can confusing, order in bind listeners irrelevant (qualified: within same function scope).


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -